Skip to content

Add vegan/vegetarian filter toggles to ingredient autocompleter#1197

Open
stuckvgn wants to merge 1 commit intowger-project:masterfrom
stuckvgn:feature/ingredient-dietary-filters
Open

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

Conversation

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

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

@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

@stuckvgn
Copy link
Contributor Author

stuckvgn commented Mar 1, 2026

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).

@stuckvgn
Copy link
Contributor Author

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

@stuckvgn stuckvgn closed this Mar 14, 2026
@stuckvgn
Copy link
Contributor Author

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

@stuckvgn stuckvgn reopened this Mar 14, 2026
@coveralls
Copy link
Collaborator

Coverage Status

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

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