diff --git a/src/plugins/discover/public/application/main/hooks/utils/build_state_subscribe.ts b/src/plugins/discover/public/application/main/hooks/utils/build_state_subscribe.ts index 5857527d17f42..27407822553bb 100644 --- a/src/plugins/discover/public/application/main/hooks/utils/build_state_subscribe.ts +++ b/src/plugins/discover/public/application/main/hooks/utils/build_state_subscribe.ts @@ -60,7 +60,7 @@ export const buildStateSubscribe = const isTextBasedQueryLangPrev = isTextBasedQuery(prevQuery); if (!isTextBasedQueryLangPrev) { savedSearchState.update({ nextState }); - dataState.reset(); + dataState.reset(savedSearch); } } // Cast to boolean to avoid false positives when comparing @@ -86,7 +86,7 @@ export const buildStateSubscribe = return; } savedSearch.searchSource.setField('index', nextDataView); - dataState.reset(); + dataState.reset(savedSearch); setDataView(nextDataView); savedSearchDataView = nextDataView; } diff --git a/src/plugins/discover/public/application/main/hooks/utils/change_data_view.ts b/src/plugins/discover/public/application/main/hooks/utils/change_data_view.ts index 3754079f6a10a..093f047cb7249 100644 --- a/src/plugins/discover/public/application/main/hooks/utils/change_data_view.ts +++ b/src/plugins/discover/public/application/main/hooks/utils/change_data_view.ts @@ -39,7 +39,6 @@ export async function changeDataView( const dataView = internalState.getState().dataView; const state = appState.getState(); let nextDataView: DataView | null = null; - // switch to the loading state of Discover Data, to make sure loading indication is displayed when loading the new data view internalState.transitions.setDataViewLoading(true); try { diff --git a/src/plugins/discover/public/application/main/services/discover_data_state_container.test.ts b/src/plugins/discover/public/application/main/services/discover_data_state_container.test.ts index ee46732075496..516d81cc9c3f0 100644 --- a/src/plugins/discover/public/application/main/services/discover_data_state_container.test.ts +++ b/src/plugins/discover/public/application/main/services/discover_data_state_container.test.ts @@ -95,7 +95,7 @@ describe('test getDataStateContainer', () => { await waitFor(() => { expect(dataState.data$.main$.value.fetchStatus).toBe(FetchStatus.COMPLETE); }); - dataState.reset(); + dataState.reset(stateContainer.savedSearchState.getState()); await waitFor(() => { expect(dataState.data$.main$.value.fetchStatus).toBe(FetchStatus.LOADING); }); diff --git a/src/plugins/discover/public/application/main/services/discover_data_state_container.ts b/src/plugins/discover/public/application/main/services/discover_data_state_container.ts index 201f1ba262781..b2f8ae9f0a81d 100644 --- a/src/plugins/discover/public/application/main/services/discover_data_state_container.ts +++ b/src/plugins/discover/public/application/main/services/discover_data_state_container.ts @@ -122,7 +122,7 @@ export interface DiscoverDataStateContainer { /** * resetting all data observable to initial state */ - reset: () => void; + reset: (savedSearch: SavedSearch) => void; /** * cancels the running queries @@ -320,8 +320,7 @@ export function getDataStateContainer({ return refetch$; }; - const reset = () => { - const savedSearch = getSavedSearch(); + const reset = (savedSearch: SavedSearch) => { const recordType = getRawRecordType(savedSearch.searchSource.getField('query')); sendResetMsg(dataSubjects, getInitialFetchStatus(), recordType); };