Skip to content

Commit

Permalink
Prevent duplicate entries in selection list
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants committed Oct 9, 2024
1 parent f82e247 commit 70e46f5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ui/v2.5/src/components/List/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ export function useListSelect<T extends { id: string }>(items: T[]) {
function singleSelect(id: string, selected: boolean) {
setLastClickedId(id);

// prevent duplicates
if (selected && selectedIds.has(id)) {
return;
}

setItemsSelected((prevSelected) => {
if (selected) {
const item = items.find((i) => i.id === id);
Expand All @@ -253,7 +258,10 @@ export function useListSelect<T extends { id: string }>(items: T[]) {

const subset = items.slice(start, end + 1);

const newSelected = itemsSelected.concat(subset);
// prevent duplicates
const toAdd = subset.filter((item) => !selectedIds.has(item.id));

const newSelected = itemsSelected.concat(toAdd);
setItemsSelected(newSelected);
}

Expand Down

0 comments on commit 70e46f5

Please sign in to comment.