Skip to content

Commit

Permalink
Use abort controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Oct 19, 2020
1 parent 9fb9d94 commit 29cc3ca
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default class QueryStringInputUI extends Component<Props, State> {

private persistedLog: PersistedLog | undefined;
private abortController?: AbortController;
private fetchIndexPatternsAbortController: AbortController = new AbortController();
private services = this.props.kibana.services;
private componentIsUnmounting = false;
private queryBarInputDivRefInstance: RefObject<HTMLDivElement> = createRef();
Expand All @@ -127,17 +128,25 @@ export default class QueryStringInputUI extends Component<Props, State> {
(indexPattern) => typeof indexPattern !== 'string'
) as IIndexPattern[];

this.fetchIndexPatternsAbortController = new AbortController();

const objectPatternsFromStrings = (await fetchIndexPatterns(
this.services.savedObjects!.client,
stringPatterns,
this.services.uiSettings!
)) as IIndexPattern[];

this.setState({
indexPatterns: [...objectPatterns, ...objectPatternsFromStrings],
});
if (!this.fetchIndexPatternsAbortController.signal.aborted) {
// abort the previous fetch to avoid overriding with outdated data
// issue https://github.com/elastic/kibana/issues/80831
this.fetchIndexPatternsAbortController.abort();

this.updateSuggestions();
this.setState({
indexPatterns: [...objectPatterns, ...objectPatternsFromStrings],
});

this.updateSuggestions();
}
}, 200);

private getSuggestions = async () => {
Expand Down

0 comments on commit 29cc3ca

Please sign in to comment.