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) => {