Skip to content

Commit

Permalink
CRDCDH-1772 Data View tooltip changes
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 committed Oct 10, 2024
1 parent 761eb53 commit 33d5296
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
30 changes: 28 additions & 2 deletions src/components/DataSubmissions/DeleteNodeDataButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,36 @@ describe("Implementation Requirements", () => {
userEvent.hover(getByTestId("delete-node-data-button"));

const tooltip = await findByRole("tooltip");
expect(tooltip).toBeInTheDocument();
expect(tooltip).toHaveTextContent("Delete all selected nodes from this data submission");
expect(tooltip).toBeInTheDocument(); // NOTE: We don't care about the tooltip content here, see below

userEvent.unhover(getByTestId("delete-node-data-button"));

await waitFor(() => {
expect(tooltip).not.toBeInTheDocument();
});
});

it.each<[nodeType: string, content: string]>([
["data file", "Delete all the selected data files from this data submission"],
["random metadata", "Delete all the selected records from this data submission"],
])(
"should customize the tooltip text for metadata vs data files",
async (nodeType, tooltipText) => {
const { getByTestId, findByRole } = render(
<Button nodeType={nodeType} selectedItems={["1 item ID"]} />,
{
wrapper: TestParent,
}
);

userEvent.hover(getByTestId("delete-node-data-button"));

const tooltip = await findByRole("tooltip");
expect(tooltip).toBeInTheDocument();
expect(tooltip).toHaveTextContent(tooltipText);
}
);

it("should have a tooltip when the delete button is disabled with an ongoing deletion", async () => {
const { getByTestId, findByRole } = render(<Button nodeType="test" selectedItems={[]} />, {
wrapper: (props) => <TestParent {...props} submission={{ deletingData: true }} />,
Expand Down
15 changes: 11 additions & 4 deletions src/components/DataSubmissions/DeleteNodeDataButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ const DeleteNodeDataButton = ({ nodeType, selectedItems, disabled, onDelete, ...
const { user } = useAuthContext();
const { _id, deletingData } = data?.getSubmission || {};

const tooltipText =
deletingData === true
? "Delete action unavailable while another delete operation is in progress"
: "Delete all selected nodes from this data submission";
const tooltipText = useMemo<string>(() => {
if (deletingData === true) {
return "Delete action unavailable while another delete operation is in progress";
}

if (nodeType?.toLowerCase() === "data file") {
return "Delete all the selected data files from this data submission";
}

return "Delete all the selected records from this data submission";
}, [deletingData, nodeType]);

const content = useMemo(() => {
const nodeTerm: string = selectedItems.length > 1 ? "nodes" : "node";
Expand Down

0 comments on commit 33d5296

Please sign in to comment.