From 719568cd778a82b3548f2e9f030d58c91b26c1ad Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 8 Apr 2021 20:08:10 -0600 Subject: [PATCH] [Maps] fix Kibana does not recognize a valid geo_shape index when attempting to create a Tracking Containment alert (#96633) * [Maps] fix Kibana does not recognize a valid geo_shape index when attempting to create a Tracking Containment alert * tslint * instead of forcing refresh on getIdsAndTitles, update index pattern service to add saved object to cache when index pattern is created * simplify title check * revert unneeded changes * tslint * api doc updates * fix functional test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> # Conflicts: # docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchbar.md --- ...ins-data-public.indexpatternselectprops.md | 1 - .../index_patterns/index_patterns.ts | 3 + src/plugins/data/public/public.api.md | 1 - .../index_pattern_select.tsx | 73 +++++++++++-------- .../input_control_options.ts | 2 +- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternselectprops.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternselectprops.md index 80f4832ba5643..5cfd5e1bc9929 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternselectprops.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternselectprops.md @@ -12,6 +12,5 @@ export declare type IndexPatternSelectProps = Required void; - maxIndexPatterns?: number; }; ``` diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index 2f3884a6481b4..185aa894fe7b8 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -567,6 +567,9 @@ export class IndexPatternsService { }); indexPattern.id = response.id; this.indexPatternCache.set(indexPattern.id, Promise.resolve(indexPattern)); + if (this.savedObjectsCache) { + this.savedObjectsCache.push(response as SavedObject); + } return indexPattern; } diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 8dd977e2f3b0c..84a183f11b5b4 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1537,7 +1537,6 @@ export type IndexPatternSelectProps = Required, 'isLo indexPatternId: string; fieldTypes?: string[]; onNoIndexPatterns?: () => void; - maxIndexPatterns?: number; }; // Warning: (ae-missing-release-tag) "IndexPatternSpec" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx b/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx index aa36323d11bcc..04bdb7a690268 100644 --- a/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx +++ b/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx @@ -25,7 +25,6 @@ export type IndexPatternSelectProps = Required< indexPatternId: string; fieldTypes?: string[]; onNoIndexPatterns?: () => void; - maxIndexPatterns?: number; }; export type IndexPatternSelectInternalProps = IndexPatternSelectProps & { @@ -42,10 +41,6 @@ interface IndexPatternSelectState { // Needed for React.lazy // eslint-disable-next-line import/no-default-export export default class IndexPatternSelect extends Component { - static defaultProps: { - maxIndexPatterns: 1000; - }; - private isMounted: boolean = false; state: IndexPatternSelectState; @@ -67,7 +62,7 @@ export default class IndexPatternSelect extends Component { - const { fieldTypes, onNoIndexPatterns, indexPatternService } = this.props; - const indexPatterns = await indexPatternService.find( - `${searchValue}*`, - this.props.maxIndexPatterns - ); + const isCurrentSearch = () => { + return this.isMounted && searchValue === this.state.searchValue; + }; - // We need this check to handle the case where search results come back in a different - // order than they were sent out. Only load results for the most recent search. - if (searchValue !== this.state.searchValue || !this.isMounted) { + const idsAndTitles = await this.props.indexPatternService.getIdsWithTitle(); + if (!isCurrentSearch()) { return; } - const options = indexPatterns - .filter((indexPattern) => { - return fieldTypes - ? indexPattern.fields.some((field) => { - return fieldTypes.includes(field.type); - }) - : true; - }) - .map((indexPattern) => { - return { - label: indexPattern.title, - value: indexPattern.id, - }; + const options = []; + for (let i = 0; i < idsAndTitles.length; i++) { + if (!idsAndTitles[i].title.toLowerCase().includes(searchValue.toLowerCase())) { + // index pattern excluded due to title not matching search + continue; + } + + if (this.props.fieldTypes) { + try { + const indexPattern = await this.props.indexPatternService.get(idsAndTitles[i].id); + if (!isCurrentSearch()) { + return; + } + const hasRequiredFieldTypes = indexPattern.fields.some((field) => { + return this.props.fieldTypes!.includes(field.type); + }); + if (!hasRequiredFieldTypes) { + continue; + } + } catch (err) { + // could not load index pattern, exclude it from list. + continue; + } + } + + options.push({ + label: idsAndTitles[i].title, + value: idsAndTitles[i].id, }); + + // Loading each index pattern object requires a network call so just find small number of matching index patterns + // Users can use 'searchValue' to further refine the list and locate their index pattern. + if (options.length > 15) { + break; + } + } + this.setState({ isLoading: false, options, }); - if (onNoIndexPatterns && searchValue === '' && options.length === 0) { - onNoIndexPatterns(); + if (this.props.onNoIndexPatterns && searchValue === '' && options.length === 0) { + this.props.onNoIndexPatterns(); } }, 300); diff --git a/test/functional/apps/visualize/input_control_vis/input_control_options.ts b/test/functional/apps/visualize/input_control_vis/input_control_options.ts index dc02cada9a712..2e3b5d758436e 100644 --- a/test/functional/apps/visualize/input_control_vis/input_control_options.ts +++ b/test/functional/apps/visualize/input_control_vis/input_control_options.ts @@ -31,7 +31,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); await PageObjects.visEditor.clickVisEditorTab('controls'); await PageObjects.visEditor.addInputControl(); - await comboBox.set('indexPatternSelect-0', 'logstash- '); + await comboBox.set('indexPatternSelect-0', 'logstash-'); await comboBox.set('fieldSelect-0', FIELD_NAME); await PageObjects.visEditor.clickGo(); });