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

[Lens] Do not reset filter state on incoming app navigation #83786

Merged
merged 7 commits into from
Nov 24, 2020

Conversation

flash1293
Copy link
Contributor

Fixes #83601

When switching from dashboard to Lens using the "Create new" button, unpinned filters would get carried over, but not shown in the UI.

This happened because the Lens app always resets the filter state in the data plugin on load. I added an exception to that rule to not reset the state if there's an originatingApp in the incoming package.

@flash1293 flash1293 marked this pull request as ready for review November 19, 2020 13:49
@flash1293 flash1293 requested a review from a team November 19, 2020 13:49
@flash1293 flash1293 added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Nov 19, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me - especially all the tests. (Code only review)

I do think that carrying over the filters from the dashboard is the right call - even if they aren't pinned - because it keeps context the same when moving between apps.

Edit: After further discussion with Joe, I noticed I was missing a major piece of the puzzle. The fact that any filters on lens get saved into the panel. This means that even with this PR, it would still be very easy for a user to accidentally add an unwanted filter to a panel, by editing from dashboard with a filter, then clicking save and return. In this case, I think we should try to actually clear the filters when lens starts.

In Visualize, when coming from dashboards, the filters are reset and only pinned filters / saved filters are kept. We should write a follow up to ensure that this behaviour is made consistent.

In my opinion it would be best to make Lens follow the visualize behaviour, but it would be worth getting input from product. @AlonaNadler, do you have any context around this?

@mbondyra
Copy link
Contributor

Tested, code LGTM 🆗

@flash1293
Copy link
Contributor Author

I see your point @ThomThomson and I think I agree. @AlonaNadler can you confirm this is the right behavior? Changing the PR this way shouldn't be difficult

@flash1293
Copy link
Contributor Author

I rewrote this PR to not carry over non-pinned filters from Dashboard as I think it's the right behavior as well and it's kind of urgent because I definitely wont to get it into the 7.10.1 release.

@AlonaNadler
Copy link

Ideally, when creating a new Lens panel from the dashboard, the filters should not pass to Lens unless the filter was pinned.
If users are in dashboards have a bunch of filters
This should be aligned with the experience we have in visualize.

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this code yet, but I want to point out that line 145 of app.tsx is already attempting to do the same thing. Is that line executed?

@flash1293
Copy link
Contributor Author

flash1293 commented Nov 23, 2020

@wylieconlon That's not the exactly same thing - we have too keep the state of the data plugin filter manager and the react state in the Lens app in sync.

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@flash1293
Copy link
Contributor Author

@mbondyra @ThomThomson could you have another look just to be sure? As the fix is a very different one now.

It has to be done in that place as well because line 145 Wylie pointed out is just removing the app filters from the filter manager state of the data plugin, not from the Lens local state.

Copy link
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally in Chrome, unpinned filters are no longer carried over from Dashboard. Code & tests LGTM

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in Firefox and it definitely fixes the issue, mostly commenting on style.

filters: data.query.filterManager.getFilters(),
filters: !initialContext
? data.query.filterManager.getGlobalFilters()
: data.query.filterManager.getFilters(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistic comment: could you flip the branches of this ternary? This might simplify the understanding of the code.

Also since we've had issues with this part of the code, maybe it deserves a code comment here?

@@ -116,6 +121,18 @@ 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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of code style, I'm not a big fan of how the next text depends on test setup from this test. Could you move this logic into a single test?

@flash1293
Copy link
Contributor Author

Good points @wylieconlon , adjusted the PR

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 935.0KB 935.1KB +60.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filters being carried over invisibly from dashboard to lens and saved with the lens object
7 participants