From 1ca99baa077240e3846a7bcc58575c9172ff7b15 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Wed, 20 Mar 2024 10:48:59 -0400 Subject: [PATCH] Revert changes Signed-off-by: Ian Bolton --- client/src/app/components/Autocomplete.tsx | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/client/src/app/components/Autocomplete.tsx b/client/src/app/components/Autocomplete.tsx index eebfcbbb9f..419729c908 100644 --- a/client/src/app/components/Autocomplete.tsx +++ b/client/src/app/components/Autocomplete.tsx @@ -81,20 +81,16 @@ export const Autocomplete: React.FC = ({ const filteredOptions = useMemo(() => { const lowerInputValue = inputValue.toLowerCase(); - return options.filter((option) => { - const optionNameLower = toString(option.name).toLowerCase(); - const isNotSelected = !selections.some( - (selection) => selection.id === option.id - ); - const matchesInputValue = optionNameLower.includes(lowerInputValue); - return isNotSelected && matchesInputValue; - }); + return options.filter( + ({ id, name }) => + selections.findIndex((s) => s.id === id) === -1 && // Corrected check for not selected + toString(name).toLowerCase().includes(lowerInputValue) + ); }, [options, selections, inputValue]); /** callback for removing a selection */ const deleteSelectionByItemId = (idToDelete: number) => { - const updatedSelections = selections.filter(({ id }) => id !== idToDelete); - onChange(updatedSelections); + onChange(selections.filter(({ id }) => id !== idToDelete)); }; /** lookup the option matching the itemId and add as a selection */ @@ -190,14 +186,9 @@ export const Autocomplete: React.FC = ({ if (!event || !itemId) { return; } - - const newSelection = options.find((option) => option.id === itemId); - if (newSelection) { - const updatedSelections = [...selections, newSelection].filter(Boolean); - onChange(updatedSelections); - setInputValue(""); - setMenuIsOpen(false); - } + event.stopPropagation(); + focusTextInput(true); + addSelectionByItemId(itemId); }; /** close the menu when a click occurs outside of the menu or text input group */