Fix console error in SearchToolbar on add filter
This commit is contained in:
parent
0333b47c05
commit
61d60170f3
1 changed files with 12 additions and 3 deletions
|
|
@ -144,9 +144,14 @@ function SearchToolbar({
|
||||||
return (
|
return (
|
||||||
<Autosuggest
|
<Autosuggest
|
||||||
suggestions={suggestions}
|
suggestions={suggestions}
|
||||||
onSuggestionsFetchRequested={({ value }) =>
|
onSuggestionsFetchRequested={({ value }) => {
|
||||||
setSuggestions(getSuggestions(value, query, zoneLabels))
|
// HACK: I'm not sure why, but apparently this gets called with value
|
||||||
}
|
// set to the _chosen suggestion_ after choosing it? Has that
|
||||||
|
// always happened? Idk? Let's just, gate around it, I guess?
|
||||||
|
if (typeof value === "string") {
|
||||||
|
setSuggestions(getSuggestions(value, query, zoneLabels));
|
||||||
|
}
|
||||||
|
}}
|
||||||
onSuggestionSelected={(e, { suggestion }) => {
|
onSuggestionSelected={(e, { suggestion }) => {
|
||||||
const valueWithoutLastWord = query.value.match(/^(.*?)\s*\S+$/)[1];
|
const valueWithoutLastWord = query.value.match(/^(.*?)\s*\S+$/)[1];
|
||||||
onChange({
|
onChange({
|
||||||
|
|
@ -236,6 +241,10 @@ function SearchToolbar({
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSuggestions(value, query, zoneLabels) {
|
function getSuggestions(value, query, zoneLabels) {
|
||||||
|
if (!value) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
const words = value.split(/\s+/);
|
const words = value.split(/\s+/);
|
||||||
const lastWord = words[words.length - 1];
|
const lastWord = words[words.length - 1];
|
||||||
if (lastWord.length < 2) {
|
if (lastWord.length < 2) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue