Skip to content

Commit

Permalink
Deduplicate selected ids
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Oct 4, 2024
1 parent fb108d5 commit 2117ae9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useMassSelection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('useMassSelection', () => {
});

describe('selectMultipleIds()', () => {
it('should return what type of selection', () => {
it('should select multiple ids and deduplicate selected ids', () => {
const { result, rerender } = renderHook(() =>
useMassSelection(defaultIdsList),
);
Expand All @@ -96,7 +96,7 @@ describe('useMassSelection', () => {
rerender();
expect(result.current.ids).toEqual(['1', '2', '3']);

result.current.selectMultipleIds(['4', '5', '6']);
result.current.selectMultipleIds(['3', '4', '5', '6']);
rerender();
expect(result.current.ids).toEqual(['1', '2', '3', '4', '5', '6']);
});
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMassSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useMassSelection = (
};

const selectMultipleIds = (newIds: string[]) => {
setIds([...ids, ...newIds]);
setIds([...ids, ...newIds.filter((newId) => !ids.includes(newId))]);
};

const deselectMultipleIds = (idsToRemove: string[]) => {
Expand Down

0 comments on commit 2117ae9

Please sign in to comment.