diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx b/x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx index 794128832461ba..80a7ceb61c324c 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx +++ b/x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx @@ -12,7 +12,12 @@ import { EditorFrameInstance } from '../types'; import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; import { Document, SavedObjectStore } from '../persistence'; import { mount } from 'enzyme'; -import { esFilters, IFieldType, IIndexPattern } from '../../../../../../src/plugins/data/public'; +import { + esFilters, + FilterManager, + IFieldType, + IIndexPattern, +} from '../../../../../../src/plugins/data/public'; import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'; const dataStartMock = dataPluginMock.createStartContract(); @@ -60,6 +65,10 @@ function createMockFilterManager() { subscriber(); }, getFilters: () => filters, + getGlobalFilters: () => { + // @ts-ignore + return filters.filter(esFilters.isFilterPinned); + }, removeAll: () => { filters = []; subscriber(); @@ -821,7 +830,7 @@ describe('Lens App', () => { ); }); - it('clears all existing filters when the active saved query is cleared', () => { + it('clears all existing unpinned filters when the active saved query is cleared', () => { const args = makeDefaultArgs(); args.editorFrame = frame; @@ -834,8 +843,13 @@ describe('Lens App', () => { const indexPattern = ({ id: 'index1' } as unknown) as IIndexPattern; const field = ({ name: 'myfield' } as unknown) as IFieldType; + const pinnedField = ({ name: 'pinnedField' } as unknown) as IFieldType; - args.data.query.filterManager.setFilters([esFilters.buildExistsFilter(field, indexPattern)]); + const unpinned = esFilters.buildExistsFilter(field, indexPattern); + const pinned = esFilters.buildExistsFilter(pinnedField, indexPattern); + FilterManager.setFiltersStore([pinned], esFilters.FilterStateStore.GLOBAL_STATE); + + args.data.query.filterManager.setFilters([pinned, unpinned]); instance.update(); instance.find(TopNavMenu).prop('onClearSavedQuery')!(); @@ -844,7 +858,7 @@ describe('Lens App', () => { expect(frame.mount).toHaveBeenLastCalledWith( expect.any(Element), expect.objectContaining({ - filters: [], + filters: [pinned], }) ); }); diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx b/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx index 615e91f56df6c5..35e45af6a3d689 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx +++ b/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx @@ -258,7 +258,7 @@ export function App({ setState(s => ({ ...s, savedQuery: undefined, - filters: [], + filters: data.query.filterManager.getGlobalFilters(), query: { query: '', language: