diff --git a/src/content/dataSubmissions/DataSubmission.tsx b/src/content/dataSubmissions/DataSubmission.tsx index 67c610d9..a7104b57 100644 --- a/src/content/dataSubmissions/DataSubmission.tsx +++ b/src/content/dataSubmissions/DataSubmission.tsx @@ -280,7 +280,7 @@ const columns: Column[] = [ }, { label: "Status", - renderValue: (data) => {data.status === "Rejected" ? {data.status} : data.status}, + renderValue: (data) => {data.status === "Failed" ? {data.status} : data.status}, field: "status", }, { @@ -334,9 +334,11 @@ const DataSubmission = () => { const [batches, setBatches] = useState([]); const [totalBatches, setTotalBatches] = useState(0); + const [hasUploadingBatches, setHasUploadingBatches] = useState(false); const [prevBatchFetch, setPrevBatchFetch] = useState>(null); - const [error, setError] = useState(null); - const [loading, setLoading] = useState(false); + const [batchRefreshTimeout, setBatchRefreshTimeout] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(false); const [openErrorDialog, setOpenErrorDialog] = useState(false); const [openFileListDialog, setOpenFileListDialog] = useState(false); const [selectedRow, setSelectedRow] = useState(null); @@ -409,6 +411,7 @@ const DataSubmission = () => { } setBatches(newBatchFiles.listBatches.batches); setTotalBatches(newBatchFiles.listBatches.total); + setHasUploadingBatches(newBatchFiles.fullStatusList.batches.some((b) => b.status === "Uploading")); } catch (err) { setError("Unable to retrieve batch data."); } finally { @@ -499,6 +502,21 @@ const DataSubmission = () => { } }, [data?.getSubmission?.fileValidationStatus, data?.getSubmission?.metadataValidationStatus]); + useEffect(() => { + if (user?.role !== "Submitter") { + return () => {}; + } + if (!hasUploadingBatches && batchRefreshTimeout) { + clearInterval(batchRefreshTimeout); + setBatchRefreshTimeout(null); + getSubmission(); + } else if (!batchRefreshTimeout && hasUploadingBatches) { + setBatchRefreshTimeout(setInterval(refreshBatchTable, 60000)); + } + + return () => clearInterval(batchRefreshTimeout); + }, [hasUploadingBatches]); + return ( diff --git a/src/graphql/listBatches.ts b/src/graphql/listBatches.ts index b89acc2b..28dc9ec8 100644 --- a/src/graphql/listBatches.ts +++ b/src/graphql/listBatches.ts @@ -54,6 +54,11 @@ export const query = gql` ...BatchFragment @skip(if: $partial) } } + fullStatusList: listBatches(submissionID: $submissionID, first: -1) { + batches { + status + } + } } ${FullBatchFragment} ${BaseBatchFragment} @@ -61,4 +66,7 @@ export const query = gql` export type Response = { listBatches: ListBatches; + fullStatusList: { + batches: Pick[]; + }; }; diff --git a/src/types/Submissions.d.ts b/src/types/Submissions.d.ts index 074374ce..5281e958 100644 --- a/src/types/Submissions.d.ts +++ b/src/types/Submissions.d.ts @@ -91,7 +91,7 @@ type BatchFileInfo = { updatedAt: string // ISO 8601 date time format with UTC or offset e.g., 2023-05-01T09:23:30Z }; -type BatchStatus = "New" | "Uploaded" | "Upload Failed" | "Loaded" | "Rejected"; +type BatchStatus = "Uploading" | "Uploaded" | "Failed"; type MetadataIntention = "New" | "Update" | "Delete";