From 2117ae9d91cf7de3fa0f959118922ff0582bc017 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Fri, 4 Oct 2024 15:33:02 -0500 Subject: [PATCH] Deduplicate selected ids --- src/hooks/useMassSelection.test.ts | 4 ++-- src/hooks/useMassSelection.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hooks/useMassSelection.test.ts b/src/hooks/useMassSelection.test.ts index 9ea830e9d..bbe5aaca8 100644 --- a/src/hooks/useMassSelection.test.ts +++ b/src/hooks/useMassSelection.test.ts @@ -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), ); @@ -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']); }); diff --git a/src/hooks/useMassSelection.ts b/src/hooks/useMassSelection.ts index 239924d7e..d9a849e3a 100644 --- a/src/hooks/useMassSelection.ts +++ b/src/hooks/useMassSelection.ts @@ -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[]) => {