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-2138 Disable "Delete Node Data" button after submit #579

Merged
merged 1 commit into from
Jan 3, 2025
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
22 changes: 22 additions & 0 deletions src/components/DataSubmissions/DeleteNodeDataButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,26 @@ describe("Implementation Requirements", () => {
expect(queryByTestId("delete-node-data-button")).not.toBeInTheDocument();
}
);

it.each<SubmissionStatus>(["New", "In Progress", "Rejected", "Withdrawn"])(
"should (implicitly) be enabled for the Submission Status %s",
(status) => {
const { getByTestId } = render(<Button nodeType="test" selectedItems={["item-1"]} />, {
wrapper: (props) => <TestParent {...props} submission={{ status }} />,
});

expect(getByTestId("delete-node-data-button")).toBeEnabled();
}
);

it.each<SubmissionStatus>(["Submitted", "Released", "Completed", "Canceled", "Deleted"])(
"should be disabled for the Submission Status %s",
(status) => {
const { getByTestId } = render(<Button nodeType="test" selectedItems={["item-1"]} />, {
wrapper: (props) => <TestParent {...props} submission={{ status }} />,
});

expect(getByTestId("delete-node-data-button")).toBeDisabled();
}
);
});
14 changes: 13 additions & 1 deletion src/components/DataSubmissions/DeleteNodeDataButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ const StyledTooltip = styled(StyledFormTooltip)({
},
});

/**
* An array of submission statuses that should disable the delete button
*/
const DisabledStatuses: SubmissionStatus[] = [
"Submitted",
"Released",
"Completed",
"Canceled",
"Deleted",
];

type Props = {
/**
* The name of the node type currently selected
Expand All @@ -41,7 +52,7 @@ const DeleteNodeDataButton = ({ nodeType, selectedItems, disabled, onDelete, ...
const { enqueueSnackbar } = useSnackbar();
const { data } = useSubmissionContext();
const { user } = useAuthContext();
const { _id, deletingData } = data?.getSubmission || {};
const { _id, status, deletingData } = data?.getSubmission || {};

const collaborator = data?.getSubmission?.collaborators?.find(
(c) => c.collaboratorID === user?._id
Expand Down Expand Up @@ -146,6 +157,7 @@ const DeleteNodeDataButton = ({ nodeType, selectedItems, disabled, onDelete, ...
disabled ||
deletingData === true ||
selectedItems.length === 0 ||
DisabledStatuses.includes(status) ||
(collaborator && collaborator.permission !== "Can Edit")
}
aria-label="Delete nodes icon"
Expand Down
Loading