Skip to content

Commit

Permalink
[8.12] [Discover] Fix "Unsaved changes" badge for ES|QL (el…
Browse files Browse the repository at this point in the history
…astic#174645) (elastic#174832)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Discover] Fix "Unsaved changes" badge for ES|QL
(elastic#174645)](elastic#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":"[email protected]"},"sourceCommit":{"committedDate":"2024-01-15T11:12:56Z","message":"[Discover]
Fix \"Unsaved changes\" badge for ES|QL (elastic#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 (elastic#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 (elastic#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 <[email protected]>
  • Loading branch information
kibanamachine and jughosta authored Jan 15, 2024
1 parent 3c7c2f1 commit 9456432
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
30 changes: 30 additions & 0 deletions test/functional/apps/discover/group3/_unsaved_changes_badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ 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');
const kibanaServer = getService('kibanaServer');
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',
Expand Down Expand Up @@ -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');
});
});
}

0 comments on commit 9456432

Please sign in to comment.