Skip to content

Commit 719568c

Browse files
nreesekibanamachine
andcommitted
[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
1 parent 0b111dc commit 719568c

5 files changed

Lines changed: 48 additions & 32 deletions

File tree

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternselectprops.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ export declare type IndexPatternSelectProps = Required<Omit<EuiComboBoxProps<any
1212
indexPatternId: string;
1313
fieldTypes?: string[];
1414
onNoIndexPatterns?: () => void;
15-
maxIndexPatterns?: number;
1615
};
1716
```

src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@ export class IndexPatternsService {
567567
});
568568
indexPattern.id = response.id;
569569
this.indexPatternCache.set(indexPattern.id, Promise.resolve(indexPattern));
570+
if (this.savedObjectsCache) {
571+
this.savedObjectsCache.push(response as SavedObject<IndexPatternSavedObjectAttrs>);
572+
}
570573
return indexPattern;
571574
}
572575

src/plugins/data/public/public.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,6 @@ export type IndexPatternSelectProps = Required<Omit<EuiComboBoxProps<any>, 'isLo
15371537
indexPatternId: string;
15381538
fieldTypes?: string[];
15391539
onNoIndexPatterns?: () => void;
1540-
maxIndexPatterns?: number;
15411540
};
15421541

15431542
// Warning: (ae-missing-release-tag) "IndexPatternSpec" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)

src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export type IndexPatternSelectProps = Required<
2525
indexPatternId: string;
2626
fieldTypes?: string[];
2727
onNoIndexPatterns?: () => void;
28-
maxIndexPatterns?: number;
2928
};
3029

3130
export type IndexPatternSelectInternalProps = IndexPatternSelectProps & {
@@ -42,10 +41,6 @@ interface IndexPatternSelectState {
4241
// Needed for React.lazy
4342
// eslint-disable-next-line import/no-default-export
4443
export default class IndexPatternSelect extends Component<IndexPatternSelectInternalProps> {
45-
static defaultProps: {
46-
maxIndexPatterns: 1000;
47-
};
48-
4944
private isMounted: boolean = false;
5045
state: IndexPatternSelectState;
5146

@@ -67,7 +62,7 @@ export default class IndexPatternSelect extends Component<IndexPatternSelectInte
6762

6863
componentDidMount() {
6964
this.isMounted = true;
70-
this.fetchOptions();
65+
this.fetchOptions('');
7166
this.fetchSelectedIndexPattern(this.props.indexPatternId);
7267
}
7368

@@ -107,39 +102,59 @@ export default class IndexPatternSelect extends Component<IndexPatternSelectInte
107102
};
108103

109104
debouncedFetch = _.debounce(async (searchValue: string) => {
110-
const { fieldTypes, onNoIndexPatterns, indexPatternService } = this.props;
111-
const indexPatterns = await indexPatternService.find(
112-
`${searchValue}*`,
113-
this.props.maxIndexPatterns
114-
);
105+
const isCurrentSearch = () => {
106+
return this.isMounted && searchValue === this.state.searchValue;
107+
};
115108

116-
// We need this check to handle the case where search results come back in a different
117-
// order than they were sent out. Only load results for the most recent search.
118-
if (searchValue !== this.state.searchValue || !this.isMounted) {
109+
const idsAndTitles = await this.props.indexPatternService.getIdsWithTitle();
110+
if (!isCurrentSearch()) {
119111
return;
120112
}
121113

122-
const options = indexPatterns
123-
.filter((indexPattern) => {
124-
return fieldTypes
125-
? indexPattern.fields.some((field) => {
126-
return fieldTypes.includes(field.type);
127-
})
128-
: true;
129-
})
130-
.map((indexPattern) => {
131-
return {
132-
label: indexPattern.title,
133-
value: indexPattern.id,
134-
};
114+
const options = [];
115+
for (let i = 0; i < idsAndTitles.length; i++) {
116+
if (!idsAndTitles[i].title.toLowerCase().includes(searchValue.toLowerCase())) {
117+
// index pattern excluded due to title not matching search
118+
continue;
119+
}
120+
121+
if (this.props.fieldTypes) {
122+
try {
123+
const indexPattern = await this.props.indexPatternService.get(idsAndTitles[i].id);
124+
if (!isCurrentSearch()) {
125+
return;
126+
}
127+
const hasRequiredFieldTypes = indexPattern.fields.some((field) => {
128+
return this.props.fieldTypes!.includes(field.type);
129+
});
130+
if (!hasRequiredFieldTypes) {
131+
continue;
132+
}
133+
} catch (err) {
134+
// could not load index pattern, exclude it from list.
135+
continue;
136+
}
137+
}
138+
139+
options.push({
140+
label: idsAndTitles[i].title,
141+
value: idsAndTitles[i].id,
135142
});
143+
144+
// Loading each index pattern object requires a network call so just find small number of matching index patterns
145+
// Users can use 'searchValue' to further refine the list and locate their index pattern.
146+
if (options.length > 15) {
147+
break;
148+
}
149+
}
150+
136151
this.setState({
137152
isLoading: false,
138153
options,
139154
});
140155

141-
if (onNoIndexPatterns && searchValue === '' && options.length === 0) {
142-
onNoIndexPatterns();
156+
if (this.props.onNoIndexPatterns && searchValue === '' && options.length === 0) {
157+
this.props.onNoIndexPatterns();
143158
}
144159
}, 300);
145160

test/functional/apps/visualize/input_control_vis/input_control_options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
3131
);
3232
await PageObjects.visEditor.clickVisEditorTab('controls');
3333
await PageObjects.visEditor.addInputControl();
34-
await comboBox.set('indexPatternSelect-0', 'logstash- ');
34+
await comboBox.set('indexPatternSelect-0', 'logstash-');
3535
await comboBox.set('fieldSelect-0', FIELD_NAME);
3636
await PageObjects.visEditor.clickGo();
3737
});

0 commit comments

Comments
 (0)