forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Fix "New" link in ES|QL mode (elastic#177038)
- Closes elastic#176873 ## Summary This PR makes sure that when user presses "New" top nav link in Discover, they will stay in ES|QL mode if the previous mode was ES|QL too. The ES|QL query will be reset to the initial one `from <index pattern> | limit 10`. For this query I created a new util `getInitialESQLQuery()`. ### 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 - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
c2b3173
commit a786612
Showing
13 changed files
with
218 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/kbn-esql-utils/src/utils/get_initial_esql_query.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getInitialESQLQuery } from './get_initial_esql_query'; | ||
|
||
describe('getInitialESQLQuery', () => { | ||
it('should work correctly', () => { | ||
expect(getInitialESQLQuery('logs*')).toBe('from logs* | limit 10'); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/kbn-esql-utils/src/utils/get_initial_esql_query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/** | ||
* Builds an ES|QL query for the provided index or index pattern | ||
* @param indexOrIndexPattern | ||
*/ | ||
export function getInitialESQLQuery(indexOrIndexPattern: string): string { | ||
return `from ${indexOrIndexPattern} | limit 10`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
|
||
export default function ({ getService, getPageObjects }: FtrProviderContext) { | ||
const esArchiver = getService('esArchiver'); | ||
const PageObjects = getPageObjects([ | ||
'common', | ||
'discover', | ||
'timePicker', | ||
'header', | ||
'unifiedSearch', | ||
]); | ||
const kibanaServer = getService('kibanaServer'); | ||
const filterBar = getService('filterBar'); | ||
const queryBar = getService('queryBar'); | ||
const monacoEditor = getService('monacoEditor'); | ||
const testSubjects = getService('testSubjects'); | ||
const security = getService('security'); | ||
|
||
describe('discover new search action', function () { | ||
before(async function () { | ||
await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']); | ||
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json'); | ||
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional'); | ||
await kibanaServer.uiSettings.replace({ defaultIndex: 'logstash-*' }); | ||
await PageObjects.common.navigateToApp('discover'); | ||
await PageObjects.timePicker.setDefaultAbsoluteRange(); | ||
}); | ||
|
||
after(async () => { | ||
await kibanaServer.importExport.unload('test/functional/fixtures/kbn_archiver/discover.json'); | ||
await esArchiver.unload('test/functional/fixtures/es_archiver/logstash_functional'); | ||
await kibanaServer.uiSettings.replace({}); | ||
await kibanaServer.savedObjects.cleanStandardList(); | ||
}); | ||
|
||
it('should work correctly for data view mode', async function () { | ||
await filterBar.addFilter({ field: 'extension', operation: 'is', value: 'png' }); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await queryBar.setQuery('bytes > 15000'); | ||
await queryBar.submitQuery(); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await PageObjects.discover.getHitCount()).to.be('353'); | ||
expect(await filterBar.hasFilter('extension', 'png')).to.be(true); | ||
expect(await queryBar.getQueryString()).to.be('bytes > 15000'); | ||
|
||
await PageObjects.discover.clickNewSearchButton(); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await PageObjects.discover.getHitCount()).to.be('14,004'); | ||
expect(await filterBar.hasFilter('extension', 'png')).to.be(false); | ||
expect(await queryBar.getQueryString()).to.be(''); | ||
}); | ||
|
||
it('should work correctly for a saved search in data view mode', async function () { | ||
await PageObjects.discover.createAdHocDataView('logs*', true); | ||
await filterBar.addFilter({ field: 'extension', operation: 'is', value: 'css' }); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await queryBar.setQuery('bytes > 100'); | ||
await queryBar.submitQuery(); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await PageObjects.discover.getHitCount()).to.be('2,108'); | ||
expect(await filterBar.hasFilter('extension', 'css')).to.be(true); | ||
expect(await queryBar.getQueryString()).to.be('bytes > 100'); | ||
|
||
await PageObjects.discover.saveSearch('adHoc'); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await PageObjects.discover.getHitCount()).to.be('2,108'); | ||
|
||
await PageObjects.discover.clickNewSearchButton(); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await PageObjects.discover.getHitCount()).to.be('14,004'); | ||
expect(await filterBar.hasFilter('extension', 'css')).to.be(false); | ||
expect(await queryBar.getQueryString()).to.be(''); | ||
expect( | ||
await PageObjects.unifiedSearch.getSelectedDataView('discover-dataView-switch-link') | ||
).to.be('logs**'); | ||
expect(await PageObjects.discover.isAdHocDataViewSelected()).to.be(true); | ||
}); | ||
|
||
it('should work correctly for ESQL mode', async () => { | ||
await PageObjects.discover.selectTextBaseLang(); | ||
|
||
const testQuery = `from logstash-* | limit 100 | stats countB = count(bytes) by geo.dest | sort countB`; | ||
await monacoEditor.setCodeEditorValue(testQuery); | ||
await testSubjects.click('querySubmitButton'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await PageObjects.discover.getHitCountInt()).to.greaterThan(10); | ||
await testSubjects.existOrFail('unifiedHistogramSuggestionSelector'); | ||
|
||
await PageObjects.discover.clickNewSearchButton(); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await monacoEditor.getCodeEditorValue()).to.be('from logstash-* | limit 10'); | ||
await testSubjects.missingOrFail('unifiedHistogramSuggestionSelector'); // histogram also updated | ||
expect(await PageObjects.discover.getHitCount()).to.be('10'); | ||
}); | ||
|
||
it('should work correctly for a saved search in ESQL mode', async () => { | ||
await PageObjects.discover.selectTextBaseLang(); | ||
|
||
const testQuery = `from logstash-* | limit 100 | stats countB = count(bytes) by geo.dest | sort countB`; | ||
await monacoEditor.setCodeEditorValue(testQuery); | ||
await testSubjects.click('querySubmitButton'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await PageObjects.discover.getHitCountInt()).to.greaterThan(10); | ||
await testSubjects.existOrFail('unifiedHistogramSuggestionSelector'); | ||
|
||
await PageObjects.discover.saveSearch('esql'); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await PageObjects.discover.getHitCountInt()).to.greaterThan(10); | ||
|
||
await PageObjects.discover.clickNewSearchButton(); | ||
await PageObjects.discover.waitUntilSearchingHasFinished(); | ||
expect(await monacoEditor.getCodeEditorValue()).to.be('from logstash-* | limit 10'); | ||
await testSubjects.missingOrFail('unifiedHistogramSuggestionSelector'); // histogram also updated | ||
expect(await PageObjects.discover.getHitCount()).to.be('10'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters