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: relocate the revisions segment to the outer ring
Adorian Doran55d2acab1758
diff --git a/apps/client/src/widgets/react/charts/DonutChart.tsx b/apps/client/src/widgets/react/charts/DonutChart.tsxindex 1006186dac..ed090f7716 100644--- a/apps/client/src/widgets/react/charts/DonutChart.tsx+++ b/apps/client/src/widgets/react/charts/DonutChart.tsx@@ -36,6 +36,12 @@ export interface DonutRing<T = unknown> {interface DonutChartProps<T> {rings: DonutRing<T>[];className?: string;+ /**+ * SVG paint servers (gradients, patterns) for segments whose class points `--donut-segment-color`+ * at one: a stroke can only reference them through `url(#id)`, so they must live in this chart's+ * own `<defs>`.+ */+ defs?: ComponentChildren;/** Rendered centered in the hole, above the rings. */children?: ComponentChildren;}@@ -56,7 +62,7 @@ const SEGMENT_GAP = 3;* the element: a dashed circle's extent is the whole ring, so an anchored tooltip would hover far* from the segment it describes.*/-export default function DonutChart<T>({ rings, className, children }: DonutChartProps<T>) {+export default function DonutChart<T>({ rings, className, defs, children }: DonutChartProps<T>) {const half = DONUT_VIEW_SIZE / 2;const { containerRef, containerProps, showTooltip, hideTooltip, tooltipNode } = useChartTooltip<HTMLDivElement>();@@ -65,6 +71,7 @@ export default function DonutChart<T>({ rings, className, children }: DonutChart// pointer handlers don't register correctly under the test DOM (see the render spec).<div ref={containerRef} className={clsx("donut-chart", className)} {...containerProps}><svg viewBox={`${-half} ${-half} ${DONUT_VIEW_SIZE} ${DONUT_VIEW_SIZE}`}>+ {defs && <defs>{defs}</defs>}{/* Rotated so every ring starts at 12 o'clock. */}<g transform="rotate(-90)">{rings.map((ring) => (diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsxindex 399d709029..1aa54a1f64 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx@@ -43,6 +43,7 @@ export default function Browse({ path, onPathChange }: BrowseProps) {thickness: CHILDREN_RING_THICKNESS,segments: usage ? buildChildrenSegments(usage, {getTitle,+ revisionsLabel: t("space_usage.revisions"),deletedNotesLabel: t("space_usage.deleted_notes", { count: usage.deletedNotes?.noteCount ?? 0 }),makeTooltip: segmentTooltip,makeOthersTooltip: (count, size) =>diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/donut_segments.spec.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/donut_segments.spec.tsindex aa088a4306..773c26a5c5 100644--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/donut_segments.spec.ts+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/donut_segments.spec.ts@@ -18,17 +18,17 @@ function usage(overrides: Partial<SpaceUsageNoteResponse> = {}): SpaceUsageNoteR};}-function child(noteId: string, subtreeSize: number) {- return { noteId, subtreeSize, subtreeRevisionsSize: 0, subtreeNoteCount: 1 };+function child(noteId: string, subtreeSize: number, subtreeRevisionsSize = 0) {+ return { noteId, subtreeSize, subtreeRevisionsSize, subtreeNoteCount: 1 };}const makeTooltip = (kind: UsageTooltipKind, title: string, size: number) => `${kind}:${title}/${size}`;const makeOthersTooltip = (count: number, size: number) => `${count} more/${size}`;describe("buildCompositionSegments", () => {- const options = { bodyLabel: "Body", revisionsLabel: "Revisions", makeTooltip, makeOthersTooltip };+ const options = { bodyLabel: "Body", makeTooltip, makeOthersTooltip };- it("orders body, attachments largest-first, then revisions, with case-prefixed tooltips", () => {+ it("orders body then attachments largest-first, leaving history to the children ring", () => {const segments = buildCompositionSegments(usage({noteId: "note",ownSize: 100,@@ -39,7 +39,8 @@ describe("buildCompositionSegments", () => {]}), options);- expect(segments.map((segment) => segment.id)).toEqual([ "body", "attachment/big", "attachment/small", "revisions" ]);+ // The note's own revisions are on the payload and deliberately unused here.+ expect(segments.map((segment) => segment.id)).toEqual([ "body", "attachment/big", "attachment/small" ]);expect(segments[0]).toMatchObject({value: 100,className: "space-usage-segment-body",@@ -47,7 +48,6 @@ describe("buildCompositionSegments", () => {data: { noteId: "note" }});expect(segments[1]).toMatchObject({ value: 50, tooltip: "attachment:Big image/50", data: { attachmentId: "big" } });- expect(segments[3]).toMatchObject({ value: 40, className: "space-usage-segment-revisions", tooltip: "plain:Revisions/40" });});it("consolidates segments below 2% of the ring into an inert counted bucket", () => {@@ -91,6 +91,7 @@ describe("buildCompositionSegments", () => {describe("buildChildrenSegments", () => {const options = {getTitle: (noteId: string) => `title of ${noteId}`,+ revisionsLabel: "Revisions",deletedNotesLabel: "Deleted notes",makeTooltip,makeOthersTooltip@@ -148,4 +149,30 @@ describe("buildChildrenSegments", () => {expect(buildChildrenSegments(usage(), options)).toEqual([]);expect(buildChildrenSegments(usage({ deletedNotes: { size: 0, noteCount: 0 } }), options)).toEqual([]);});++ it("carries the whole subtree's history in one segment, ahead of the deleted bucket", () => {+ const segments = buildChildrenSegments(usage({+ // Far below 0.5% of the ring, yet history must stay its own segment rather than fold in.+ revisionsSize: 7,+ children: [ child("big", 100000, 12), child("small", 50, 5) ],+ deletedNotes: { size: 25, noteCount: 3 }+ }), options);++ expect(segments.map((segment) => segment.id))+ .toEqual([ "child/big", "others", "revisions", "/deleted-notes" ]);+ // This note's own 7 plus both children's subtree totals — never the per-child figures drawn+ // separately, which would count a shared snapshot at each entity holding it.+ expect(segments[2]).toMatchObject({+ value: 24,+ className: "space-usage-segment-revisions",+ tooltip: "plain:Revisions/24"+ });+ expect(segments[2].hue).toBeUndefined();+ });++ it("omits the revisions segment when the subtree has no history at all", () => {+ const segments = buildChildrenSegments(usage({ children: [ child("a", 10) ] }), options);++ expect(segments.map((segment) => segment.id)).toEqual([ "child/a" ]);+ });});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 791d79129c..868fcfad96 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@@ -24,19 +24,21 @@ type MakeOthersTooltip = (count: number, size: number) => string;interface CompositionOptions {bodyLabel: string;- revisionsLabel: string;makeTooltip: MakeTooltip;makeOthersTooltip: MakeOthersTooltip;}/**- * The composition ring of a single note: its body, each attachment on its own, and the revisions- * total — in that order, attachments largest-first. Empty components are dropped, and segments too- * small to see consolidate into a trailing "Others".+ * The composition ring of a single note: its body and each attachment on its own, attachments+ * largest-first. Empty components are dropped, and segments too small to see consolidate into a+ * trailing "Others".+ *+ * History is deliberately absent: it belongs to the whole subtree rather than to this note alone,+ * so the children ring carries it for every note at once (see {@link buildChildrenSegments}).*/export function buildCompositionSegments(usage: SpaceUsageNoteResponse,- { bodyLabel, revisionsLabel, makeTooltip, makeOthersTooltip }: CompositionOptions+ { bodyLabel, makeTooltip, makeOthersTooltip }: CompositionOptions): DonutSegment<UsageSegmentData>[] {const segments: DonutSegment<UsageSegmentData>[] = [];@@ -64,20 +66,12 @@ export function buildCompositionSegments(});}- if (usage.revisionsSize > 0) {- segments.push({- id: "revisions",- value: usage.revisionsSize,- className: "space-usage-segment-revisions",- tooltip: makeTooltip("plain", revisionsLabel, usage.revisionsSize)- });- }-return consolidateSmallSegments(segments, MIN_COMPOSITION_SEGMENT_FRACTION, makeOthersTooltip);}interface ChildrenOptions {getTitle: (noteId: string) => string;+ revisionsLabel: string;deletedNotesLabel: string;makeTooltip: MakeTooltip;makeOthersTooltip: MakeOthersTooltip;@@ -85,12 +79,16 @@ interface ChildrenOptions {/*** The children ring: each child weighted by its whole subtree, largest first, tinted by its own- * "random" stable hue. Slivers consolidate into "Others"; on the root, the deleted-notes bucket- * closes the ring afterwards — deleted space is its own entry, never folded away.+ * "random" stable hue. Slivers consolidate into "Others"; the subtree's history then closes the+ * ring, and on the root the deleted-notes bucket follows it — neither is ever folded away.+ *+ * Child weights leave history out, so one revisions segment stands for all of it at once: this+ * note's own and every descendant's. Splitting it per child would mean drawing per-entity revision+ * figures, which count a snapshot's blob again at every entity sharing it.*/export function buildChildrenSegments(usage: SpaceUsageNoteResponse,- { getTitle, deletedNotesLabel, makeTooltip, makeOthersTooltip }: ChildrenOptions+ { getTitle, revisionsLabel, deletedNotesLabel, makeTooltip, makeOthersTooltip }: ChildrenOptions): DonutSegment<UsageSegmentData>[] {const children = [ ...usage.children ].filter((child) => child.subtreeSize > 0)@@ -104,6 +102,16 @@ export function buildChildrenSegments(}));const segments = consolidateSmallSegments(children, MIN_CHILD_SEGMENT_FRACTION, makeOthersTooltip);+ const revisionsSize = subtreeRevisionsSize(usage);++ if (revisionsSize > 0) {+ segments.push({+ id: "revisions",+ value: revisionsSize,+ className: "space-usage-segment-revisions",+ tooltip: makeTooltip("plain", revisionsLabel, revisionsSize)+ });+ }if (usage.deletedNotes && usage.deletedNotes.size > 0) {segments.push({@@ -118,6 +126,18 @@ export function buildChildrenSegments(return segments;}+/**+ * The whole subtree's history: this note's own revisions plus every descendant's, the children+ * already carrying their own subtrees' totals. Exported so the view can quote the same figure the+ * ring draws rather than reproducing the sum.+ */+export function subtreeRevisionsSize(usage: SpaceUsageNoteResponse) {+ return usage.children.reduce(+ (sum, child) => sum + child.subtreeRevisionsSize,+ usage.revisionsSize+ );+}+/** 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 39fc87190d..e603c29c8d 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@@ -5,6 +5,9 @@--space-usage-body-color: color-mix(in srgb, var(--accented-background-color) 70%, #5b8dd9 30%);--space-usage-attachments-color: color-mix(in srgb, var(--accented-background-color) 70%, #d9a93d 30%);--space-usage-revisions-color: color-mix(in srgb, var(--accented-background-color) 70%, #8f959c 30%);+ /* The hatch's stripes: the same gray carried further from the surface, so the texture reads at+ ring thickness without becoming a second color. */+ --space-usage-revisions-stripe-color: color-mix(in srgb, var(--accented-background-color) 40%, #8f959c 60%);.space-usage-segment-body {--donut-segment-color: var(--space-usage-body-color);@@ -14,8 +17,19 @@--donut-segment-color: var(--space-usage-attachments-color);}+ /* Stroked with the hatch rather than a flat fill: history is not content the user put there,+ and the texture says so without spending another color. */.space-usage-segment-revisions {- --donut-segment-color: var(--space-usage-revisions-color);+ --donut-segment-color: url(#space-usage-revisions-hatch);+ }++ .space-usage-hatch-base {+ fill: var(--space-usage-revisions-color);+ }++ .space-usage-hatch-stripe {+ stroke: var(--space-usage-revisions-stripe-color);+ stroke-width: 2;}/* Repeats .donut-segment to outrank the primitive's clickable-cursor rule. */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 9341f9253f..c526a61c39 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@@ -69,14 +69,28 @@ afterEach(() => {});describe("NoteUsageDonut", () => {- it("renders the composition ring with the semantic segment classes", () => {+ it("renders the composition ring with the semantic segment classes, history excluded", () => {const probe = renderDonut();expect(probe.querySelector("circle.space-usage-segment-body")).not.toBeNull();expect(probe.querySelector("circle.space-usage-segment-attachment")).not.toBeNull();- expect(probe.querySelector("circle.space-usage-segment-revisions")).not.toBeNull();// The sub-2% attachment consolidated into the counted bucket.expect(probe.querySelector("circle.space-usage-segment-others")).not.toBeNull();+ // Despite the note's own revisions being on the payload: history belongs to the whole+ // subtree, so the children ring carries it instead.+ expect(probe.querySelector("circle.space-usage-segment-revisions")).toBeNull();+ });++ it("defines the hatch the revisions segment is stroked with", () => {+ const probe = renderDonut();+ const pattern = probe.querySelector("svg > defs > pattern#space-usage-revisions-hatch");++ expect(pattern).not.toBeNull();+ expect(pattern?.querySelector(".space-usage-hatch-base")).not.toBeNull();+ expect(pattern?.querySelector(".space-usage-hatch-stripe")).not.toBeNull();+ // An HTML-namespaced pattern parses but paints nothing, so the stroke would silently+ // fall back to no color at all.+ expect(pattern?.namespaceURI).toBe("http://www.w3.org/2000/svg");});it("links the center title to the note and opens it in a new tab instead of navigating", () => {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 0798f24586..142bb21d06 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@@ -46,7 +46,6 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []thickness: COMPOSITION_RING_THICKNESS,segments: buildCompositionSegments(usage, {bodyLabel: t("space_usage.note_body"),- revisionsLabel: t("space_usage.revisions"),makeTooltip: segmentTooltip,makeOthersTooltip: (count, size) =>t("space_usage.others_attachments", { count, size: formatSize(size) })@@ -58,6 +57,7 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []<DonutChart<UsageSegmentData>rings={[ compositionRing, ...outerRings ]}className={clsx("note-usage-donut", className)}+ defs={<RevisionsHatch />}>{centerActions}<a@@ -86,6 +86,29 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []);}+/**+ * The hatch the revisions segment is stroked with — history reads as the same gray as everything+ * else that is not live content, textured so it is told apart from a note at a glance.+ *+ * A stroke can only reach a pattern through `url(#id)`, which forces a document-wide ID. Two donuts+ * on one page would therefore both resolve to the first — harmless here, since the pattern carries+ * no per-instance state and every copy is identical.+ */+function RevisionsHatch() {+ return (+ <pattern+ id="space-usage-revisions-hatch"+ width="6"+ height="6"+ patternUnits="userSpaceOnUse"+ patternTransform="rotate(45)"+ >+ <rect className="space-usage-hatch-base" width="6" height="6" />+ <line className="space-usage-hatch-stripe" x1="0" y1="0" x2="0" y2="6" />+ </pattern>+ );+}+/*** 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.