From 933c69a867627e19b0150aa252b0af5d1d01cb06 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Wed, 25 Sep 2024 19:32:47 +0200 Subject: [PATCH] [ES|QL][Discover] Clean up the pinned filters while transitioning (#193817) --- .../application/main/state_management/discover_state.test.ts | 2 ++ .../application/main/state_management/discover_state.ts | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/plugins/discover/public/application/main/state_management/discover_state.test.ts b/src/plugins/discover/public/application/main/state_management/discover_state.test.ts index 78e552e4e784f..a64e36bc39097 100644 --- a/src/plugins/discover/public/application/main/state_management/discover_state.test.ts +++ b/src/plugins/discover/public/application/main/state_management/discover_state.test.ts @@ -762,10 +762,12 @@ describe('Test discover state actions', () => { savedSearchWithQuery.searchSource.setField('query', query); savedSearchWithQuery.searchSource.setField('filter', filters); const { state } = await getState('/', { savedSearch: savedSearchWithQuery }); + state.globalState?.set({ filters }); await state.actions.transitionFromDataViewToESQL(dataViewMock); expect(state.appState.getState().query).toStrictEqual({ esql: 'FROM the-data-view-title | LIMIT 10', }); + expect(state.globalState?.get?.()?.filters).toStrictEqual([]); expect(state.appState.getState().filters).toStrictEqual([]); }); diff --git a/src/plugins/discover/public/application/main/state_management/discover_state.ts b/src/plugins/discover/public/application/main/state_management/discover_state.ts index b9472716faf7e..0e1a662567bb8 100644 --- a/src/plugins/discover/public/application/main/state_management/discover_state.ts +++ b/src/plugins/discover/public/application/main/state_management/discover_state.ts @@ -382,6 +382,7 @@ export function getDiscoverStateContainer({ const transitionFromDataViewToESQL = (dataView: DataView) => { const queryString = getInitialESQLQuery(dataView); + appStateContainer.update({ query: { esql: queryString }, filters: [], @@ -390,6 +391,9 @@ export function getDiscoverStateContainer({ }, columns: [], }); + // clears pinned filters + const globalState = globalStateContainer.get(); + globalStateContainer.set({ ...globalState, filters: [] }); }; const onDataViewCreated = async (nextDataView: DataView) => {