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

[Discover] Address reverting unsaved changes issue to unpin filters #172063

Merged

Conversation

jughosta
Copy link
Contributor

@jughosta jughosta commented Nov 28, 2023

Summary

This PR changes filters diffing logic for the "Unsaved changes" badge and fixes "Revert changes" action of it. What to expect when testing:

  • If user pins a filter and the order of filters does not change, then the badge should not appear.
  • If user has 2 filters for example and pins the second one, then this action would change filters order and the badge would appear.
  • If user presses "Revert changes" action, then newly pinned filters would become unpinned.

Checklist

@jughosta jughosta added the Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. label Nov 28, 2023
@jughosta jughosta self-assigned this Nov 28, 2023

savedSearch.searchSource
.setField('query', state.query ?? undefined)
.setField('filter', [...appFilters, ...globalFilters]);
.setField('filter', [...appFilters, ...cleanedGlobalFilters]);

This comment was marked as outdated.

@@ -52,7 +52,7 @@ export function updateSavedSearch({

savedSearch.searchSource
.setField('query', state.query ?? undefined)
.setField('filter', [...appFilters, ...globalFilters]);
.setField('filter', [...globalFilters, ...appFilters]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In UI pinned filters are rendered first, then app filters. So we better pass them to Elasticsearch in the same order.

Copy link
Member

Choose a reason for hiding this comment

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

Following up about this topic, I just wanted to add some information, because it seems the order of query / filters doesn't matter from ES side, according to https://www.elastic.co/de/blog/elasticsearch-query-execution-order

Q: Does the order in which I put my queries/filters in the query DSL matter?
A: No, because they will be automatically reordered anyway based on their respective costs and match costs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @kertal! Then it's just helpful for the diffing logic.

@jughosta jughosta added Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting labels Nov 30, 2023
@jughosta jughosta marked this pull request as ready for review November 30, 2023 16:06
@jughosta jughosta requested a review from a team as a code owner November 30, 2023 16:06
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@jughosta jughosta requested a review from bhavyarm November 30, 2023 16:08
Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

The code changes look good and it works as described in the summary, but I'm not sure I understand why a change in filter order should trigger the unsaved changes badge if it doesn't impact the request?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding to serverless too!

@jughosta
Copy link
Contributor Author

jughosta commented Dec 4, 2023

@davismcphee

The code changes look good and it works as described in the summary, but I'm not sure I understand why a change in filter order should trigger the unsaved changes badge if it doesn't impact the request?

It's not a change for the request but it is a visual change in the UI. There could be another case when user adds a filter and disables it right away - also it would not impact the request but it's a change nevertheless. So I would rather show the badge then and let the user to revert modifications.

@davismcphee
Copy link
Contributor

It's not a change for the request but it is a visual change in the UI. There could be another case when user adds a filter and disables it right away - also it would not impact the request but it's a change nevertheless. So I would rather show the badge then and let the user to revert modifications.

I can understand the thinking here, and maybe this is more in line with most user's expectations, but as a user I found it difficult to understand why sometimes pinning a filter would trigger unsaved changes and other times not. To phrase it better, I think more importantly than if it affects the request would be if it affects the saved state of the current saved search. The pinned states and order of filters don't, but a disabled filter would, which is why I view these situations differently.

Since @bhavyarm reported the issue, maybe we could get some feedback on what you think would make more sense for users? Pinning/unpinning filters doesn't affect the saved search state, but it will sometimes change the visual order of the filters in the UI. Do you think it makes sense to show the unsaved changes badge only when a pinning/unpinning action changes the visual order of filters, or do you think it would be better to always ignore pinning/unpinning since it doesn't affect the underlying state?

We can also quickly validate with the team tomorrow in our sync. If others agree that the visual order change should trigger the badge, I'm happy to move forward with merging this.

@jughosta jughosta removed the backport:skip This commit does not require backporting label Dec 7, 2023
@jughosta jughosta added the backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) label Dec 7, 2023
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #67 / security APIs - Audit Log Audit Log logs audit events when reading and writing saved objects

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
discover 589.7KB 590.0KB +240.0B

History

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

cc @jughosta

@jughosta
Copy link
Contributor Author

jughosta commented Dec 8, 2023

I think it can be still worth merging as the PR provides an improvement and fixes the "Revert" action. We could revisit whether the filters order should trigger the badge or not later based on users feedback.

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

I think it can be still worth merging as the PR provides an improvement and fixes the "Revert" action. We could revisit whether the filters order should trigger the badge or not later based on users feedback.

I agree 👍 We discussed this as a team, and while I think it would be ideal if filter order didn't matter, there are some technical constraints that make this more difficult, so I think this is fine for now. It solves the more significant issue of the revert not working, and we can revisit later if needed. LGTM, thanks!

@jughosta jughosta merged commit c89c990 into elastic:main Dec 8, 2023
40 checks passed
@jughosta jughosta deleted the 172025-unpin-filters-when-reverting-changes branch December 8, 2023 21:45
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 8, 2023
…lastic#172063)

- Closes elastic#172025

## Summary

This PR changes filters diffing logic for the "Unsaved changes" badge
and fixes "Revert changes" action of it. What to expect when testing:

- If user pins a filter and the order of filters does not change, then
the badge should not appear.
- If user has 2 filters for example and pins the second one, then this
action would change filters order and the badge would appear.
- If user presses "Revert changes" action, then newly pinned filters
would become unpinned.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

(cherry picked from commit c89c990)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.12

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Dec 8, 2023
…lters (#172063) (#172999)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Discover] Address reverting unsaved changes issue to unpin filters
(#172063)](#172063)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Julia
Rechkunova","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-12-08T21:45:31Z","message":"[Discover]
Address reverting unsaved changes issue to unpin filters (#172063)\n\n-
Closes https://github.com/elastic/kibana/issues/172025\r\n\r\n##
Summary\r\n\r\nThis PR changes filters diffing logic for the \"Unsaved
changes\" badge\r\nand fixes \"Revert changes\" action of it. What to
expect when testing:\r\n\r\n- If user pins a filter and the order of
filters does not change, then\r\nthe badge should not appear.\r\n- If
user has 2 filters for example and pins the second one, then
this\r\naction would change filters order and the badge would
appear.\r\n- If user presses \"Revert changes\" action, then newly
pinned filters\r\nwould become unpinned.\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"c89c990f30ea1e01bc29438aa48995fa2477119c","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:skip","Team:DataDiscovery","backport:prev-minor","v8.13.0"],"number":172063,"url":"https://github.com/elastic/kibana/pull/172063","mergeCommit":{"message":"[Discover]
Address reverting unsaved changes issue to unpin filters (#172063)\n\n-
Closes https://github.com/elastic/kibana/issues/172025\r\n\r\n##
Summary\r\n\r\nThis PR changes filters diffing logic for the \"Unsaved
changes\" badge\r\nand fixes \"Revert changes\" action of it. What to
expect when testing:\r\n\r\n- If user pins a filter and the order of
filters does not change, then\r\nthe badge should not appear.\r\n- If
user has 2 filters for example and pins the second one, then
this\r\naction would change filters order and the badge would
appear.\r\n- If user presses \"Revert changes\" action, then newly
pinned filters\r\nwould become unpinned.\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"c89c990f30ea1e01bc29438aa48995fa2477119c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/172063","number":172063,"mergeCommit":{"message":"[Discover]
Address reverting unsaved changes issue to unpin filters (#172063)\n\n-
Closes https://github.com/elastic/kibana/issues/172025\r\n\r\n##
Summary\r\n\r\nThis PR changes filters diffing logic for the \"Unsaved
changes\" badge\r\nand fixes \"Revert changes\" action of it. What to
expect when testing:\r\n\r\n- If user pins a filter and the order of
filters does not change, then\r\nthe badge should not appear.\r\n- If
user has 2 filters for example and pins the second one, then
this\r\naction would change filters order and the badge would
appear.\r\n- If user presses \"Revert changes\" action, then newly
pinned filters\r\nwould become unpinned.\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"c89c990f30ea1e01bc29438aa48995fa2477119c"}}]}]
BACKPORT-->

Co-authored-by: Julia Rechkunova <[email protected]>
@bhavyarm
Copy link
Contributor

@davismcphee I am so sorry I missed your ping here. Thanks very much :) I read through the comments and the fix looks good to me. Thanks @jughosta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.12.0 v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pin across all apps on filter triggers unsaved changes badge
7 participants