diff --git a/src/app/views/query-runner/query-input/auto-complete/AutoComplete.tsx b/src/app/views/query-runner/query-input/auto-complete/AutoComplete.tsx index a1b9a4f3c1..e3df3bf222 100644 --- a/src/app/views/query-runner/query-input/auto-complete/AutoComplete.tsx +++ b/src/app/views/query-runner/query-input/auto-complete/AutoComplete.tsx @@ -13,15 +13,13 @@ import { sanitizeQueryUrl } from '../../../../utils/query-url-sanitization'; import { parseSampleUrl } from '../../../../utils/sample-url-generation'; import { translateMessage } from '../../../../utils/translate-messages'; import { queryInputStyles } from '../QueryInput.styles'; - - import { cleanUpSelectedSuggestion, getLastCharacterOf, + getLastSymbolInUrl, getParametersWithVerb } from './auto-complete.util'; import SuggestionsList from './SuggestionsList'; - class AutoComplete extends Component { private autoCompleteRef: React.RefObject; @@ -53,7 +51,7 @@ class AutoComplete extends Component { }, 10); } - public onBlur = (e: any) => { + public updateUrlContent = (e: any) => { const userInput = e.target.value; this.props.contentChanged(userInput); }; @@ -73,7 +71,7 @@ class AutoComplete extends Component { this.initialiseAutoComplete(userInput); }; - public onClick = (e: any) => { + public selectSuggestion = (e: any) => { const selected = e.currentTarget.innerText; this.appendSuggestionToUrl(selected); }; @@ -165,7 +163,7 @@ class AutoComplete extends Component { const controlPeriod = event.ctrlKey && event.keyCode === KeyCodes.period; if (controlSpace || controlPeriod) { const userInput = event.target.value; - const lastSymbol = this.getLastSymbolInUrl(userInput); + const lastSymbol = getLastSymbolInUrl(userInput); const previousUserInput = userInput.substring(0, lastSymbol.value + 1); if (lastSymbol.key === '/' || lastSymbol.key === '?') { const compare = userInput.replace(previousUserInput, ''); @@ -367,42 +365,15 @@ class AutoComplete extends Component { return null; } - private getLastSymbolInUrl(url: string) { - const availableSymbols = [ - { - key: '/', - value: 0 - }, - { - key: ',', - value: 0 - }, - { - key: '$', - value: 0 - }, - { - key: '=', - value: 0 - }, - { - key: '&', - value: 0 - }, - { - key: '?', - value: 0 - } - ]; - - availableSymbols.forEach(element => { - element.value = url.lastIndexOf(element.key); - }); - const max = availableSymbols.reduce((prev, current) => (prev.value > current.value) ? prev : current); - return max; + closeSuggestionDialog = (event: any) => { + const { currentTarget, relatedTarget } = event; + if (!currentTarget.contains(relatedTarget as Node) && this.state.showSuggestions) { + this.setState({ + showSuggestions: false + }) + } } - public render() { const { activeSuggestion, @@ -418,13 +389,13 @@ class AutoComplete extends Component { }: any = queryInputStyles(currentTheme).autoComplete; return ( - <> +
{ this.onClick(e)} />} - + onClick={(e: any) => this.selectSuggestion(e)} />} +
); } } diff --git a/src/app/views/query-runner/query-input/auto-complete/SuggestionsList.tsx b/src/app/views/query-runner/query-input/auto-complete/SuggestionsList.tsx index cc9d411f19..ff77390962 100644 --- a/src/app/views/query-runner/query-input/auto-complete/SuggestionsList.tsx +++ b/src/app/views/query-runner/query-input/auto-complete/SuggestionsList.tsx @@ -26,7 +26,7 @@ const SuggestionsList = (props: any) => { }, [activeSuggestion]); return ( -
    +
      {filteredSuggestions.map((suggestion: {} | null | undefined, index: number) => { return (
    • { + element.value = url.lastIndexOf(element.key); + }); + const max = availableSymbols.reduce((prev, current) => (prev.value > current.value) ? prev : current); + return max; } \ No newline at end of file