Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.10] [Lens] Do not reset filter state on incoming app navigation (#83786) #84205

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
}