ui: special check for selected values

This commit is contained in:
nick-delirium 2025-02-13 17:27:29 +01:00
parent 08340eb0f4
commit ea142b9596
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0

View file

@ -100,13 +100,19 @@ export function AutocompleteModal({
};
const sortedOptions = React.useMemo(() => {
const withSelected = [...options];
selectedValues.forEach(val => {
if (!options.find(i => i.value === val)) {
withSelected.unshift({ value: val, label: val });
}
})
if (values[0] && values[0].length) {
const sorted = options.sort((a, b) => {
const sorted = withSelected.sort((a, b) => {
return values.includes(a.value) ? -1 : 1;
});
return sorted;
}
return options;
return withSelected;
}, [options, values]);
const queryBlocks = commaQuery ? query.split(',') : [query];