-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Navigating from Field statistics tab to text based languag…
…es should return to the documents view (#152572) Closes #152485 ~Would be better to override this somewhere in app state management logic but I could not find a right place for it.~ Done Current changes make sure that for text-based queries only grid view is possible (both on Discover and as embeddable) and the app state will be updated accordingly.
- Loading branch information
Showing
10 changed files
with
207 additions
and
15 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
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
58 changes: 58 additions & 0 deletions
58
src/plugins/discover/public/application/main/utils/get_valid_view_mode.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,58 @@ | ||
/* | ||
* 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 { VIEW_MODE } from '@kbn/saved-search-plugin/common'; | ||
import { getValidViewMode } from './get_valid_view_mode'; | ||
|
||
describe('getValidViewMode', () => { | ||
test('should work correctly for regular mode', () => { | ||
expect( | ||
getValidViewMode({ | ||
viewMode: undefined, | ||
isTextBasedQueryMode: false, | ||
}) | ||
).toBeUndefined(); | ||
|
||
expect( | ||
getValidViewMode({ | ||
viewMode: VIEW_MODE.DOCUMENT_LEVEL, | ||
isTextBasedQueryMode: false, | ||
}) | ||
).toBe(VIEW_MODE.DOCUMENT_LEVEL); | ||
|
||
expect( | ||
getValidViewMode({ | ||
viewMode: VIEW_MODE.AGGREGATED_LEVEL, | ||
isTextBasedQueryMode: false, | ||
}) | ||
).toBe(VIEW_MODE.AGGREGATED_LEVEL); | ||
}); | ||
|
||
test('should work correctly for text-based mode', () => { | ||
expect( | ||
getValidViewMode({ | ||
viewMode: undefined, | ||
isTextBasedQueryMode: true, | ||
}) | ||
).toBeUndefined(); | ||
|
||
expect( | ||
getValidViewMode({ | ||
viewMode: VIEW_MODE.DOCUMENT_LEVEL, | ||
isTextBasedQueryMode: true, | ||
}) | ||
).toBe(VIEW_MODE.DOCUMENT_LEVEL); | ||
|
||
expect( | ||
getValidViewMode({ | ||
viewMode: VIEW_MODE.AGGREGATED_LEVEL, | ||
isTextBasedQueryMode: true, | ||
}) | ||
).toBe(VIEW_MODE.DOCUMENT_LEVEL); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/plugins/discover/public/application/main/utils/get_valid_view_mode.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,29 @@ | ||
/* | ||
* 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 { VIEW_MODE } from '@kbn/saved-search-plugin/public'; | ||
|
||
/** | ||
* Returns a valid view mode | ||
* @param viewMode | ||
* @param isTextBasedQueryMode | ||
*/ | ||
export const getValidViewMode = ({ | ||
viewMode, | ||
isTextBasedQueryMode, | ||
}: { | ||
viewMode?: VIEW_MODE; | ||
isTextBasedQueryMode: boolean; | ||
}): VIEW_MODE | undefined => { | ||
if (viewMode === VIEW_MODE.AGGREGATED_LEVEL && isTextBasedQueryMode) { | ||
// only this mode is supported for text-based languages | ||
return VIEW_MODE.DOCUMENT_LEVEL; | ||
} | ||
|
||
return viewMode; | ||
}; |
17 changes: 17 additions & 0 deletions
17
src/plugins/discover/public/application/main/utils/is_text_based_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,17 @@ | ||
/* | ||
* 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 { isTextBasedQuery } from './is_text_based_query'; | ||
|
||
describe('isTextBasedQuery', () => { | ||
it('should work correctly', () => { | ||
expect(isTextBasedQuery({ query: '', language: 'lucene' })).toEqual(false); | ||
expect(isTextBasedQuery({ sql: 'SELECT * from foo' })).toEqual(true); | ||
expect(isTextBasedQuery()).toEqual(false); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/plugins/discover/public/application/main/utils/is_text_based_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,18 @@ | ||
/* | ||
* 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 type { AggregateQuery, Query } from '@kbn/es-query'; | ||
import { RecordRawType } from '../services/discover_data_state_container'; | ||
import { getRawRecordType } from './get_raw_record_type'; | ||
|
||
/** | ||
* Checks if the query is of AggregateQuery type | ||
* @param query | ||
*/ | ||
export function isTextBasedQuery(query?: Query | AggregateQuery): query is AggregateQuery { | ||
return getRawRecordType(query) === RecordRawType.PLAIN; | ||
} |
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