Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRDCDH-754 Poll for Batch Status Updates #269

Merged
merged 8 commits into from
Jan 30, 2024
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
Loading