Skip to content

Commit

Permalink
Fix: Prevent unintentional display of suggestions (#2070)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Aug 31, 2022
1 parent 0f5cbf6 commit c237533
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ const AutoComplete = (props: IAutoCompleteProps) => {
const [suggestions, setSuggestions] = useState<string[]>([]);

useEffect(() => {
if (previousQuery) {
initialiseAutoComplete(sampleQuery.sampleUrl)
}
setQueryUrl(sampleQuery.sampleUrl);
}, [sampleQuery.sampleUrl]);

useEffect(() => {
displayAutoCompleteSuggestions(queryUrl);
if (queryUrl !== previousQuery) {
displayAutoCompleteSuggestions(queryUrl);
}
setIsMultiline(isOverflowing(queryUrl));
}, [autoCompleteOptions, queryUrl]);

Expand All @@ -61,7 +61,6 @@ const AutoComplete = (props: IAutoCompleteProps) => {
};

const initialiseAutoComplete = (currentValue: string) => {
setQueryUrl(currentValue);
if (currentValue.includes(GRAPH_URL)) {
const { index, context } = getLastDelimiterInUrl(currentValue);
const { searchText: searchWith, previous: preceedingText } = getSearchText(currentValue, index!);
Expand Down Expand Up @@ -175,6 +174,8 @@ const AutoComplete = (props: IAutoCompleteProps) => {
const { previous: preceedingText } = getSearchText(url, index!);
const shouldSuggestVersions = preceedingText === GRAPH_URL + '/';

setShouldShowSuggestions(false);

let theSuggestions: string[] = [];
if (shouldSuggestVersions) {
theSuggestions = GRAPH_API_VERSIONS;
Expand All @@ -185,14 +186,11 @@ const AutoComplete = (props: IAutoCompleteProps) => {

if (theSuggestions.length > 0) {
const filtered = (searchText) ? getFilteredSuggestions(searchText, theSuggestions) : theSuggestions;
if (filtered && filtered.length > 0) {
if (filtered.length > 0) {
setSuggestions(filtered);
setShouldShowSuggestions(true);
}
} else {
setShouldShowSuggestions(false);
}

}

const trackSuggestionSelectionEvent = (suggestion: string) => {
Expand Down

0 comments on commit c237533

Please sign in to comment.