Skip to content

Commit

Permalink
[BUG][Data Explorer][Discover] Allow filter and query persist when re…
Browse files Browse the repository at this point in the history
…fresh page or paste url to a new tab (opensearch-project#5206)

Issue Resolve
opensearch-project#5179
opensearch-project#5071

Signed-off-by: ananzh <[email protected]>

(cherry picked from commit 5623cef)
Signed-off-by: Miki <[email protected]>
  • Loading branch information
ananzh authored and AMoo-Miki committed Oct 4, 2023
1 parent fb19243 commit 0b2ab53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect } from 'react';
import React from 'react';
import { DataExplorerServices, ViewProps } from '../../../../../data_explorer/public';
import {
OpenSearchDashboardsContextProvider,
useOpenSearchDashboards,
} 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<SearchContextValue>({} as SearchContextValue);

Expand All @@ -24,16 +23,6 @@ export default function DiscoverContext({ children }: React.PropsWithChildren<Vi
...services,
});

const { osdUrlStateStorage } = deServices;

// Connect the query service to the url state
useEffect(() => {
connectStorageToQueryState(services.data.query, osdUrlStateStorage, {
filters: opensearchFilters.FilterStateStore.APP_STATE,
query: true,
});
}, [osdUrlStateStorage, services.data.query, services.uiSettings]);

return (
<OpenSearchDashboardsContextProvider services={services}>
<SearchContext.Provider value={searchParams}>{children}</SearchContext.Provider>
Expand Down

0 comments on commit 0b2ab53

Please sign in to comment.