Skip to content

Commit ecc3a7a

Browse files
[ui-sb] moves the destination_path from FormData to query param (#4217)
1 parent c209f6e commit ecc3a7a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

desktop/core/src/desktop/js/utils/hooks/useFileUpload/useRegularUpload.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,17 @@ describe('useRegularUpload', () => {
107107

108108
const mockFormData = new FormData();
109109
mockFormData.append('file', mockFile.file);
110-
mockFormData.append('destination_path', mockFile.filePath);
111110

112-
expect(mockSave).toHaveBeenCalledWith(
113-
mockFormData,
114-
expect.objectContaining({
115-
onSuccess: expect.any(Function),
116-
onError: expect.any(Function)
117-
})
118-
);
111+
expect(mockSave).toHaveBeenCalledWith(mockFormData, {
112+
onSuccess: expect.any(Function),
113+
onError: expect.any(Function),
114+
postOptions: {
115+
onUploadProgress: expect.any(Function),
116+
params: {
117+
destination_path: mockFile.filePath
118+
}
119+
}
120+
});
119121
expect(mockUpdateFileVariables).toHaveBeenCalledWith(mockFile.uuid, {
120122
status: FileStatus.Uploading
121123
});

desktop/core/src/desktop/js/utils/hooks/useFileUpload/useRegularUpload.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import useSaveData from '../useSaveData/useSaveData';
2121
import { getItemProgress } from './utils';
2222
import { RegularFile, FileVariables, FileStatus } from './types';
2323

24-
interface UseUploadQueueResponse {
25-
addFiles: (item: RegularFile[]) => void;
24+
interface UseRegularUploadResponse {
25+
addFiles: (items: RegularFile[], overwrite?: boolean) => void;
2626
cancelFile: (uuid: RegularFile['uuid']) => void;
2727
isLoading: boolean;
2828
}
2929

30-
interface UploadQueueOptions {
30+
interface UseRegularUploadProps {
3131
concurrentProcess?: number;
3232
updateFileVariables: (item: RegularFile['uuid'], variables: FileVariables) => void;
3333
onComplete: () => void;
@@ -37,15 +37,14 @@ const useRegularUpload = ({
3737
concurrentProcess = DEFAULT_CONCURRENT_MAX_CONNECTIONS,
3838
updateFileVariables,
3939
onComplete
40-
}: UploadQueueOptions): UseUploadQueueResponse => {
40+
}: UseRegularUploadProps): UseRegularUploadResponse => {
4141
const { save } = useSaveData(UPLOAD_FILE_URL);
4242

4343
const processRegularFile = async (item: RegularFile) => {
4444
updateFileVariables(item.uuid, { status: FileStatus.Uploading });
4545

4646
const payload = new FormData();
4747
payload.append('file', item.file);
48-
payload.append('destination_path', item.filePath);
4948

5049
return save(payload, {
5150
onSuccess: () => {
@@ -55,6 +54,9 @@ const useRegularUpload = ({
5554
updateFileVariables(item.uuid, { status: FileStatus.Failed, error });
5655
},
5756
postOptions: {
57+
params: {
58+
destination_path: item.filePath
59+
},
5860
onUploadProgress: progress => {
5961
const itemProgress = getItemProgress(progress);
6062
updateFileVariables(item.uuid, { progress: itemProgress });

0 commit comments

Comments
 (0)