From 5623cef4587104afa92eeb099dfe7a2f2369b3a7 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Wed, 4 Oct 2023 11:05:06 -0700 Subject: [PATCH] [BUG][Data Explorer][Discover] Allow filter and query persist when refresh page or paste url to a new tab (#5206) Issue Resolve https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5179 https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5071 Signed-off-by: ananzh --- CHANGELOG.md | 1 + .../application/view_components/canvas/top_nav.tsx | 7 +++++++ .../application/view_components/context/index.tsx | 13 +------------ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 081b20c4eab..17750e4af78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fix `visAugmenter` forming empty key-value pairs in its calls to the `SavedObject` API ([#5190](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5190)) - [Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171)) - [Data Explorer][Discover] Allow data grid to auto adjust size based on fetched data count ([#5191](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5191)) +- [BUG][Data Explorer][Discover] Allow filter and query persist when refresh page or paste url to a new tab ([#5206](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5206)) ### 🚞 Infrastructure diff --git a/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx b/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx index b75a48d3acf..feb7b91e7c5 100644 --- a/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx +++ b/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx @@ -13,6 +13,7 @@ import { IndexPattern } from '../../../opensearch_dashboards_services'; import { getTopNavLinks } from '../../components/top_nav/get_top_nav_links'; import { useDiscoverContext } from '../context'; import { getRootBreadcrumbs } from '../../helpers/breadcrumbs'; +import { opensearchFilters, connectStorageToQueryState } from '../../../../../data/public'; export interface TopNavProps { opts: { @@ -35,10 +36,16 @@ export const TopNav = ({ opts }: TopNavProps) => { }, data, chrome, + osdUrlStateStorage, } = services; const topNavLinks = savedSearch ? getTopNavLinks(services, inspectorAdapters, savedSearch) : []; + connectStorageToQueryState(services.data.query, osdUrlStateStorage, { + filters: opensearchFilters.FilterStateStore.APP_STATE, + query: true, + }); + useEffect(() => { let isMounted = true; const getDefaultIndexPattern = async () => { diff --git a/src/plugins/discover/public/application/view_components/context/index.tsx b/src/plugins/discover/public/application/view_components/context/index.tsx index 7052ed2887f..f4180d16b19 100644 --- a/src/plugins/discover/public/application/view_components/context/index.tsx +++ b/src/plugins/discover/public/application/view_components/context/index.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useEffect } from 'react'; +import React from 'react'; import { DataExplorerServices, ViewProps } from '../../../../../data_explorer/public'; import { OpenSearchDashboardsContextProvider, @@ -11,7 +11,6 @@ import { } from '../../../../../opensearch_dashboards_react/public'; import { getServices } from '../../../opensearch_dashboards_services'; import { useSearch, SearchContextValue } from '../utils/use_search'; -import { connectStorageToQueryState, opensearchFilters } from '../../../../../data/public'; const SearchContext = React.createContext({} as SearchContextValue); @@ -24,16 +23,6 @@ export default function DiscoverContext({ children }: React.PropsWithChildren { - connectStorageToQueryState(services.data.query, osdUrlStateStorage, { - filters: opensearchFilters.FilterStateStore.APP_STATE, - query: true, - }); - }, [osdUrlStateStorage, services.data.query, services.uiSettings]); - return ( {children}