Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 (autocomplete) fix multi-autocomplete causing crashes #2207

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ function findItem<T extends Item>(
strict: boolean,
suggestions: T[],
value: T | T['id'],
): T | null {
): T | T['id'] | null {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I would have liked to define a type overload for this function so that if strict: true is used - the input value would be T and strict: false would be T['id']. But that's not possible due to a TS limitation

microsoft/TypeScript#24413

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;
}

Expand Down Expand Up @@ -302,7 +298,7 @@ function SingleAutocomplete<T extends Item>({
}
}}
highlightedIndex={highlightedIndex}
selectedItem={selectedItem || null}
selectedItem={selectedItem instanceof Object ? selectedItem : null}
itemToString={itemToString}
inputValue={value}
isOpen={isOpen}
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2207.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---

Fix multi-autocomplete in rules page causing crashes