Add new interface for storing f filter state#5996
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces TypeScript interfaces for a pluggable filter state persistence architecture that will support both URL-based and in-memory storage strategies.
Key Changes:
- Defines
PersistenceStrategyinterface withpersist()andclear()methods - Introduces
FilterValueControllerinterface matching the existing FilterValueProvider API for backward compatibility - Adds skeleton implementations for
UrlPersistenceStrategyandInMemoryPersistenceStrategy(marked with TODOs)
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| FilterValueController.ts | Defines core interfaces (PersistenceStrategy, FilterValueController, FilterValueControllerConfig) establishing the contract for filter state management |
| UrlPersistenceStrategy.ts | Adds URL-based persistence strategy skeleton with configuration for router history and query parameter preservation |
| InMemoryPersistenceStrategy.ts | Adds in-memory persistence strategy skeleton with configuration for initial state and change callbacks |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| * @see {@link ./strategies/UrlPersistenceStrategy.ts} | ||
| * @see {@link ./strategies/InMemoryPersistenceStrategy.ts} |
There was a problem hiding this comment.
The @see links reference './strategies/' but the actual files are in './persistenceStrategies/'. Update the paths to '@see {@link ./persistenceStrategies/UrlPersistenceStrategy.ts}' and '@see {@link ./persistenceStrategies/InMemoryPersistenceStrategy.ts}'.
| * @see {@link ./strategies/UrlPersistenceStrategy.ts} | |
| * @see {@link ./strategies/InMemoryPersistenceStrategy.ts} | |
| * @see {@link ./persistenceStrategies/UrlPersistenceStrategy.ts} | |
| * @see {@link ./persistenceStrategies/InMemoryPersistenceStrategy.ts} |
| * Callback when state changes in memory | ||
| */ | ||
| onStateChange?: (state: FilterContainer) => void; | ||
| } |
There was a problem hiding this comment.
[nitpick] Missing blank line between the closing brace of InMemoryPersistenceStrategyConfig and the JSDoc comment. Add a blank line for consistency with TypeScript formatting conventions.
| } | |
| } |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5996 +/- ##
==========================================
- Coverage 39.49% 39.48% -0.01%
==========================================
Files 2429 2431 +2
Lines 39518 39528 +10
Branches 8711 8711
==========================================
Hits 15609 15609
- Misses 23883 23893 +10
Partials 26 26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Scope of the change
This PR introduces new TypeScript interfaces to separate two tasks of current
FilterValueProvider:Holding canonical state of filters will be separate of persisting the state. It's done by introducing new persistence strategies: in URL (list pages) and in-memory (for modals). Implementation will be done in next PR (note for URL we will just wrap our existing logic, to avoid breaking changes)
Added
PersistenceStrategy
Base interface for pluggable persistence implementations with persist() and clear() methods.
FilterValueController
Main controller interface matching the existing FilterValueProvider API to ensure backward compatibility.
Why
Our current implementation treats URLs as source of truth for filter state. We don't use URL state for modals, where we want to introduce filters in. This also has drawbacks: because we treat it as source of truth we need to always rehydrate state by fetching options (e.g. reference attributes values) from API, even though we have already fetched this data in the filter UI itself.
How ConditionalFilter work right now
New approach
List page example
Modal example