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

[GLT-3976] added copy buttons for donor names and external names #153

Merged
merged 3 commits into from
Sep 12, 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
1 change: 1 addition & 0 deletions changes/add_copyName-donor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copy button next to Donor name and External Donor name to copy the name to clipboard
21 changes: 13 additions & 8 deletions ts/data/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "./requisition";
import { Tooltip } from "../component/tooltip";
import { caseFilters, latestActivitySort } from "../component/table-components";
import { makeCopyButton } from "../util/html-utils";

const dayMillis = 1000 * 60 * 60 * 24;

Expand Down Expand Up @@ -130,16 +131,20 @@ export const caseDefinition: TableDefinition<Case, Test> = {
title: "Donor",
sortType: "text",
addParentContents(kase, fragment) {
fragment.appendChild(
makeNameDiv(
kase.donor.name,
urls.miso.sample(kase.donor.id),
urls.dimsum.donor(kase.donor.name)
)
const nameDiv = makeNameDiv(
kase.donor.name,
urls.miso.sample(kase.donor.id),
urls.dimsum.donor(kase.donor.name),
kase.donor.name
);
fragment.appendChild(
makeTextDivWithTooltip(kase.donor.externalName, "External Name")
fragment.appendChild(nameDiv);

const externalNameDiv = makeTextDivWithTooltip(
kase.donor.externalName,
"External Name",
true
);
fragment.appendChild(externalNameDiv);

const tumourDetailDiv = document.createElement("div");
tumourDetailDiv.appendChild(
Expand Down
23 changes: 20 additions & 3 deletions ts/util/html-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,30 @@ export function makeCopyButton(text: string): HTMLButtonElement {
return button;
}

export function makeTextDivWithTooltip(text: string, tooltip: string) {
export function makeTextDivWithTooltip(
text: string,
tooltip: string,
addCopyButton = false
) {
const div = document.createElement("div");
div.appendChild(document.createTextNode(text));
div.className = "flex flex-row space-x-1 items-center";
const textSpan = document.createElement("span");
textSpan.appendChild(document.createTextNode(text));

if (addCopyButton) {
const copyButton = makeCopyButton(text);
copyButton.classList.add("text-12");
div.appendChild(textSpan);
div.appendChild(copyButton);
} else {
div.appendChild(textSpan);
}

const tooltipInstance = Tooltip.getInstance();
const addContents = (fragment: DocumentFragment) =>
fragment.appendChild(document.createTextNode(tooltip));
tooltipInstance.addTarget(div, addContents);
tooltipInstance.addTarget(textSpan, addContents);

return div;
}

Expand Down