Skip to content

Commit

Permalink
[Maps] fix Kibana does not recognize a valid geo_shape index when att…
Browse files Browse the repository at this point in the history
…empting to create a Tracking Containment alert (elastic#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 <[email protected]>
  • Loading branch information
nreese and kibanamachine committed Apr 9, 2021
1 parent 8c8665e commit 318a0a6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ export declare type IndexPatternSelectProps = Required<Omit<EuiComboBoxProps<any
indexPatternId: string;
fieldTypes?: string[];
onNoIndexPatterns?: () => void;
maxIndexPatterns?: number;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "isInvalid" | "storageKey" | "intl" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "disableLanguageSwitcher" | "autoSubmit" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "isInvalid" | "storageKey" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "disableLanguageSwitcher" | "autoSubmit" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "isInvalid" | "storageKey" | "intl" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "disableLanguageSwitcher" | "autoSubmit" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated"> & ReactIntl.InjectedIntlProps>;
SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "intl" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "intl" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated"> & ReactIntl.InjectedIntlProps>;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexPatternSavedObjectAttrs>);
}
return indexPattern;
}

Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,6 @@ export type IndexPatternSelectProps = Required<Omit<EuiComboBoxProps<any>, '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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type IndexPatternSelectProps = Required<
indexPatternId: string;
fieldTypes?: string[];
onNoIndexPatterns?: () => void;
maxIndexPatterns?: number;
};

export type IndexPatternSelectInternalProps = IndexPatternSelectProps & {
Expand All @@ -42,10 +41,6 @@ interface IndexPatternSelectState {
// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default class IndexPatternSelect extends Component<IndexPatternSelectInternalProps> {
static defaultProps: {
maxIndexPatterns: 1000;
};

private isMounted: boolean = false;
state: IndexPatternSelectState;

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

componentDidMount() {
this.isMounted = true;
this.fetchOptions();
this.fetchOptions('');
this.fetchSelectedIndexPattern(this.props.indexPatternId);
}

Expand Down Expand Up @@ -107,39 +102,59 @@ export default class IndexPatternSelect extends Component<IndexPatternSelectInte
};

debouncedFetch = _.debounce(async (searchValue: string) => {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 318a0a6

Please sign in to comment.