marmelab / marmelab/react-admin
FilterButton adds filter in arbitrary order
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 26.9k
- Forks
- 5.5k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 19
Description
**What you were expecting:**
Adding a new filter using the FilterButton shows the filter at the end of the current filter list
**What happened instead:**
The new filter appears at an arbitrary position
**Steps to reproduce:**
1. Open the e-commerce demo https://marmelab.com/react-admin-demo/#/
2. Click on the Orders menu
3. Add the "Min amount" filter
4. Add the "customer" filter
5. The Customer filter appears in the middle instead of the end of the form
https://github.com/marmelab/react-admin/assets/99944/214b01e2-7ff3-45d2-a462-773717fbd32c
**Related code:**
This comes from the fact that the `displayedFilters` uses an object instead of an array:
https://github.com/marmelab/react-admin/blob/4089ad726b9ae699173790a6f97685a22426e34a/packages/ra-core/src/controller/list/queryReducer.ts#L95-L120
Why is it an object? This choice was made 7 years ago, when first implementing this feature:
https://github.com/marmelab/react-admin/commit/2e2604d0d93a420dc61e1b30d5f6dada501e4f12
**Possible Solution**
Store displayed filters as an array instead. But this breaks backwards compatibility for those with existing filters in localStorage, so the change must allow the code to work with an old data structure.
**Environment**
* React-admin version: all
* Last version that did not exhibit the issue (if applicable): none
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/ra-core/src/controller/list/queryReducer.ts, then trace the FilterButton displayedFilters flow and existing localStorage handling. Reproduce the Orders scenario in the e-commerce demo; done when newly added filters retain insertion order while existing object-shaped persisted filters continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100