diff --git a/test/functional/services/dashboard/add_panel.ts b/test/functional/services/dashboard/add_panel.ts index 773664612c6dc..9f70b95befaa6 100644 --- a/test/functional/services/dashboard/add_panel.ts +++ b/test/functional/services/dashboard/add_panel.ts @@ -39,6 +39,11 @@ export function DashboardAddPanelProvider({ getService, getPageObjects }: FtrPro await PageObjects.common.sleep(500); } + async clickVisType(visType: string) { + log.debug('DashboardAddPanel.clickVisType'); + await testSubjects.click(`visType-${visType}`); + } + async clickAddNewEmbeddableLink(type: string) { await testSubjects.click('createNew'); await testSubjects.click(`createNew-${type}`); diff --git a/x-pack/plugins/lens/public/app_plugin/app.test.tsx b/x-pack/plugins/lens/public/app_plugin/app.test.tsx index 70f3f767930ec..d8e4f0955b5aa 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.test.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.test.tsx @@ -307,6 +307,9 @@ describe('Lens App', () => { const pinnedField = ({ name: 'pinnedField' } as unknown) as IFieldType; const pinnedFilter = esFilters.buildExistsFilter(pinnedField, indexPattern); services.data.query.filterManager.getFilters = jest.fn().mockImplementation(() => { + return []; + }); + services.data.query.filterManager.getGlobalFilters = jest.fn().mockImplementation(() => { return [pinnedFilter]; }); const { component, frame } = mountWith({ services }); @@ -321,6 +324,7 @@ describe('Lens App', () => { filters: [pinnedFilter], }) ); + expect(services.data.query.filterManager.getFilters).not.toHaveBeenCalled(); }); it('displays errors from the frame in a toast', () => { diff --git a/x-pack/plugins/lens/public/app_plugin/app.tsx b/x-pack/plugins/lens/public/app_plugin/app.tsx index 3407ea5de49c4..6f786c6cea766 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.tsx @@ -69,7 +69,11 @@ export function App({ const currentRange = data.query.timefilter.timefilter.getTime(); return { query: data.query.queryString.getQuery(), - filters: data.query.filterManager.getFilters(), + // Do not use app-specific filters from previous app, + // only if Lens was opened with the intention to visualize a field (e.g. coming from Discover) + filters: !initialContext + ? data.query.filterManager.getGlobalFilters() + : data.query.filterManager.getFilters(), isLoading: Boolean(initialInput), indexPatternsForTopNav: [], dateRange: { diff --git a/x-pack/test/functional/apps/lens/dashboard.ts b/x-pack/test/functional/apps/lens/dashboard.ts index c24f4ccf01bcd..17b70b8510f04 100644 --- a/x-pack/test/functional/apps/lens/dashboard.ts +++ b/x-pack/test/functional/apps/lens/dashboard.ts @@ -36,7 +36,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { before(async () => { await PageObjects.common.navigateToApp('dashboard'); await security.testUser.setRoles( - ['global_dashboard_all', 'global_discover_all', 'test_logstash_reader'], + [ + 'global_dashboard_all', + 'global_discover_all', + 'test_logstash_reader', + 'global_visualize_all', + ], false ); }); @@ -116,6 +121,24 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); const hasGeoDestFilter = await filterBar.hasFilter('geo.dest', 'LS'); expect(hasGeoDestFilter).to.be(true); + await filterBar.addFilter('geo.src', 'is', 'US'); + await filterBar.toggleFilterPinned('geo.src'); + }); + + it('should not carry over filters if creating a new lens visualization from within dashboard', async () => { + await PageObjects.common.navigateToApp('dashboard'); + await PageObjects.dashboard.clickNewDashboard(); + await filterBar.addFilter('geo.src', 'is', 'US'); + await filterBar.toggleFilterPinned('geo.src'); + await filterBar.addFilter('geo.dest', 'is', 'LS'); + + await dashboardAddPanel.clickCreateNewLink(); + await dashboardAddPanel.clickVisType('lens'); + await PageObjects.header.waitUntilLoadingHasFinished(); + const hasGeoDestFilter = await filterBar.hasFilter('geo.dest', 'LS'); + expect(hasGeoDestFilter).to.be(false); + const hasGeoSrcFilter = await filterBar.hasFilter('geo.src', 'US', true, true); + expect(hasGeoSrcFilter).to.be(true); }); }); }