Skip to content

Commit

Permalink
Fix duplicate items appearing in selected list (again) (#5377)
Browse files Browse the repository at this point in the history
* Fix duplicate detection in useListSelect
* Prevent double invocation of select handler
  • Loading branch information
WithoutPants authored Oct 15, 2024
1 parent 32c4844 commit 5283eb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ui/v2.5/src/components/List/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ 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) {
// prevent duplicates
if (prevSelected.some((v) => v.id === id)) {
return prevSelected;
}

const item = items.find((i) => i.id === id);
if (item) {
return [...prevSelected, item];
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/components/Shared/GridCard/GridCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const GridCard: React.FC<ICardProps> = (props: ICardProps) => {
if (props.selecting) {
props.onSelectedChanged(!props.selected, shiftKey);
event.preventDefault();
event.stopPropagation();
}
}

Expand Down

0 comments on commit 5283eb8

Please sign in to comment.