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

No reload on changes to disabled filters in dashboard #41144

Merged
merged 11 commits into from
Jul 29, 2019

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Jul 15, 2019

Summary

Related #33926

This PR prevents requests to the backend if disabled filters are changed. It updates the app state but prevents the call to search source by not calling forceReload on the vis object in case of the editor resp. not propagating the input changes to the dashboard container in case of dashboard.

I'm not sure whether this is the right place for that, and maybe this even becomes a non-issue when we have generic caching on the data layer (not sure whether this is planned).

Ping
@stacey-gammon (because of embeddable and dashboard knowledge)
@lukeelmers (because of data access layer knowledge)
@timroes (because of visualize editor knowledge)

Input greatly appreciated before I clean up and add tests.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

- [ ] This was checked for cross-browser compatibility, including a check against IE11
- [ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
- [ ] Documentation was added for features that require explanation or tutorials

For maintainers

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

Thanks for the ping -- took a look and overall makes sense! Looks like a good optimization; it might be nice to have a test for it though.

Haven't tested locally yet, but will do that soon and report back with any other findings.

changes.filters &&
Object.keys(changes).length === 1 &&
!areFilterChangesFetchRelevant($scope.model.filters, changes.filters)
)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Might just be me, but I re-read this conditional 3 times before I understood it 😄 Probably due to the double-negation. Maybe there's a way to simplify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exactly what I meant by

Input greatly appreciated before I clean up and add tests.

in the PR description 😄

Just wanted to make sure the approach is sound. I will ping again once this leaves draft status.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think having this logic here will get us into trouble. I didn't test but I feel like things can get out of sync now. Like, lets say you change a disabled filter from abc to xyz. You then add a new panel into the container. This change comes from the container, so this code gets run:

          inputSubscription = dashboardContainer.getInput$().subscribe(async () => {
            let dirty = false;

            // This has to be first because handleDashboardContainerChanges causes
            // appState.save which will cause refreshDashboardContainer to be called.

            // Add filters modifies the object passed to it, hence the clone deep.
            if (!_.isEqual(container.getInput().filters, queryFilter.getFilters())) {
              await queryFilter.addFilters(_.cloneDeep(container.getInput().filters));

              dashboardStateManager.applyFilters($scope.model.query, container.getInput().filters);
              dirty = true;
            }

At this point, I think we might have a bug because it's going to look like the container updated the disabled filter back to abc and the xyz changes will get overwritten.

I think maybe the safer bet is to just let every embeddable handle when to fetch or not. We could have a bigger discussion on whether it even makes sense to send disabled filters down to the embeddables. The logic in this class is difficult to follow with state updates coming from so many different places but I think it will get much clearer once we get rid of angular and can clean this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, that's exactly what happens. Is this code block handling the case when a filter is added from within the dashboard (e.g. clicking a bar in a bar chart)?

Not sending disabled filters down to the embeddables is an interesting thought, but it might be useful to have this information there in the future (another thing which isn't solved right in my code). Handling this for each embeddable individually is probably the best solution, I will adjust my PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

this code block handling the case when a filter is added from within the dashboard (e.g. clicking a bar in a bar chart)?

Yes, at least for saved searches. For visualizations I think it actually goes through the angular service and by-passes the container but it shouldn't and we need to fix it to get drilldowns to work properly. Also handles any other changes coming from a container, e.g. any actions that modify any container or embeddable state, etc.

Handling this for each embeddable individually is probably the best solution, I will adjust my PR.

sounds good!

@flash1293 flash1293 marked this pull request as ready for review July 18, 2019 13:45
@flash1293 flash1293 requested a review from nreese July 18, 2019 13:45
@flash1293 flash1293 added bug Fixes for quality problems that affect the customer experience Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.4.0 v8.0.0 labels Jul 18, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

That's exactly what I meant by

Input greatly appreciated before I clean up and add tests.

in the PR description 😄

Ahh my apologies @flash1293! I totally missed that line 😬

Saw that you switched it from draft status, so I pulled it down locally to test & I'm having a hard time verifying the changes:

  • In visualize, when I disable a filter it actually removes it completely in the UI
    • It appears to still correctly update the global state (e.g. if I pin a filter in visualize, then disable it, the vis displays the correct value, but the pill disappears. However, pill is visible when i go over to dashboard)
  • In dashboard, when I disable a filter and then edit or invert, I still see the _msearch requests going out.

@flash1293
Copy link
Contributor Author

@lukeelmers It seems like I “optimized” too much here, sorry. I’m going to take care of it. I can’t put the PR back into draft status but I will ping you once this is working as intended.

@flash1293 flash1293 changed the title No reload on changes to disabled filters in visualize and dashboard [WIP] No reload on changes to disabled filters in visualize and dashboard Jul 18, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@flash1293 flash1293 changed the title [WIP] No reload on changes to disabled filters in visualize and dashboard No reload on changes to disabled filters in visualize and dashboard Jul 22, 2019
@flash1293
Copy link
Contributor Author

I tested around a bit and I can't find a case it's not working anymore. Ping @lukeelmers @nreese

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

LGTM

Tested and confirmed that in dashboard, disabling a filter and inverting it (include/exclude) doesn’t create additional requests. Visualize behavior remains unchanged since @lukasolson said he would incorporate it into #41204 instead.

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

lgtm
code review, tested in chrome

@flash1293 flash1293 changed the title No reload on changes to disabled filters in visualize and dashboard No reload on changes to disabled filters in dashboard Jul 25, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

I would suggest that you use the onlyDisabled function from src/legacy/core_plugins/data/public/filter/filter_manager/lib/only_disabled.js (export it on the top level of the plugin to use it)

This function is (a) fully covered by tests and (b) also used by filter manager to detect similar changes.
If you don't like the lodash-y implementaiton, feel free to change it, I would just like us to use the same logic.

@flash1293
Copy link
Contributor Author

Thanks @lizozom I'll update my implementation

@lizozom
Copy link
Contributor

lizozom commented Jul 29, 2019

Filter manager code LGTM

@elasticmachine
Copy link
Contributor

💔 Build Failed

@flash1293
Copy link
Contributor Author

Jenkins, test this.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.4.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants