Skip to content

Commit

Permalink
Send update upload status to new endpoint shape using sampleFileId
Browse files Browse the repository at this point in the history
Signed-off-by: cosa65 <[email protected]>
  • Loading branch information
cosa65 committed Nov 28, 2023
1 parent 0204a7e commit f14b0aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/redux/actions/samples/createSampleFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ const createSampleFile = (
) => async (dispatch) => {
const updatedAt = dayjs().toISOString();

const sampleFileId = uuidv4();

try {
const url = `/v2/experiments/${experimentId}/samples/${sampleId}/sampleFiles/${type}`;
const body = {
sampleFileId: uuidv4(),
sampleFileId,
size: fileForApiV1.size,
};

Expand Down Expand Up @@ -49,7 +51,9 @@ const createSampleFile = (

return body.sampleFileId;
} catch (e) {
dispatch(updateSampleFileUpload(experimentId, sampleId, type, UploadStatus.UPLOAD_ERROR));
dispatch(updateSampleFileUpload(
experimentId, sampleId, sampleFileId, type, UploadStatus.UPLOAD_ERROR,
));

throw e;
}
Expand Down
4 changes: 2 additions & 2 deletions src/redux/actions/samples/updateSampleFileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import UploadStatus from 'utils/upload/UploadStatus';
import fileNameForApiV1 from 'utils/upload/fileNameForApiV1';

const updateSampleFileUpload = (
experimentId, sampleId, type, uploadStatus, uploadProgress,
experimentId, sampleId, sampleFileId, type, uploadStatus, uploadProgress,
) => async (dispatch) => {
const updatedAt = dayjs().toISOString();

// Don't send an api update whenever the progress bar is updated, only for uploadStatus changes
// TODO: move progress to not even be a part of redux, manage it in a different way
if (uploadStatus !== UploadStatus.UPLOADING) {
const url = `/v2/experiments/${experimentId}/samples/${sampleId}/sampleFiles/${type}`;
const url = `/v2/experiments/${experimentId}/sampleFiles/${sampleFileId}`;
const body = { uploadStatus };

try {
Expand Down
10 changes: 6 additions & 4 deletions src/utils/upload/processUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const createAndUploadSampleFile = async (file, experimentId, sampleId, dispatch,
try {
file.fileObject = await loadAndCompressIfNecessary(file, () => {
dispatch(updateSampleFileUpload(
experimentId, sampleId, fileType, UploadStatus.COMPRESSING,
experimentId, sampleId, sampleFileId, fileType, UploadStatus.COMPRESSING,
));
});

Expand All @@ -94,7 +94,9 @@ const createAndUploadSampleFile = async (file, experimentId, sampleId, dispatch,
? UploadStatus.FILE_READ_ABORTED
: UploadStatus.FILE_READ_ERROR;

dispatch(updateSampleFileUpload(experimentId, sampleId, fileType, fileErrorStatus));
dispatch(updateSampleFileUpload(
experimentId, sampleId, sampleFileId, fileType, fileErrorStatus,
));
return;
}
}
Expand All @@ -109,7 +111,7 @@ const createAndUploadSampleFile = async (file, experimentId, sampleId, dispatch,

const updateSampleFileUploadProgress = (status, percentProgress = 0) => dispatch(
updateSampleFileUpload(
experimentId, sampleId, fileType, status, percentProgress,
experimentId, sampleId, sampleFileId, fileType, status, percentProgress,
),
);

Expand All @@ -118,7 +120,7 @@ const createAndUploadSampleFile = async (file, experimentId, sampleId, dispatch,
await prepareAndUploadFileToS3(file, uploadUrlParams, 'sample', updateSampleFileUploadProgress);
} catch (e) {
dispatch(updateSampleFileUpload(
experimentId, sampleId, fileType, UploadStatus.UPLOAD_ERROR,
experimentId, sampleId, sampleFileId, fileType, UploadStatus.UPLOAD_ERROR,
));
}
};
Expand Down

0 comments on commit f14b0aa

Please sign in to comment.