Sort shopfront category filter buttons alphabetically, or by enterprise preference#14487
Open
BethanOFN wants to merge 2 commits into
Open
Conversation
…se preference Category filters on the shopfront were displayed in arbitrary database-ID order. Two bugs caused this: the taxons API endpoint had no ORDER BY, and the frontend stored taxons in a plain JS object (integer keys always iterate in ascending ID order, destroying any API-provided ordering). Fix: sort taxons in the API response alphabetically by default, or by preferred_shopfront_taxon_order when the distributor has by_category sorting configured. Change supplied_taxons from a hash to an array in the products controller so the API sort order is preserved. Update filter_selector to handle array input alongside the existing hash input used by properties.
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
/api/v0/order_cycles/:id/taxons.jsonendpoint had noORDER BY, and the frontend stored taxons in a plain JS object (integer-indexed keys always iterate in ascending numeric order in JS, destroying any API-provided ordering).preferred_shopfront_taxon_orderwhen the distributor has "by category" sorting configured. Changesupplied_taxonsfrom a hash to an array in the products controller to preserve the sort order. Updatefilter_selectorto handle array input alongside the existing hash input used by properties.Closes openfoodfoundation/wishlist#534
Test plan
filter_selector)bundle exec rspec spec/controllers/api/v0/order_cycles_controller_spec.rb— all 23 examples pass