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
client/content manager/space usage: allow previewing attachments
Adorian Doran6e09cfe06455
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.tsindex 3b4955ef12..c584fc8b20 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts@@ -223,6 +223,17 @@ export function quickEditNote(notePath: string[]) {void appContext.triggerCommand("openInPopup", { noteIdOrPath: notePath.join("/") });}+/**+ * The same popup, showing one of the note's attachments instead of the note itself — what the+ * composition ring's attachment segments stand for.+ */+export function quickEditAttachment(notePath: string[], attachmentId: string) {+ void appContext.triggerCommand("openInPopup", {+ noteIdOrPath: notePath.join("/"),+ viewScope: { viewMode: "attachments", attachmentId }+ });+}+/** Opens the note in a new tab, leaving the settings page in place. */export function openNoteInNewTab(noteId: string) {void appContext.tabManager.openContextWithNote(noteId, {diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.spec.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.spec.tsxindex a48690d86b..c9932d083b 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.spec.tsx+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.spec.tsx@@ -133,6 +133,27 @@ describe("NoteUsageDonut", () => {expect(mocks.triggerCommand).toHaveBeenCalledWith("openInPopup", { noteIdOrPath: "root/n1" });});+ it("opens what each composition segment stands for in the quick-edit popup", () => {+ const probe = renderDonut();+ const click = (selector: string) => probe.querySelector(selector)+ ?.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));++ click("circle.space-usage-segment-attachment");+ expect(mocks.triggerCommand).toHaveBeenLastCalledWith("openInPopup", {+ noteIdOrPath: "root/n1",+ viewScope: { viewMode: "attachments", attachmentId: "a1" }+ });++ // The body stands for the note itself, so it opens what the center title does.+ click("circle.space-usage-segment-body");+ expect(mocks.triggerCommand).toHaveBeenLastCalledWith("openInPopup", { noteIdOrPath: "root/n1" });++ // The bucket stands for several attachments at once, so there is nothing to open.+ mocks.triggerCommand.mockClear();+ click("circle.space-usage-segment-others");+ expect(mocks.triggerCommand).not.toHaveBeenCalled();+ });+it("totals each ring in the hole, with the actions above the title", () => {const probe = renderDonut();const center = probe.querySelector<HTMLElement>(".donut-chart-center");diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.tsxindex 86c9ebccf8..723ab7e4d0 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.tsx+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.tsx@@ -11,7 +11,7 @@ import { t } from "../../../../../services/i18n";import { formatSize } from "../../../../../services/utils";import DonutChart, { type DonutRing } from "../../../../react/charts/DonutChart";import { useStaticTooltip } from "../../../../react/hooks";-import { quickEditNote } from "./context_menu";+import { quickEditAttachment, quickEditNote } from "./context_menu";import {buildCompositionSegments,noteWeight,@@ -63,8 +63,18 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []makeTooltip: segmentTooltip,makeOthersTooltip: (count, size) =>t("space_usage.others_attachments", { count, size: formatSize(size) })- })- }), [ usage ]);+ }),+ // Every segment here stands for something the popup can show: the body is the note itself,+ // each other segment one of its attachments. The consolidated "Others" bucket stands for+ // several at once, so it opens nothing.+ onSegmentClick: (segment) => {+ if (segment.data?.attachmentId) {+ quickEditAttachment(notePath, segment.data.attachmentId);+ } else if (segment.data?.noteId) {+ quickEditNote(notePath);+ }+ }+ }), [ usage, notePath ]);return (