Skip to content

Add vegan/vegetarian filter toggles to ingredient autocompleter#1197

Closed
samtuckerdavis wants to merge 1 commit into
wger-project:masterfrom
samtuckerdavis:feature/ingredient-dietary-filters
Closed

Add vegan/vegetarian filter toggles to ingredient autocompleter#1197
samtuckerdavis wants to merge 1 commit into
wger-project:masterfrom
samtuckerdavis:feature/ingredient-dietary-filters

Conversation

@samtuckerdavis

Copy link
Copy Markdown
Contributor

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.

@rolandgeider

Copy link
Copy Markdown
Member

you're on fire! I'll try to look at this later

@rolandgeider

Copy link
Copy Markdown
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

@samtuckerdavis

Copy link
Copy Markdown
Contributor Author

The PR has been updated to align with the approach you implemented — filters are in a popup (Popover with TuneIcon), and labels use 'Vegan' / 'Vegetarian' without 'only'. Also added the missing filterVegan / filterVegetarian keys to the German translation (de/translation.json).

@samtuckerdavis

Copy link
Copy Markdown
Contributor Author

Closing this PR — on reflection, this change may not be the right fit for this project. Thanks for your time!

@samtuckerdavis

Copy link
Copy Markdown
Contributor Author

Apologies for the accidental close — this has your feedback incorporated and is ready for review.

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 74.893%. remained the same
when pulling 1eba9fb on stuckvgn:feature/ingredient-dietary-filters
into 1632cb2 on wger-project:master.

@rolandgeider

Copy link
Copy Markdown
Member

the translation keys are already available on master, closing here

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

3 participants