Skip to content

Commit

Permalink
Update KQL/filter bar suggestions to cancel when navigating away
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Jun 23, 2020
1 parent b2d3833 commit 61ef4b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class PhraseSuggestorUI<T extends PhraseSuggestorProps> extends React.Com
PhraseSuggestorState
> {
private services = this.props.kibana.services;
private abortController?: AbortController;
public state: PhraseSuggestorState = {
suggestions: [],
isLoading: false,
Expand All @@ -54,6 +55,10 @@ export class PhraseSuggestorUI<T extends PhraseSuggestorProps> extends React.Com
this.updateSuggestions();
}

public componentWillUnmount() {
if (this.abortController) this.abortController.abort();
}

protected isSuggestingValues() {
const shouldSuggestValues = this.services.uiSettings.get(
UI_SETTINGS.FILTERS_EDITOR_SUGGEST_VALUES
Expand All @@ -67,6 +72,8 @@ export class PhraseSuggestorUI<T extends PhraseSuggestorProps> extends React.Com
};

protected updateSuggestions = debounce(async (query: string = '') => {
if (this.abortController) this.abortController.abort();
this.abortController = new AbortController();
const { indexPattern, field } = this.props as PhraseSuggestorProps;
if (!field || !this.isSuggestingValues()) {
return;
Expand All @@ -77,6 +84,7 @@ export class PhraseSuggestorUI<T extends PhraseSuggestorProps> extends React.Com
indexPattern,
field,
query,
signal: this.abortController.signal,
});

this.setState({ suggestions, isLoading: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class QueryStringInputUI extends Component<Props, State> {
public inputRef: HTMLInputElement | null = null;

private persistedLog: PersistedLog | undefined;
private abortController: AbortController | undefined;
private abortController?: AbortController;
private services = this.props.kibana.services;
private componentIsUnmounting = false;

Expand Down Expand Up @@ -497,6 +497,7 @@ export class QueryStringInputUI extends Component<Props, State> {
}

public componentWillUnmount() {
if (this.abortController) this.abortController.abort();
this.updateSuggestions.cancel();
this.componentIsUnmounting = true;
}
Expand Down

0 comments on commit 61ef4b3

Please sign in to comment.