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
feat(attachments): pin the meeting transcript above its note
Elian Doranf458eb702688
diff --git a/apps/client/src/widgets/layout/NoteTitleActions.spec.tsx b/apps/client/src/widgets/layout/NoteTitleActions.spec.tsxindex 55a215c469..4c489280f2 100644--- a/apps/client/src/widgets/layout/NoteTitleActions.spec.tsx+++ b/apps/client/src/widgets/layout/NoteTitleActions.spec.tsx@@ -18,6 +18,7 @@ vi.mock("../NoteDetail", () => ({checkFullHeight: () => true}));vi.mock("./NoteTypeSwitcher", () => ({ default: () => null }));+vi.mock("./PinnedAttachments", () => ({ default: () => null }));describe("NoteTitleActions", () => {it("toggles the promoted attributes on their shortcut only for its own note context", async () => {diff --git a/apps/client/src/widgets/layout/NoteTitleActions.tsx b/apps/client/src/widgets/layout/NoteTitleActions.tsxindex 28221ffc2a..c8555bf625 100644--- a/apps/client/src/widgets/layout/NoteTitleActions.tsx+++ b/apps/client/src/widgets/layout/NoteTitleActions.tsx@@ -15,17 +15,20 @@ import { useNoteContext, useNoteLabel, useNoteProperty, useTriliumEvent, useTrilimport { NewNoteLink } from "../react/NoteLink";import SearchDefinition from "../search/SearchDefinition";import NoteTypeSwitcher from "./NoteTypeSwitcher";+import PinnedAttachments from "./PinnedAttachments";export default function NoteTitleActions() {const { note, ntxId, componentId, noteContext, viewScope } = useNoteContext();const noteType = useNoteProperty(note, "type");+ const isDefaultView = !viewScope?.viewMode || viewScope.viewMode === "default";return (<div className="title-actions"><PromotedAttributes note={note} componentId={componentId} noteContext={noteContext} />{noteType === "search" && <SearchProperties note={note} ntxId={ntxId} />}+ {isDefaultView && note && <PinnedAttachments note={note} />}<EditedNotes />- {(!viewScope?.viewMode || viewScope.viewMode === "default") && <NoteTypeSwitcher note={note} />}+ {isDefaultView && <NoteTypeSwitcher note={note} />}</div>);}diff --git a/apps/client/src/widgets/layout/PinnedAttachments.css b/apps/client/src/widgets/layout/PinnedAttachments.cssnew file mode 100644index 0000000000..760ec8d541--- /dev/null+++ b/apps/client/src/widgets/layout/PinnedAttachments.css@@ -0,0 +1,7 @@+.pinned-attachment {+ .transcript {+ height: auto;+ max-height: 40vh;+ padding-inline: 0;+ }+}diff --git a/apps/client/src/widgets/layout/PinnedAttachments.spec.tsx b/apps/client/src/widgets/layout/PinnedAttachments.spec.tsxnew file mode 100644index 0000000000..7cec96bd74--- /dev/null+++ b/apps/client/src/widgets/layout/PinnedAttachments.spec.tsx@@ -0,0 +1,50 @@+import { act } from "preact/test-utils";+import { describe, expect, it, vi } from "vitest";++import type FAttachment from "../../entities/fattachment";+import { buildNote } from "../../test/easy-froca";+import { renderInto } from "../../test/render";+import PinnedAttachments from "./PinnedAttachments";++vi.mock("../type_widgets/transcript/TranscriptView", () => ({+ default: ({ attachment }: { attachment: FAttachment }) =>+ <div className="transcript-stub">{attachment.attachmentId}</div>+}));++function attachment(attachmentId: string, role: string, title: string) {+ return { attachmentId, role, title } as FAttachment;+}++async function renderWith(attachments: FAttachment[]) {+ const note = buildNote({ title: "Meeting", type: "text" });+ vi.spyOn(note, "getAttachments").mockResolvedValue(attachments);+ let container: HTMLElement | undefined;+ await act(async () => {+ container = renderInto(<PinnedAttachments note={note} />);+ });+ if (!container) {+ throw new Error("nothing rendered");+ }+ return container;+}++describe("PinnedAttachments", () => {+ it("shows the attachments of a pinned role, expanded and titled, and no others", async () => {+ const container = await renderWith([+ attachment("image1", "image", "photo.png"),+ attachment("transcript1", "transcript", "Transcript")+ ]);++ const sections = container.querySelectorAll(".pinned-attachment");+ expect(sections).toHaveLength(1);+ const [ section ] = sections;+ expect(section.textContent).toContain("Transcript");+ expect(section.querySelector("[aria-expanded]")?.getAttribute("aria-expanded")).toBe("true");+ expect(section.querySelector(".transcript-stub")?.textContent).toBe("transcript1");+ });++ it("renders nothing for a note without one", async () => {+ const container = await renderWith([ attachment("image1", "image", "photo.png") ]);+ expect(container.querySelector(".pinned-attachment")).toBeNull();+ });+});diff --git a/apps/client/src/widgets/layout/PinnedAttachments.tsx b/apps/client/src/widgets/layout/PinnedAttachments.tsxnew file mode 100644index 0000000000..5d6af7d341--- /dev/null+++ b/apps/client/src/widgets/layout/PinnedAttachments.tsx@@ -0,0 +1,39 @@+import "./PinnedAttachments.css";++import type { ComponentType } from "preact";++import type FAttachment from "../../entities/fattachment";+import type FNote from "../../entities/fnote";+import Collapsible from "../react/Collapsible";+import { useAttachments } from "../react/hooks";+import TranscriptView from "../type_widgets/transcript/TranscriptView";++/** The attachment roles shown at the top of their note, each with the view that renders it. */+const PINNED_ROLE_VIEWS: Record<string, ComponentType<{ attachment: FAttachment }>> = {+ transcript: TranscriptView+};++/** Shows the note's attachments of a pinned role above its content, one section each. */+export default function PinnedAttachments({ note }: { note: FNote }) {+ const attachments = useAttachments(note);++ return (+ <>+ {attachments.map((attachment) => {+ const View = Object.hasOwn(PINNED_ROLE_VIEWS, attachment.role)+ ? PINNED_ROLE_VIEWS[attachment.role]+ : null;+ return View && (+ <Collapsible+ key={attachment.attachmentId}+ className="pinned-attachment"+ title={attachment.title}+ initiallyExpanded+ >+ <View attachment={attachment} />+ </Collapsible>+ );+ })}+ </>+ );+}