From 3eee0b11d26b5735a637cb3eec71e41cbd1892c0 Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins Date: Wed, 10 Jan 2024 17:15:34 +0000 Subject: [PATCH] :bug: (autocomplete) fix multi-autocomplete causing crashes (#2207) --- .../src/components/autocomplete/Autocomplete.tsx | 8 ++------ upcoming-release-notes/2207.md | 6 ++++++ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 upcoming-release-notes/2207.md diff --git a/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx b/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx index aa10a321826..10483817b1f 100644 --- a/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx +++ b/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx @@ -31,16 +31,12 @@ function findItem( strict: boolean, suggestions: T[], value: T | T['id'], -): T | null { +): T | T['id'] | null { if (strict) { const idx = suggestions.findIndex(item => item.id === value); return idx === -1 ? null : suggestions[idx]; } - if (typeof value === 'string') { - throw new Error('value can be string only if strict = false'); - } - return value; } @@ -302,7 +298,7 @@ function SingleAutocomplete({ } }} highlightedIndex={highlightedIndex} - selectedItem={selectedItem || null} + selectedItem={selectedItem instanceof Object ? selectedItem : null} itemToString={itemToString} inputValue={value} isOpen={isOpen} diff --git a/upcoming-release-notes/2207.md b/upcoming-release-notes/2207.md new file mode 100644 index 00000000000..4db717c4aed --- /dev/null +++ b/upcoming-release-notes/2207.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [MatissJanis] +--- + +Fix multi-autocomplete in rules page causing crashes