-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Discover] Skip loading filter if navigating to a saved search without params #10913
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| fix: | ||
| - Skip loading filter if navigating to a saved search without params ([#10913](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10913)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,11 @@ export interface ISyncConfig { | |
| filters: FilterStateStore; | ||
| query: boolean; | ||
| dataset?: boolean; | ||
| /** | ||
| * When true, skips using existing filters from filterManager when initializing state from URL. | ||
| * This is useful when navigating to a saved search/explore to prevent filter persistence. | ||
| */ | ||
| skipAppFiltersFromMemory?: boolean; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -74,7 +79,8 @@ export const connectStorageToQueryState = ( | |
|
|
||
| const initialStateFromURL: QueryState = osdUrlStateStorage.get('_q') ?? { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe unrelated to this PR: the name initialStateFromURL is a bit misleading, because it's not just url state, it also reads in-memory state |
||
| query: queryString.getDefaultQuery(), | ||
| filters: filterManager.getAppFilters(), | ||
| // If caller specifies to skip filters from memory, use empty array | ||
| filters: syncConfig.skipAppFiltersFromMemory ? [] : filterManager.getAppFilters(), | ||
| }; | ||
|
|
||
| if (!osdUrlStateStorage.get('_q')) { | ||
|
|
@@ -86,6 +92,11 @@ export const connectStorageToQueryState = ( | |
| queryString.clearQuery(); | ||
| } | ||
|
|
||
| // Clear app filters if caller requested to skip filters from memory | ||
| if (syncConfig.skipAppFiltersFromMemory && syncConfig.filters === FilterStateStore.APP_STATE) { | ||
| filterManager.setAppFilters([]); | ||
| } | ||
|
|
||
| if (syncConfig.query && !_.isEqual(initialStateFromURL.query, queryString.getQuery())) { | ||
| if (initialStateFromURL.query) { | ||
| queryString.setQuery(_.cloneDeep(initialStateFromURL.query)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,9 +77,16 @@ export const TopNav = ({ opts, showSaveQuery, isEnhancementsEnabled }: TopNavPro | |
| : []; | ||
|
|
||
| const syncConfig = useMemo(() => { | ||
| // Check if navigating to a saved search without params - skip filter persistence | ||
| const currentHash = window.location.hash.split('?')[0]; | ||
| const isSavedSearchUrl = currentHash.includes('#/view/'); | ||
| const hasUrlParams = window.location.hash.includes('?'); | ||
| const shouldSkipFilters = isSavedSearchUrl && !hasUrlParams; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't get why it should check |
||
|
|
||
| return { | ||
| filters: opensearchFilters.FilterStateStore.APP_STATE, | ||
| query: true, | ||
| skipAppFiltersFromMemory: shouldSkipFilters, | ||
| }; | ||
| }, []); | ||
|
|
||
|
|
||
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.
Maybe unrelated to this PR, it seems in
connectStorageToQueryState, we're doing two-way state syncingmemory state <-> url sate, do you know the intention?