From d4b3ca5325fb362c45f89acaac8650890660d6e1 Mon Sep 17 00:00:00 2001 From: Danny Banks Date: Thu, 16 Nov 2023 13:00:39 -0800 Subject: [PATCH] fix(storagemanager): upload action now displays state properly (#4666) Co-authored-by: Caleb Pollman --- .../upload-actions/index.page.tsx | 2 +- .../__tests__/reducer.test.ts | 55 +++++++++++++++++++ .../hooks/useStorageManager/reducer.ts | 4 +- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/examples/next/pages/ui/components/storage/storage-manager/upload-actions/index.page.tsx b/examples/next/pages/ui/components/storage/storage-manager/upload-actions/index.page.tsx index 04968ec3feb..4ddc08125e3 100644 --- a/examples/next/pages/ui/components/storage/storage-manager/upload-actions/index.page.tsx +++ b/examples/next/pages/ui/components/storage/storage-manager/upload-actions/index.page.tsx @@ -10,7 +10,7 @@ export function StorageManagerExample() { acceptedFileTypes={['image/*']} accessLevel="guest" autoUpload={false} - maxFileCount={1} + maxFileCount={10} showThumbnails /> ); diff --git a/packages/react-storage/src/components/StorageManager/hooks/useStorageManager/__tests__/reducer.test.ts b/packages/react-storage/src/components/StorageManager/hooks/useStorageManager/__tests__/reducer.test.ts index a2ce3efe933..44984a0d390 100644 --- a/packages/react-storage/src/components/StorageManager/hooks/useStorageManager/__tests__/reducer.test.ts +++ b/packages/react-storage/src/components/StorageManager/hooks/useStorageManager/__tests__/reducer.test.ts @@ -309,4 +309,59 @@ describe('storageManagerStateReducer', () => { expect(result.current.state.files).toEqual([file]); }); + + it('should only change added files to queued in QUEUE_FILES action', () => { + const { result } = renderHook(() => { + const [state, dispatch] = useReducer(storageManagerStateReducer, { + files: [ + { + id: imageFile.name, + file: imageFile, + error: '', + key: imageFile.name, + status: FileStatus.ADDED, + isImage: true, + progress: -1, + }, + { + id: imageFile.name, + file: imageFile, + error: '', + key: imageFile.name, + status: FileStatus.UPLOADED, + isImage: true, + progress: 100, + }, + ], + }); + return { state, dispatch }; + }); + + const queueFilesAction: Action = { + type: StorageManagerActionTypes.QUEUE_FILES, + }; + + act(() => result.current.dispatch(queueFilesAction)); + + expect(result.current.state.files).toEqual([ + { + id: imageFile.name, + file: imageFile, + error: '', + key: imageFile.name, + status: FileStatus.QUEUED, + isImage: true, + progress: -1, + }, + { + id: imageFile.name, + file: imageFile, + error: '', + key: imageFile.name, + status: FileStatus.UPLOADED, + isImage: true, + progress: 100, + }, + ]); + }); }); diff --git a/packages/react-storage/src/components/StorageManager/hooks/useStorageManager/reducer.ts b/packages/react-storage/src/components/StorageManager/hooks/useStorageManager/reducer.ts index 693d48ab9b2..4ff7596dd25 100644 --- a/packages/react-storage/src/components/StorageManager/hooks/useStorageManager/reducer.ts +++ b/packages/react-storage/src/components/StorageManager/hooks/useStorageManager/reducer.ts @@ -50,7 +50,9 @@ export function storageManagerStateReducer( ...files, { ...currentFile, - status: FileStatus.QUEUED, + ...(currentFile.status === FileStatus.ADDED + ? { status: FileStatus.QUEUED } + : {}), }, ]; }, []);