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: include the attachments size in the treemap
Adorian Doran79d0515d5e29
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex cb2b91338d..34691d9996 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2680,6 +2680,7 @@"others_attachments_one": "{{count}} more attachment ({{size}})","others_attachments_other": "{{count}} more attachments ({{size}})","cell_size": "Size: {{size}}",+ "cell_size_with_attachments": "Size: {{size}} (of which {{attachmentsSize}} as attachments)","segment_tooltip": "{{- title}} ({{size}})","attachment_tooltip": "Attachment: {{- title}} ({{size}})","child_tooltip": "Child note: {{- title}} ({{size}})",diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsxindex 8aab3c0f70..285295f40d 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx@@ -43,7 +43,14 @@ export default function Overview({ overview, onShowDetails }: OverviewProps) {),includeRevisions: INCLUDE_REVISIONS,getIcon: (noteId) => icons.get(noteId),- makeSizeDetail: (size) => t("space_usage.cell_size", { size: formatSize(size) })+ // A cell's area covers the note's body and its attachments together; where attachments are+ // part of that, the line says how much, so a big cell is read for the right reason.+ makeSizeDetail: (size, attachmentsSize) => attachmentsSize > 0+ ? t("space_usage.cell_size_with_attachments", {+ size: formatSize(size),+ attachmentsSize: formatSize(attachmentsSize)+ })+ : t("space_usage.cell_size", { size: formatSize(size) })}), [ overview, icons ]);return (diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.tsindex 5910a8be36..0e50bc7372 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts@@ -26,7 +26,7 @@ function build(overview: SpaceUsageOverviewResponse, includeRevisions = false) {hiddenNotesLabel: "Hidden notes",deletedNotesLabel: "Deleted notes",includeRevisions,- makeSizeDetail: (size) => `size:${size}`+ makeSizeDetail: (size, attachmentsSize) => `size:${size}/att:${attachmentsSize}`});}@@ -54,14 +54,20 @@ describe("buildOverviewModel", () => {// The size rides along in the note preview tooltip rather than a second tooltip of its own.expect(leaf.attributes).toEqual({"data-href": "#root/folder/leaf",- "data-tooltip-detail": "size:120"+ "data-tooltip-detail": "size:120/att:20"});});- it("states the size its area encodes, and stays silent when no wording is given", () => {+ it("states the size its area encodes and how much of it is attachments, or stays silent", () => {const overview = response([ entry("a", [ "a" ], { ownSize: 5, revisionsSize: 7 }) ]);+ const detailOf = (model: TreemapItem<OverviewCell>) =>+ childById(model, "a").attributes?.["data-tooltip-detail"];- expect(childById(build(overview, true), "a").attributes?.["data-tooltip-detail"]).toBe("size:12");+ expect(detailOf(build(overview, true))).toBe("size:12/att:0");++ // The attachment share is the note's own figure, whatever the weight happens to cover.+ const withAttachments = response([ entry("a", [ "a" ], { ownSize: 5, attachmentsSize: 30 }) ]);+ expect(detailOf(build(withAttachments))).toBe("size:35/att:30");const silent = buildOverviewModel(overview, {otherNotesLabel: "Other notes",@@ -120,7 +126,7 @@ describe("buildOverviewModel", () => {expect(selfCell.data).toEqual({ noteId: "parent", notePath: [ "root", "parent" ] });expect(selfCell.attributes).toEqual({"data-href": "#root/parent",- "data-tooltip-detail": "size:50"+ "data-tooltip-detail": "size:50/att:0"});expect(childById(parent, "child").value).toBe(10);});diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.tsindex e7b916a53e..3149d026fc 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts@@ -24,9 +24,10 @@ interface OverviewModelOptions {getIcon?: (noteId: string) => string | undefined;/*** Wording for the size a note cell contributes to its hover tooltip, given the weight its area- * encodes. Omit to leave the cells silent about their size.+ * encodes and how much of that weight is attachments rather than the note's own body. Omit to+ * leave the cells silent about their size.*/- makeSizeDetail?: (size: number) => string;+ makeSizeDetail?: (size: number, attachmentsSize: number) => string;}/**@@ -89,7 +90,7 @@ export function buildOverviewModel("data-href": `#${cell.notePath?.join("/")}`,// The note preview tooltip shows this under the title, which is how a cell states its// size without any text of its own — and without a second tooltip competing with it.- ...(makeSizeDetail ? { "data-tooltip-detail": makeSizeDetail(weight) } : {})+ ...(makeSizeDetail ? { "data-tooltip-detail": makeSizeDetail(weight, entry.attachmentsSize) } : {})};const icon = getIcon?.(entry.noteId);