Add vegan/vegetarian filter toggles to ingredient autocompleter#1197
Open
stuckvgn wants to merge 3 commits intowger-project:masterfrom
Open
Add vegan/vegetarian filter toggles to ingredient autocompleter#1197stuckvgn wants to merge 3 commits intowger-project:masterfrom
stuckvgn wants to merge 3 commits intowger-project:masterfrom
Conversation
Surfaces the is_vegan and is_vegetarian fields added to the wger backend (wger-project/wger#2218) in the meal form ingredient search UI. - ApiIngredientType: add is_vegan / is_vegetarian nullable boolean fields - Ingredient model: add isVegan / isVegetarian properties with fromJson mapping - searchIngredient(): accept optional isVegan / isVegetarian filter params, pass as ?is_vegan=true / ?is_vegetarian=true query params to ingredientinfo API - IngredientAutocompleter: add "Vegan only" and "Vegetarian only" toggle switches rendered as a row below the search input; filters re-trigger search on change - i18n: add nutrition.filterVegan and nutrition.filterVegetarian translation keys - Tests: update ingredient service fixture and assertions for new fields
5 tasks
Member
|
you're on fire! I'll try to look at this later |
This will be specially important if we add more options in the future or rework the language one so that it is more flexible.
Member
While this has technically nothing to do with the vegan flags, we can refactor the language handling while we're at it. This should make the behaviour more transparent to the user and could be expanded in the future if needed (manually selecting other languages, etc.).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Companion frontend to wger-project/wger#2218, which adds
is_veganandis_vegetarianfields to theIngredientmodel and exposes them via theingredientinfoAPI endpoint.This PR surfaces those fields in the meal form ingredient search so users can filter results by dietary preference directly in the autocompleter.
Changes:
ApiIngredientType— addis_vegan: boolean | nullandis_vegetarian: boolean | nullIngredientmodel — addisVegan/isVegetarianproperties with adapter mapping from JSONsearchIngredient()service — accept optionalisVegan/isVegetarianparams, passed as?is_vegan=true/?is_vegetarian=truequery params to theingredientinfoAPIIngredientAutocompleter— add "Vegan only" and "Vegetarian only"Switchtoggles rendered as a row below the search input; toggling either filter immediately re-triggers searchnutrition.filterVeganandnutrition.filterVegetariantranslation keysBehaviour
When both toggles are off (default), search behaves exactly as before — no dietary filter params are sent. Enabling a toggle appends
?is_vegan=trueor?is_vegetarian=trueto the API query. Both can be enabled simultaneously.Ingredients with
NULLdietary status (unknown) are excluded when a filter is active, since the API uses exact matching (True/False/NULL).Dependencies
Requires wger-project/wger#2218 to be merged and the
ingredientinfoAPI to returnis_vegan/is_vegetarianfields. The autocompleter degrades gracefully before that — the new fields will just benullon all ingredients and the toggle UI still renders, it just won't filter anything until the backend lands.