-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add new interface for storing f filter state #5996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
witoszekdev
wants to merge
1
commit into
main
Choose a base branch
from
eng-695-add-filter-value-controller
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/components/ConditionalFilter/ValueProvider/FilterValueController.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { FilterContainer, FilterElement } from "../FilterElement"; | ||
| import { UrlToken } from "./UrlToken"; | ||
|
|
||
| /** | ||
| * PersistenceStrategy defines the contract for persisting and clearing filter state. | ||
| * | ||
| * Implementations: | ||
| * - UrlPersistenceStrategy: stores state in URL query parameters (for list pages) | ||
| * - InMemoryPersistenceStrategy: stores state in React component state (for modals) | ||
| * | ||
| * @see {@link ./strategies/UrlPersistenceStrategy.ts} | ||
| * @see {@link ./strategies/InMemoryPersistenceStrategy.ts} | ||
| */ | ||
| export interface PersistenceStrategy { | ||
| /** | ||
| * Persist the filter state to the underlying storage mechanism. | ||
| * @param value The filter container to persist | ||
| */ | ||
| persist(value: FilterContainer): void; | ||
|
|
||
| /** | ||
| * Clear all persisted filter state from the underlying storage mechanism. | ||
| */ | ||
| clear(): void; | ||
| } | ||
|
|
||
| export interface FilterValueControllerConfig { | ||
| persistenceStrategy: PersistenceStrategy; | ||
|
|
||
| /** | ||
| * Initial filter state to populate the controller with. | ||
| * If not provided, controller starts with an empty state | ||
| */ | ||
| initialValue?: FilterContainer; | ||
|
|
||
| initialLoading?: boolean; | ||
|
|
||
| /** | ||
| * Callback invoked when the filter value changes. | ||
| * Can be used to trigger side effects like data fetching. | ||
| */ | ||
| onChange?: (value: FilterContainer) => void; | ||
| } | ||
|
|
||
| /** | ||
| * FilterValueController is used for managing filter state with different strategies (URL, in-memory) | ||
| * | ||
| * This interface matches FilterValueProvider to ensure backward compatibility | ||
| * with existing code that uses useUrlValueProvider. | ||
| */ | ||
| export interface FilterValueController { | ||
| readonly value: FilterContainer; | ||
|
|
||
| readonly loading: boolean; | ||
|
|
||
| /** | ||
| * Persist a new filter value using the configured persistence strategy. | ||
| * @param newValue The new filter container to persist | ||
| */ | ||
| persist(newValue: FilterContainer): void; | ||
|
|
||
| /** | ||
| * Check if a specific filter element is present in the current state. | ||
| * @param element The filter element to check | ||
| */ | ||
| isPersisted(element: FilterElement): boolean; | ||
|
|
||
| /** | ||
| * Clear all filters using the configured persistence strategy. | ||
| */ | ||
| clear(): void; | ||
|
|
||
| /** | ||
| * Get a specific token by name from the mirrored UrlToken[] representation. | ||
| * This method provides backward compatibility with existing code that expects | ||
| * URL token access for initial state hydration. | ||
| * | ||
| * @param name The name of the token to retrieve | ||
| */ | ||
| getTokenByName(name: string): UrlToken | undefined; | ||
|
|
||
| /** | ||
| * The number of active filter elements | ||
| */ | ||
| readonly count: number; | ||
|
|
||
| /** | ||
| * Must be called when page is unloaded in useEffect | ||
| */ | ||
| cleanup(): void; | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
...ents/ConditionalFilter/ValueProvider/persistenceStrategies/InMemoryPersistenceStrategy.ts
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||
| import { FilterContainer } from "../../FilterElement"; | ||||||
| import { PersistenceStrategy } from "../FilterValueController"; | ||||||
|
|
||||||
| export interface InMemoryPersistenceStrategyConfig { | ||||||
| /** | ||||||
| * Initial state for the in-memory storage. | ||||||
| * If not provided, starts with an empty FilterContainer | ||||||
| */ | ||||||
| initialState?: FilterContainer; | ||||||
|
|
||||||
| /** | ||||||
| * Callback when state changes in memory | ||||||
| */ | ||||||
| onStateChange?: (state: FilterContainer) => void; | ||||||
| } | ||||||
|
||||||
| } | |
| } |
51 changes: 51 additions & 0 deletions
51
...omponents/ConditionalFilter/ValueProvider/persistenceStrategies/UrlPersistenceStrategy.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { FilterContainer } from "../../FilterElement"; | ||
| import { PersistenceStrategy } from "../FilterValueController"; | ||
|
|
||
| export interface UrlPersistenceStrategyConfig { | ||
| /** | ||
| * The router history object for URL manipulation. | ||
| * Should be compatible with react-router's history API. | ||
| */ | ||
| history: { | ||
| replace: (location: { pathname: string; search?: string }) => void; | ||
| }; | ||
|
|
||
| /** | ||
| * Current location information from the router. | ||
| */ | ||
| location: { | ||
| pathname: string; | ||
| search: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Additional query parameters to preserve during filter persistence. | ||
| * These params are merged with filter state when updating the URL. | ||
| * | ||
| * For example: | ||
| * - query: Search query | ||
| * - before: Pagination cursor | ||
| * - after: Pagination cursor | ||
| * etc. | ||
| */ | ||
| preservedParams?: Record<string, string | undefined>; | ||
| } | ||
|
|
||
| /** | ||
| * TODO: | ||
| * - Wrap router.history.replace calls from useUrlValueProvider | ||
| * - Handle URL query parameter serialization using prepareStructure utility | ||
| * - Preserve additional params (activeTab, query, before, after) | ||
| * - Ensure FilterContainer format compatibility | ||
| */ | ||
| export class UrlPersistenceStrategy implements PersistenceStrategy { | ||
| constructor(private config: UrlPersistenceStrategyConfig) {} | ||
|
|
||
| persist(_value: FilterContainer): void { | ||
| throw new Error("UrlPersistenceStrategy.persist: Not implemented yet"); | ||
| } | ||
|
|
||
| clear(): void { | ||
| throw new Error("UrlPersistenceStrategy.clear: Not implemented yet"); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
@seelinks reference './strategies/' but the actual files are in './persistenceStrategies/'. Update the paths to '@see {@link ./persistenceStrategies/UrlPersistenceStrategy.ts}' and '@see {@link ./persistenceStrategies/InMemoryPersistenceStrategy.ts}'.