Skip to content

Commit

Permalink
Merge pull request #269 from CBIIT/CRDCDH-754
Browse files Browse the repository at this point in the history
CRDCDH-754 Poll for Batch Status Updates
  • Loading branch information
Alejandro-Vega authored Jan 30, 2024
2 parents a263894 + 1c2e943 commit 6c749d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/content/dataSubmissions/DataSubmission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const columns: Column<Batch>[] = [
},
{
label: "Status",
renderValue: (data) => <Box textTransform="capitalize">{data.status === "Rejected" ? <StyledRejectedStatus>{data.status}</StyledRejectedStatus> : data.status}</Box>,
renderValue: (data) => <Box textTransform="capitalize">{data.status === "Failed" ? <StyledRejectedStatus>{data.status}</StyledRejectedStatus> : data.status}</Box>,
field: "status",
},
{
Expand Down Expand Up @@ -334,9 +334,11 @@ const DataSubmission = () => {

const [batches, setBatches] = useState<Batch[]>([]);
const [totalBatches, setTotalBatches] = useState<number>(0);
const [hasUploadingBatches, setHasUploadingBatches] = useState<boolean>(false);
const [prevBatchFetch, setPrevBatchFetch] = useState<FetchListing<Batch>>(null);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
const [batchRefreshTimeout, setBatchRefreshTimeout] = useState<NodeJS.Timeout>(null);
const [error, setError] = useState<string>(null);
const [loading, setLoading] = useState<boolean>(false);
const [openErrorDialog, setOpenErrorDialog] = useState<boolean>(false);
const [openFileListDialog, setOpenFileListDialog] = useState<boolean>(false);
const [selectedRow, setSelectedRow] = useState<Batch | null>(null);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 (
<StyledWrapper>
<StyledBanner bannerSrc={bannerSvg} />
Expand Down
8 changes: 8 additions & 0 deletions src/graphql/listBatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ export const query = gql`
...BatchFragment @skip(if: $partial)
}
}
fullStatusList: listBatches(submissionID: $submissionID, first: -1) {
batches {
status
}
}
}
${FullBatchFragment}
${BaseBatchFragment}
`;

export type Response = {
listBatches: ListBatches;
fullStatusList: {
batches: Pick<Batch, 'status'>[];
};
};
2 changes: 1 addition & 1 deletion src/types/Submissions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 6c749d5

Please sign in to comment.