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-496 Batch Table Error Count #241

Merged
merged 13 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/content/dataSubmissions/Contexts/BatchTableContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const BatchTableContext = React.createContext<{
handleOpenErrorDialog?:(data: Batch) => void;
}>({});

export default BatchTableContext;
4 changes: 2 additions & 2 deletions src/content/dataSubmissions/Contexts/QCResultsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import React from "react";

const QCResultsContext = React.createContext<{
handleOpenErrorDialog?:(data: QCResult) => void;
handleOpenErrorDialog?:(data: QCResult) => void;
}>({});

export default QCResultsContext;
71 changes: 68 additions & 3 deletions src/content/dataSubmissions/DataSubmission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Alert,
AlertColor,
Box,
Button,
Card,
CardActions,
CardActionsProps,
Expand Down Expand Up @@ -37,6 +38,8 @@ import { FormatDate } from "../../utils";
import DataSubmissionActions from "./DataSubmissionActions";
import QualityControl from "./QualityControl";
import { ReactComponent as CopyIconSvg } from "../../assets/icons/copy_icon_2.svg";
import ErrorDialog from "./ErrorDialog";
import BatchTableContext from "./Contexts/BatchTableContext";
import DataSubmissionStatistics from '../../components/DataSubmissions/ValidationStatistics';
import ValidationControls from '../../components/DataSubmissions/ValidationControls';
import { useAuthContext } from "../../components/Contexts/AuthContext";
Expand Down Expand Up @@ -203,6 +206,23 @@ const StyledCopyIDButton = styled(IconButton)(() => ({
}
}));

const StyledErrorDetailsButton = styled(Button)(() => ({
color: "#0D78C5",
fontFamily: "Inter",
fontSize: "16px",
fontStyle: "normal",
fontWeight: 600,
lineHeight: "19px",
textDecorationLine: "underline",
textTransform: "none",
padding: 0,
justifyContent: "flex-start",
"&:hover": {
background: "transparent",
textDecorationLine: "underline",
},
}));

const columns: Column<Batch>[] = [
{
label: "Upload Type",
Expand Down Expand Up @@ -233,7 +253,32 @@ const columns: Column<Batch>[] = [
minWidth: "240px"
}
},
/* TODO: Error Count removed for MVP2-M2. Will be re-added in the future */
{
label: "Errors",
renderValue: (data) => (
<BatchTableContext.Consumer>
{({ handleOpenErrorDialog }) => {
if (data?.errors?.length === 0) {
return null;
}

return (
<StyledErrorDetailsButton
onClick={() => handleOpenErrorDialog && handleOpenErrorDialog(data)}
variant="text"
disableRipple
disableTouchRipple
disableFocusRipple
>
{data.errors?.length > 0 ? `${data.errors.length} ${data.errors.length === 1 ? "Error" : "Errors"}` : ""}
</StyledErrorDetailsButton>
);
}}
</BatchTableContext.Consumer>
),
field: "errors",
Alejandro-Vega marked this conversation as resolved.
Show resolved Hide resolved
sortDisabled: true
},
];

const URLTabs = {
Expand All @@ -254,6 +299,8 @@ const DataSubmission = () => {
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
const [changesAlert, setChangesAlert] = useState<AlertState>(null);
const [openErrorDialog, setOpenErrorDialog] = useState<boolean>(false);
const [selectedRow, setSelectedRow] = useState<Batch | null>(null);
const tableRef = useRef<TableMethods>(null);
const isValidTab = tab && Object.values(URLTabs).includes(tab);
const disableSubmit = useMemo(
Expand Down Expand Up @@ -385,6 +432,15 @@ const DataSubmission = () => {
navigator.clipboard.writeText(submissionId);
};

const handleOpenErrorDialog = (data: Batch) => {
setOpenErrorDialog(true);
setSelectedRow(data);
};

const providerValue = useMemo(() => ({
handleOpenErrorDialog
}), [handleOpenErrorDialog]);

return (
<StyledWrapper>
<GenericAlert open={!!changesAlert} severity={changesAlert?.severity} key="data-submission-alert">
Expand Down Expand Up @@ -432,7 +488,7 @@ const DataSubmission = () => {

<StyledMainContentArea>
{tab === URLTabs.DATA_UPLOAD ? (
<>
<BatchTableContext.Provider value={providerValue}>
<DataSubmissionUpload
submitterID={dataSubmission?.submitterID}
readOnly={submissionLockedStatuses.includes(dataSubmission?.status)}
Expand All @@ -444,9 +500,10 @@ const DataSubmission = () => {
data={batchFiles || []}
total={totalBatchFiles || 0}
loading={loading}
defaultRowsPerPage={20}
onFetchData={handleFetchBatchFiles}
/>
</>
</BatchTableContext.Provider>
) : <QualityControl />}
</StyledMainContentArea>
</StyledCardContent>
Expand All @@ -459,6 +516,14 @@ const DataSubmission = () => {
</StyledCardActions>
</StyledCard>
</StyledBannerContentContainer>
<ErrorDialog
open={openErrorDialog}
onClose={() => setOpenErrorDialog(false)}
header="Data Submission"
title="Error Count"
errors={selectedRow?.errors}
uploadedDate={dataSubmission?.createdAt}
/>
</StyledWrapper>
);
};
Expand Down
10 changes: 6 additions & 4 deletions src/content/dataSubmissions/ErrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ const StyledErrorItem = styled(Typography)({

const StyledErrorDetails = styled(Stack)({
padding: "10px",
overflowY: "auto",
maxHeight: "290px"
});

type Props = {
header?: string;
title?: string;
closeText?: string;
errors: ErrorMessage[];
errors: string[];
uploadedDate: string;
onClose?: () => void;
} & Omit<DialogProps, "onClose">;
Expand Down Expand Up @@ -137,10 +139,10 @@ const ErrorDialog = ({
{`${errors?.length || 0} ${errors?.length === 1 ? "COUNT" : "COUNTS"} ON ${FormatDate(uploadedDate, "M/D/YYYY", "N/A")}:`}
</StyledSubtitle>
<Stack direction="column" spacing={2.75}>
{errors?.map((error: ErrorMessage, idx: number) => (
{errors?.map((error: string, idx: number) => (
// eslint-disable-next-line react/no-array-index-key
<StyledErrorItem key={`${idx}_${error.title}_${error.description}`}>
{`${idx + 1}. ${error.description}`}
<StyledErrorItem key={`${idx}_${error}`}>
{`${idx + 1}. ${error}`}
</StyledErrorItem>
))}
</Stack>
Expand Down
2 changes: 1 addition & 1 deletion src/content/dataSubmissions/QualityControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const QualityControl = () => {
onClose={() => setOpenErrorDialog(false)}
header="Data Submission"
title="Reasons"
errors={selectedRow?.description}
errors={selectedRow?.description?.map((error) => error.description)}
uploadedDate={selectedRow?.uploadedDate}
/>
</>
Expand Down