Skip to content

Add vegan/vegetarian filter toggles to ingredient autocompleter#1197

Open
stuckvgn wants to merge 3 commits intowger-project:masterfrom
stuckvgn:feature/ingredient-dietary-filters
Open

Add vegan/vegetarian filter toggles to ingredient autocompleter#1197
stuckvgn wants to merge 3 commits intowger-project:masterfrom
stuckvgn:feature/ingredient-dietary-filters

Conversation

@stuckvgn
Copy link

Summary

Companion frontend to wger-project/wger#2218, which adds is_vegan and is_vegetarian fields to the Ingredient model and exposes them via the ingredientinfo API 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 — add is_vegan: boolean | null and is_vegetarian: boolean | null
  • Ingredient model — add isVegan / isVegetarian properties with adapter mapping from JSON
  • searchIngredient() service — accept optional isVegan / isVegetarian params, passed as ?is_vegan=true / ?is_vegetarian=true query params to the ingredientinfo API
  • IngredientAutocompleter — add "Vegan only" and "Vegetarian only" Switch toggles rendered as a row below the search input; toggling either filter immediately re-triggers search
  • i18n — add nutrition.filterVegan and nutrition.filterVegetarian translation keys
  • Tests — update ingredient service fixture and assertions to include the new fields

Behaviour

When both toggles are off (default), search behaves exactly as before — no dietary filter params are sent. Enabling a toggle appends ?is_vegan=true or ?is_vegetarian=true to the API query. Both can be enabled simultaneously.

Ingredients with NULL dietary 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 ingredientinfo API to return is_vegan / is_vegetarian fields. The autocompleter degrades gracefully before that — the new fields will just be null on all ingredients and the toggle UI still renders, it just won't filter anything until the backend lands.

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
@rolandgeider
Copy link
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.
@rolandgeider
Copy link
Member

FYI, I moved the options to a popup, if we add more in the future, having them inline doesn't scale. I have also renamed the labels from "vegan only" to just "vegan" as I think this is clearer

Bildschirmfoto 2026-02-26 um 21 45 18

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.).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add plant-based / dietary preference filters to nutrition module

2 participants