Fix duplicate label selection bug in AutocompleteLabelSelector

When attempting to create a label that already exists, the component
would add it to the selected labels without checking if it was already
selected, causing duplicate entries.

Now checks if the label is already selected before adding it.

Fixes issue where creating labels via label select allows duplicate
labels if the label is already assigned.
This commit is contained in:
Jan-Henrik Bruhn 2026-01-24 16:41:44 +01:00
parent 2c91320bb7
commit d17702452d

View file

@ -99,8 +99,10 @@ const AutocompleteLabelSelector = ({ value, onChange, scope }: Props) => {
// Check if ID already exists // Check if ID already exists
if (labels.some((l) => l.id === id)) { if (labels.some((l) => l.id === id)) {
// If label already exists, just select it // If label already exists, just select it (but only if not already selected)
if (!value.includes(id)) {
onChange([...value, id]); onChange([...value, id]);
}
setInputValue(''); setInputValue('');
setIsOpen(false); setIsOpen(false);
setHighlightedIndex(0); setHighlightedIndex(0);