diff --git a/src/plugins/discover/public/application/main/services/discover_saved_search_container.ts b/src/plugins/discover/public/application/main/services/discover_saved_search_container.ts index 422fa787da849..ef88aba74d7db 100644 --- a/src/plugins/discover/public/application/main/services/discover_saved_search_container.ts +++ b/src/plugins/discover/public/application/main/services/discover_saved_search_container.ts @@ -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') { diff --git a/test/functional/apps/discover/group3/_unsaved_changes_badge.ts b/test/functional/apps/discover/group3/_unsaved_changes_badge.ts index c931a11f4f5f4..305298ff2ccc6 100644 --- a/test/functional/apps/discover/group3/_unsaved_changes_badge.ts +++ b/test/functional/apps/discover/group3/_unsaved_changes_badge.ts @@ -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'); + }); }); }