[8.12] [Discover] Fix "Unsaved changes" badge for ES|QL (#174645) (#174832)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Discover] Fix "Unsaved changes" badge for ES|QL
(#174645)](https://github.com/elastic/kibana/pull/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":"https://github.com/elastic/kibana/pull/174645","mergeCommit":{"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"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","branchLabelMappingKey":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/174645","number":174645,"mergeCommit":{"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"}}]}]
BACKPORT-->

Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
This commit is contained in:
Kibana Machine 2024-01-15 07:50:33 -05:00 committed by GitHub
parent 3c7c2f16cc
commit 945643256d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View file

@ -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
return query && 'esql' in query ? query.esql : searchSource.getField('index')?.id;
}
if (searchSourceFieldName === 'filter') {

View file

@ -11,6 +11,7 @@ import { FtrProviderContext } from '../ftr_provider_context';
const SAVED_SEARCH_NAME = 'test saved search';
const SAVED_SEARCH_WITH_FILTERS_NAME = 'test saved search with filters';
const SAVED_SEARCH_ESQL = 'test saved search ES|QL';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
@ -18,6 +19,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const dataGrid = getService('dataGrid');
const filterBar = getService('filterBar');
const monacoEditor = getService('monacoEditor');
const browser = getService('browser');
const PageObjects = getPageObjects([
'settings',
'common',
@ -194,5 +197,32 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await filterBar.isFilterNegated('bytes')).to.be(false);
expect(await PageObjects.discover.getHitCount()).to.be('1,373');
});
it('should not show a badge after loading an ES|QL saved search, only after changes', async () => {
await PageObjects.discover.selectTextBaseLang();
await monacoEditor.setCodeEditorValue('from logstash-* | limit 10');
await testSubjects.click('querySubmitButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
await PageObjects.discover.saveSearch(SAVED_SEARCH_ESQL);
await PageObjects.discover.waitUntilSearchingHasFinished();
await testSubjects.missingOrFail('unsavedChangesBadge');
await browser.refresh();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
await testSubjects.missingOrFail('unsavedChangesBadge');
await monacoEditor.setCodeEditorValue('from logstash-* | limit 100');
await testSubjects.click('querySubmitButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();
await testSubjects.existOrFail('unsavedChangesBadge');
});
});
}