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] Fix "Unsaved changes" badge for ES|QL #174645

Merged
merged 4 commits into from
Jan 15, 2024

Conversation

jughosta
Copy link
Contributor

@jughosta jughosta commented Jan 10, 2024

Summary

This PR fixes a bug where "Unsaved changes" badge would appear after page refresh for an ES|QL saved search.

To reproduce on main:

  • Create a new ES|QL saved search
  • Reload the page => Notice that the badge appeared

With this PR the issue should be resolved. It was caused by the fact that adhoc data view id might change internally.

Checklist

@jughosta jughosta added Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) backport:prev-minor Backport to the previous minor version (i.e. one version back from main) labels Jan 10, 2024
@jughosta jughosta self-assigned this Jan 10, 2024
@jughosta
Copy link
Contributor Author

/ci

@jughosta
Copy link
Contributor Author

/ci

@jughosta jughosta marked this pull request as ready for review January 10, 2024 20:46
@jughosta jughosta requested a review from a team as a code owner January 10, 2024 20:46
@elasticmachine
Copy link
Contributor

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

@@ -318,7 +318,9 @@ function getSearchSourceFieldValueForComparison(
searchSourceFieldName: keyof SearchSourceFields
) {
if (searchSourceFieldName === 'index') {
return searchSource.getField('index')?.id;
const query = searchSource.getField('query');
// ad-hoc data view id can change, so we rather compare the ES|QL query itself here
Copy link
Member

Choose a reason for hiding this comment

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

this makes sense, I've got one question, when does the id change in ES|QL and the query.esql doesn't? A quick thought, maybe, when initializing the ad-hoc data view, we could use the used index-pattern (with a prefix) as id. This could also maybe fix the problem of having multiple data views with the same index pattern on a dashboard. So ids wouldn't be random but derived from the used index pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kertal I have not found yet why/when it changes

Copy link
Member

Choose a reason for hiding this comment

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

maybe if you change the index pattern in the ES|QL query, and then go back to the previous query. Then it will high likely get a new ID

const dataViewObj = await services.dataViews.create({
title: indexPatternFromQuery,
});

So if we would assign an id derived by the used index pattern here, then it should be stable (it's not something for this PR, but I'm now continuing thinking, because this might also fix the problem of having multiple data views on a dashboard with the same index pattern) ... FYI @stratoula ... is there a reason not to use a data view id generated by the index pattern of the ES|QL query? like esql-{indexpattern} or esql-{indexpatternHash}

Copy link
Contributor

Choose a reason for hiding this comment

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

This can actually work Matthias, very good idea 👏

Copy link
Contributor

Choose a reason for hiding this comment

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

I can give it a try tomorrow to see how it will work!

@stratoula
Copy link
Contributor

@jughosta @kertal Matthias' idea seems to solve this problem and the one with the multiple identical dataviews in the dashboards. So let's pause this PR, I will let you know

@jughosta
Copy link
Contributor Author

@stratoula Sure! If your fix can be also backported to 8.12 then it would be great!

@stratoula
Copy link
Contributor

I would prefer to not backport it, I want to merge it and have this tested (I did the same change for Lens charts). ES|QL is on tech preview so it is fine if there are some bugs before GA.

@jughosta
Copy link
Contributor Author

@stratoula Okay, then it still makes sense to backport this PR to fix the badge which we introduced in 8.12.

@stratoula
Copy link
Contributor

stratoula commented Jan 12, 2024

Yes this makes sense 👍 Checking your code, I like your change. It makes more sense to check the query rather than the id for ES|QL (taken under consideration that ES|QL works without dataviews). So on second thoughts I feel we should proceed with this change in general. Wdyt?

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thx for fixing this and adding a functional test on top !

@jughosta jughosta enabled auto-merge (squash) January 15, 2024 10:05
@kibana-ci
Copy link
Collaborator

💚 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
discover 564.1KB 564.1KB +50.0B

History

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

cc @jughosta

@jughosta jughosta merged commit 900ab21 into elastic:main Jan 15, 2024
19 checks passed
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 15, 2024
## Summary

This PR fixes a bug where "Unsaved changes" badge would appear after
page refresh for an ES|QL saved search.

To reproduce on main:
- Create a new ES|QL saved search
- Reload the page => Notice that the badge appeared

With this PR the issue should be resolved. It was caused by the fact
that adhoc data view id might change internally.

### 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 900ab21)
@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 Jan 15, 2024
…74645) (#174832)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Discover] Fix "Unsaved changes" badge for ES|QL
(#174645)](#174645)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Julia
Rechkunova","email":"julia.rechkunova@elastic.co"},"sourceCommit":{"committedDate":"2024-01-15T11:12:56Z","message":"[Discover]
Fix \"Unsaved changes\" badge for ES|QL (#174645)\n\n##
Summary\r\n\r\nThis PR fixes a bug where \"Unsaved changes\" badge would
appear after\r\npage refresh for an ES|QL saved search.\r\n\r\nTo
reproduce on main:\r\n- Create a new ES|QL saved search\r\n- Reload the
page => Notice that the badge appeared\r\n\r\nWith this PR the issue
should be resolved. It was caused by the fact\r\nthat adhoc data view id
might change internally.\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":"900ab217a2cba446c923ac3bd46795d6c70fe106","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"],"title":"[Discover]
Fix \"Unsaved changes\" badge for
ES|QL","number":174645,"url":"#174645
Fix \"Unsaved changes\" badge for ES|QL (#174645)\n\n##
Summary\r\n\r\nThis PR fixes a bug where \"Unsaved changes\" badge would
appear after\r\npage refresh for an ES|QL saved search.\r\n\r\nTo
reproduce on main:\r\n- Create a new ES|QL saved search\r\n- Reload the
page => Notice that the badge appeared\r\n\r\nWith this PR the issue
should be resolved. It was caused by the fact\r\nthat adhoc data view id
might change internally.\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":"900ab217a2cba446c923ac3bd46795d6c70fe106"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","branchLabelMappingKey":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"#174645
Fix \"Unsaved changes\" badge for ES|QL (#174645)\n\n##
Summary\r\n\r\nThis PR fixes a bug where \"Unsaved changes\" badge would
appear after\r\npage refresh for an ES|QL saved search.\r\n\r\nTo
reproduce on main:\r\n- Create a new ES|QL saved search\r\n- Reload the
page => Notice that the badge appeared\r\n\r\nWith this PR the issue
should be resolved. It was caused by the fact\r\nthat adhoc data view id
might change internally.\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":"900ab217a2cba446c923ac3bd46795d6c70fe106"}}]}]
BACKPORT-->

Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
@mistic mistic added v8.12.1 and removed v8.12.0 labels Jan 17, 2024
@mistic
Copy link
Member

mistic commented Jan 17, 2024

This PR didn't make it into the latest BC for 8.12.0. Updating the labels.

CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
## Summary

This PR fixes a bug where "Unsaved changes" badge would appear after
page refresh for an ES|QL saved search.

To reproduce on main:
- Create a new ES|QL saved search
- Reload the page => Notice that the badge appeared

With this PR the issue should be resolved. It was caused by the fact
that adhoc data view id might change internally.


### 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to 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 App Team (Document Explorer, Saved Search, Surrounding documents, Graph) v8.12.1 v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants