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/browse view: improve the central labels
Adorian Doranc06be7f38cd4
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 9190793928..4e6fa3b441 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2685,9 +2685,11 @@"attachment_tooltip": "Attachment: {{- title}} ({{size}})","child_tooltip": "Child note: {{- title}} ({{size}})","center_note_size": "Note: <Size/>",- "center_note_size_hint": "Space this note actually occupies: body, attachments and revisions, with duplicated content counted once",+ "center_note_size_hint": "This note's body and its attachments, matching the inner ring. It actually occupies {{size}} on disk with its revisions included, shared content counted once.",+ "center_revisions_size": "Revisions: <Size/>",+ "center_revisions_size_hint": "Every revision in this subtree, this note's and its descendants', matching the gray segment. A snapshot still sharing content with the live note is counted again here.","center_subtree_size": "Subtree: <Size/>",- "center_subtree_size_hint": "Space this note and all of its descendants actually occupy, revisions included, with duplicated content counted once",+ "center_subtree_size_hint": "This note and all of its descendants with their history left out, matching the rings together. The subtree actually occupies {{size}} on disk with revisions included, shared content counted once.","back": "Back","current_note": "Current note:","status_content_one": "1 note occupying {{size}} (of which {{attachmentsSize}} are note attachments)",diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/donut_segments.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/donut_segments.tsindex 868fcfad96..5367c2f9fb 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/donut_segments.ts+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/donut_segments.ts@@ -138,6 +138,19 @@ export function subtreeRevisionsSize(usage: SpaceUsageNoteResponse) {);}+/** What the composition ring sums to: the note's body and its attachments, history excluded. */+export function noteWeight(usage: SpaceUsageNoteResponse) {+ return usage.ownSize + usage.attachmentsSize;+}++/**+ * What the composition ring and the children ring's child segments sum to together — the subtree+ * without its history, which the ring keeps as a segment of its own.+ */+export function subtreeWeight(usage: SpaceUsageNoteResponse) {+ return usage.children.reduce((sum, child) => sum + child.subtreeSize, noteWeight(usage));+}+/** Replaces the segments below the given share of the ring's total with one inert "N more (size)". */function consolidateSmallSegments(segments: DonutSegment<UsageSegmentData>[],diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.css b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.cssindex e603c29c8d..fccaf52a9f 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.css+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.css@@ -38,7 +38,7 @@}/* Keeps the text inside the hole (inner ring inner edge ≈ 21% in from the box edge); nudged- upward so the button + three text lines sit visually centered rather than sagging low. */+ upward so the button + four text lines sit visually centered rather than sagging low. */.donut-chart-center {padding: 23%;gap: 2px;@@ -58,9 +58,19 @@text-decoration: underline;}+ /* The lines carry their own tight leading, so the block sets its own spacing: one gap above it,+ and the center's own gap no longer stretches the lines apart. */+ .note-usage-donut-sizes {+ display: flex;+ flex-direction: column;+ margin-top: 8px;+ gap: 2px;+ }+.note-usage-donut-size {opacity: 0.7;font-size: 0.85em;+ line-height: 1;}.note-usage-donut-size-value {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 c526a61c39..5c7e54b66d 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@@ -40,7 +40,8 @@ const USAGE: SpaceUsageNoteResponse = {// Below 2% of the ring: consolidates into the "others" segment.{ attachmentId: "tiny", title: "Tiny attachment", role: "file", size: 10 }],- children: []+ // One child, so the subtree figures are tellable apart from the note's own.+ children: [ { noteId: "c1", subtreeSize: 4000, subtreeRevisionsSize: 500, subtreeNoteCount: 2 } ]};let container: HTMLDivElement | undefined;@@ -110,12 +111,19 @@ describe("NoteUsageDonut", () => {});});- it("shows the deduplicated note and subtree sizes, with the actions above the title", () => {+ it("totals each ring in the hole, with the actions above the title", () => {const probe = renderDonut();const center = probe.querySelector<HTMLElement>(".donut-chart-center");const values = [ ...probe.querySelectorAll(".note-usage-donut-size-value") ].map((el) => el.textContent);- expect(values).toEqual([ formatSize(150), formatSize(700) ]);+ expect(values).toEqual([+ // Body + attachments, what the composition ring draws — not the deduplicated 150.+ formatSize(15010),+ // This note's revisions plus the child subtree's, what the gray segment draws.+ formatSize(3500),+ // Both rings together, history excluded — not the deduplicated 700.+ formatSize(19010)+ ]);expect(center?.firstElementChild?.classList.contains("extra-action")).toBe(true);});});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 142bb21d06..3edf174a4b 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@@ -12,7 +12,14 @@ import { formatSize } from "../../../../../services/utils";import DonutChart, { type DonutRing } from "../../../../react/charts/DonutChart";import { useStaticTooltip } from "../../../../react/hooks";import { openNoteInNewTab } from "./context_menu";-import { buildCompositionSegments, type UsageSegmentData, type UsageTooltipKind } from "./donut_segments";+import {+ buildCompositionSegments,+ noteWeight,+ subtreeRevisionsSize,+ subtreeWeight,+ type UsageSegmentData,+ type UsageTooltipKind+} from "./donut_segments";export const COMPOSITION_RING_RADIUS = 133;/** Half the children ring's: the note's own breakdown reads as the quieter, supporting ring. */@@ -72,16 +79,26 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []}}onContextMenu={onTitleContextMenu}>{title}</a>- <SizeLine- i18nKey="space_usage.center_note_size"- hintKey="space_usage.center_note_size_hint"- size={usage.noteContentSize}- />- <SizeLine- i18nKey="space_usage.center_subtree_size"- hintKey="space_usage.center_subtree_size_hint"- size={usage.subtreeContentSize}- />+ {/* Each line is the total of what surrounds it, so the hole reads as the rings' legend.+ The deduplicated on-disk figures are the hints' business — they answer a different+ question (what erasing would reclaim) and would not match any drawn area. */}+ <div className="note-usage-donut-sizes">+ <SizeLine+ i18nKey="space_usage.center_note_size"+ hint={t("space_usage.center_note_size_hint", { size: formatSize(usage.noteContentSize) })}+ size={noteWeight(usage)}+ />+ <SizeLine+ i18nKey="space_usage.center_revisions_size"+ hint={t("space_usage.center_revisions_size_hint")}+ size={subtreeRevisionsSize(usage)}+ />+ <SizeLine+ i18nKey="space_usage.center_subtree_size"+ hint={t("space_usage.center_subtree_size_hint", { size: formatSize(usage.subtreeContentSize) })}+ size={subtreeWeight(usage)}+ />+ </div></DonutChart>);}@@ -113,9 +130,9 @@ function RevisionsHatch() {* One labelled center line, the value emphasized, with the app's tooltip explaining what the figure* covers. `<Trans>` lets translations put the value wherever their wording needs it.*/-function SizeLine({ i18nKey, hintKey, size }: { i18nKey: string, hintKey: string, size: number }) {+function SizeLine({ i18nKey, hint, size }: { i18nKey: string, hint: string, size: number }) {const ref = useRef<HTMLSpanElement>(null);- useStaticTooltip(ref, useMemo(() => ({ title: t(hintKey), placement: "bottom" }), [ hintKey ]));+ useStaticTooltip(ref, useMemo(() => ({ title: hint, placement: "bottom" }), [ hint ]));return (<span ref={ref} className="note-usage-donut-size">