Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): hide the copy image reference button where it cannot copy
Elian Dorana2d0e477b46d
diff --git a/apps/client/src/widgets/layout/NoteActionsCustom.spec.tsx b/apps/client/src/widgets/layout/NoteActionsCustom.spec.tsxnew file mode 100644index 0000000000..f03db21299--- /dev/null+++ b/apps/client/src/widgets/layout/NoteActionsCustom.spec.tsx@@ -0,0 +1,30 @@+import { describe, expect, it } from "vitest";++import Component from "../../components/component";+import NoteContext from "../../components/note_context";+import { ViewScope } from "../../services/link";+import { buildNote } from "../../test/easy-froca";+import { renderInto } from "../../test/render";+import { ParentComponent } from "../react/react_utils";+import NoteActionsCustom from "./NoteActionsCustom";++describe("NoteActionsCustom", () => {+ it("offers to copy an image reference only for content it can show, in the note's own view", () => {+ expect(renderCopyButton({})).not.toBeNull();+ expect(renderCopyButton({ isProtected: true })).toBeNull();+ expect(renderCopyButton({}, { viewMode: "attachments" })).toBeNull();+ });++ function renderCopyButton({ isProtected = false }: { isProtected?: boolean }, viewScope: ViewScope = { viewMode: "default" }) {+ const note = buildNote({ title: "Diagram", type: "mermaid" });+ note.isProtected = isProtected;+ const noteContext = { viewScope } as NoteContext;++ const container = renderInto(+ <ParentComponent.Provider value={new Component()}>+ <NoteActionsCustom note={note} ntxId="ntx" noteContext={noteContext} />+ </ParentComponent.Provider>+ );+ return container.querySelector("button.bx-copy");+ }+});diff --git a/apps/client/src/widgets/layout/NoteActionsCustom.tsx b/apps/client/src/widgets/layout/NoteActionsCustom.tsxindex 03093b0500..cccfdcd386 100644--- a/apps/client/src/widgets/layout/NoteActionsCustom.tsx+++ b/apps/client/src/widgets/layout/NoteActionsCustom.tsx@@ -204,9 +204,10 @@ function DownloadFileButton({ note, parentComponent, ntxId }: NoteActionsCustomI}//#region Floating buttons-function CopyReferenceToClipboardButton({ note, noteType }: NoteActionsCustomInnerProps) {+function CopyReferenceToClipboardButton({ note, noteType, isDefaultViewMode }: NoteActionsCustomInnerProps) {const hiddenImageCopyRef = useRef<HTMLDivElement>(null);- const isEnabled = ["mermaid", "canvas", "mindMap", "image"].includes(noteType);+ const isEnabled = ["mermaid", "canvas", "mindMap", "image"].includes(noteType)+ && note.isContentAvailable() && isDefaultViewMode;return isEnabled && (<>