Skip to content

Commit

Permalink
[Lens] Do not reset filter state on incoming app navigation (#83786) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Nov 24, 2020
1 parent 7439b9d commit 2a49925
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions test/functional/services/dashboard/add_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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', () => {
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
25 changes: 24 additions & 1 deletion x-pack/test/functional/apps/lens/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
Expand Down Expand Up @@ -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);
});
});
}

0 comments on commit 2a49925

Please sign in to comment.