Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager/space usage/browse: UI improvements

Adorian Doraneea0af932c79
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 674bcf01a0..1405818ff5 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2671,13 +2671,16 @@
"deleted_notes": "Deleted notes",
"note_body": "Note content",
"revisions": "Revisions",
- "others": "Others",
+ "others_notes_one": "{{count}} more note ({{size}})",
+ "others_notes_other": "{{count}} more notes ({{size}})",
+ "others_attachments_one": "{{count}} more attachment ({{size}})",
+ "others_attachments_other": "{{count}} more attachments ({{size}})",
"segment_tooltip": "{{- title}} ({{size}})",
"attachment_tooltip": "Attachment: {{- title}} ({{size}})",
"child_tooltip": "Child note: {{- title}} ({{size}})",
- "center_note_size": "Note: {{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_subtree_size": "Subtree: {{size}}",
+ "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",
"back": "Back",
"status_content": "Database content: {{size}}",
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.css b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.css
index 50cdf7d75c..0148846bcd 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.css
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.css
@@ -52,6 +52,12 @@
padding-block: 8px;
}
+ /* At the root there is nowhere to go back to: the arrow disappears but keeps its box, so the
+ center text doesn't jump between levels. */
+ .space-usage-back.disabled {
+ visibility: hidden;
+ }
+
/* Not a note: nothing to navigate into, painted like the revisions it will one day free.
Repeats .donut-segment to outrank the primitive's clickable-cursor rule. */
.donut-segment.space-usage-segment-deleted {
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.tsx
index 4bd136f033..70c99e9035 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
@@ -6,6 +6,7 @@ import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
import froca from "../../../../../services/froca";
import { t } from "../../../../../services/i18n";
+import { formatSize } from "../../../../../services/utils";
import ActionButton from "../../../../react/ActionButton";
import type { DonutRing } from "../../../../react/charts/DonutChart";
import { buildChildrenSegments, type UsageSegmentData } from "./donut_segments";
@@ -34,8 +35,9 @@ export default function Browse() {
segments: usage ? buildChildrenSegments(usage, {
getTitle,
deletedNotesLabel: t("space_usage.deleted_notes"),
- othersLabel: t("space_usage.others"),
- makeTooltip: segmentTooltip
+ makeTooltip: segmentTooltip,
+ makeOthersTooltip: (count, size) =>
+ t("space_usage.others_notes", { count, size: formatSize(size) })
}) : [],
onSegmentClick: (segment) => {
const childId = segment.data?.noteId;
@@ -49,12 +51,6 @@ export default function Browse() {
return (
<div className="space-usage-browse">
<nav className="space-usage-breadcrumb">
- <ActionButton
- icon="bx bx-arrow-back"
- text={t("space_usage.back")}
- disabled={stack.length === 1}
- onClick={() => setStack((current) => current.length > 1 ? current.slice(0, -1) : current)}
- />
{stack.map((id, index) => (
<Fragment key={`${index}/${id}`}>
{index > 0 && <span className="space-usage-crumb-separator" aria-hidden="true">›</span>}
@@ -78,6 +74,15 @@ export default function Browse() {
title={getTitle(usage.noteId)}
notePath={stack}
outerRings={[ childrenRing ]}
+ centerActions={
+ <ActionButton
+ className="space-usage-back"
+ icon="bx bx-arrow-back"
+ text={t("space_usage.back")}
+ disabled={stack.length === 1}
+ onClick={() => setStack((current) => current.length > 1 ? current.slice(0, -1) : current)}
+ />
+ }
/>
</div>
) : (
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.ts
index 3e2bb464dd..b980c79565 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
@@ -23,9 +23,10 @@ function child(noteId: string, subtreeSize: number) {
}
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", othersLabel: "Others", makeTooltip };
+ const options = { bodyLabel: "Body", revisionsLabel: "Revisions", makeTooltip, makeOthersTooltip };
it("orders body, attachments largest-first, then revisions, with case-prefixed tooltips", () => {
const segments = buildCompositionSegments(usage({
@@ -49,7 +50,7 @@ describe("buildCompositionSegments", () => {
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 Others", () => {
+ it("consolidates segments below 2% of the ring into an inert counted bucket", () => {
const segments = buildCompositionSegments(usage({
ownSize: 1000,
attachments: [
@@ -62,7 +63,7 @@ describe("buildCompositionSegments", () => {
expect(segments[1]).toMatchObject({
value: 15,
className: "space-usage-segment-others",
- tooltip: "plain:Others/15",
+ tooltip: "2 more/15",
data: {}
});
});
@@ -80,8 +81,8 @@ describe("buildChildrenSegments", () => {
const options = {
getTitle: (noteId: string) => `title of ${noteId}`,
deletedNotesLabel: "Deleted notes",
- othersLabel: "Others",
- makeTooltip
+ makeTooltip,
+ makeOthersTooltip
};
it("weights children by subtree, largest first, each with its own stable hue", () => {
@@ -98,13 +99,13 @@ describe("buildChildrenSegments", () => {
});
});
- it("consolidates children below 0.5% of the ring into an inert Others", () => {
+ it("consolidates children below 0.5% of the ring into an inert counted bucket", () => {
const segments = buildChildrenSegments(usage({
children: [ child("big", 10000), child("tiny1", 30), child("tiny2", 10) ]
}), options);
expect(segments.map((segment) => segment.id)).toEqual([ "child/big", "others" ]);
- expect(segments[1]).toMatchObject({ value: 40, tooltip: "plain:Others/40", data: {} });
+ expect(segments[1]).toMatchObject({ value: 40, tooltip: "2 more/40", data: {} });
expect(segments[1].hue).toBeUndefined();
});
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.ts
index 8448ef8214..791d79129c 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
@@ -20,11 +20,13 @@ export const MIN_COMPOSITION_SEGMENT_FRACTION = 0.02;
/** Child segments smaller than this share of the ring consolidate into "Others". */
export const MIN_CHILD_SEGMENT_FRACTION = 0.005;
+type MakeOthersTooltip = (count: number, size: number) => string;
+
interface CompositionOptions {
bodyLabel: string;
revisionsLabel: string;
- othersLabel: string;
makeTooltip: MakeTooltip;
+ makeOthersTooltip: MakeOthersTooltip;
}
/**
@@ -34,7 +36,7 @@ interface CompositionOptions {
*/
export function buildCompositionSegments(
usage: SpaceUsageNoteResponse,
- { bodyLabel, revisionsLabel, othersLabel, makeTooltip }: CompositionOptions
+ { bodyLabel, revisionsLabel, makeTooltip, makeOthersTooltip }: CompositionOptions
): DonutSegment<UsageSegmentData>[] {
const segments: DonutSegment<UsageSegmentData>[] = [];
@@ -71,14 +73,14 @@ export function buildCompositionSegments(
});
}
- return consolidateSmallSegments(segments, MIN_COMPOSITION_SEGMENT_FRACTION, othersLabel, makeTooltip);
+ return consolidateSmallSegments(segments, MIN_COMPOSITION_SEGMENT_FRACTION, makeOthersTooltip);
}
interface ChildrenOptions {
getTitle: (noteId: string) => string;
deletedNotesLabel: string;
- othersLabel: string;
makeTooltip: MakeTooltip;
+ makeOthersTooltip: MakeOthersTooltip;
}
/**
@@ -88,7 +90,7 @@ interface ChildrenOptions {
*/
export function buildChildrenSegments(
usage: SpaceUsageNoteResponse,
- { getTitle, deletedNotesLabel, othersLabel, makeTooltip }: ChildrenOptions
+ { getTitle, deletedNotesLabel, makeTooltip, makeOthersTooltip }: ChildrenOptions
): DonutSegment<UsageSegmentData>[] {
const children = [ ...usage.children ]
.filter((child) => child.subtreeSize > 0)
@@ -101,7 +103,7 @@ export function buildChildrenSegments(
data: { noteId: child.noteId }
}));
- const segments = consolidateSmallSegments(children, MIN_CHILD_SEGMENT_FRACTION, othersLabel, makeTooltip);
+ const segments = consolidateSmallSegments(children, MIN_CHILD_SEGMENT_FRACTION, makeOthersTooltip);
if (usage.deletedNotes && usage.deletedNotes.size > 0) {
segments.push({
@@ -116,12 +118,11 @@ export function buildChildrenSegments(
return segments;
}
-/** Replaces the segments below the given share of the ring's total with one inert "Others". */
+/** Replaces the segments below the given share of the ring's total with one inert "N more (size)". */
function consolidateSmallSegments(
segments: DonutSegment<UsageSegmentData>[],
minFraction: number,
- othersLabel: string,
- makeTooltip: MakeTooltip
+ makeOthersTooltip: MakeOthersTooltip
): DonutSegment<UsageSegmentData>[] {
const total = segments.reduce((sum, segment) => sum + segment.value, 0);
@@ -131,12 +132,14 @@ function consolidateSmallSegments(
const kept: DonutSegment<UsageSegmentData>[] = [];
let othersSize = 0;
+ let othersCount = 0;
for (const segment of segments) {
if (segment.value / total >= minFraction) {
kept.push(segment);
} else {
othersSize += segment.value;
+ othersCount++;
}
}
@@ -145,7 +148,7 @@ function consolidateSmallSegments(
id: "others",
value: othersSize,
className: "space-usage-segment-others",
- tooltip: makeTooltip("plain", othersLabel, othersSize),
+ tooltip: makeOthersTooltip(othersCount, othersSize),
data: {}
});
}
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.css
index a44dc4e199..39fc87190d 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
@@ -23,23 +23,33 @@
cursor: default;
}
- /* Keeps the text inside the hole (inner ring inner edge ≈ 21% in from the box edge). */
+ /* 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. */
.donut-chart-center {
padding: 23%;
gap: 2px;
+ transform: translateY(-4%);
}
.note-usage-donut-title {
overflow: hidden;
max-width: 100%;
- color: var(--main-text-color);
+ color: var(--link-color);
font-size: 1.05rem;
white-space: nowrap;
text-overflow: ellipsis;
}
+ .note-usage-donut-title:hover {
+ text-decoration: underline;
+ }
+
.note-usage-donut-size {
opacity: 0.7;
- font-size: 0.85rem;
+ font-size: 0.85em;
+ }
+
+ .note-usage-donut-size-value {
+ font-weight: 600;
}
}
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.tsx
index 9d9d4315c1..bb824fbbbe 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
@@ -2,7 +2,10 @@ import "./note_usage_donut.css";
import type { SpaceUsageNoteResponse } from "@triliumnext/commons";
import clsx from "clsx";
+import type { ComponentChildren } from "preact";
import { useMemo } from "preact/hooks";
+import type React from "react";
+import { Trans } from "react-i18next";
import appContext from "../../../../../components/app_context";
import { t } from "../../../../../services/i18n";
@@ -22,6 +25,8 @@ interface NoteUsageDonutProps {
notePath: string[];
/** Extra rings drawn around the composition ring, e.g. Browse's children ring. */
outerRings?: DonutRing<UsageSegmentData>[];
+ /** Rendered centered above the title in the hole — e.g. Browse's back button. */
+ centerActions?: ComponentChildren;
className?: string;
}
@@ -31,7 +36,7 @@ interface NoteUsageDonutProps {
* link: it opens the note and carries the note preview tooltip. Reusable wherever one note's usage
* needs breaking down; Browse wraps it with its children ring via {@link outerRings}.
*/
-export default function NoteUsageDonut({ usage, title, notePath, outerRings = [], className }: NoteUsageDonutProps) {
+export default function NoteUsageDonut({ usage, title, notePath, outerRings = [], centerActions, className }: NoteUsageDonutProps) {
const compositionRing: DonutRing<UsageSegmentData> = useMemo(() => ({
id: "composition",
radius: COMPOSITION_RING_RADIUS,
@@ -39,8 +44,9 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []
segments: buildCompositionSegments(usage, {
bodyLabel: t("space_usage.note_body"),
revisionsLabel: t("space_usage.revisions"),
- othersLabel: t("space_usage.others"),
- makeTooltip: segmentTooltip
+ makeTooltip: segmentTooltip,
+ makeOthersTooltip: (count, size) =>
+ t("space_usage.others_attachments", { count, size: formatSize(size) })
})
}), [ usage ]);
@@ -50,6 +56,7 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []
rings={[ compositionRing, ...outerRings ]}
className={clsx("note-usage-donut", className)}
>
+ {centerActions}
<a
className="note-usage-donut-title"
href={`#${notePath.join("/")}`}
@@ -65,15 +72,27 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []
}}
>{title}</a>
<span className="note-usage-donut-size" title={t("space_usage.center_note_size_hint")}>
- {t("space_usage.center_note_size", { size: formatSize(usage.noteContentSize) })}
+ <SizeLine i18nKey="space_usage.center_note_size" size={usage.noteContentSize} />
</span>
<span className="note-usage-donut-size" title={t("space_usage.center_subtree_size_hint")}>
- {t("space_usage.center_subtree_size", { size: formatSize(usage.subtreeContentSize) })}
+ <SizeLine i18nKey="space_usage.center_subtree_size" size={usage.subtreeContentSize} />
</span>
</DonutChart>
);
}
+/** One labelled center line, the value emphasized; `<Trans>` lets translations reorder the parts. */
+function SizeLine({ i18nKey, size }: { i18nKey: string, size: number }) {
+ return (
+ <Trans
+ i18nKey={i18nKey}
+ components={{
+ Size: <span className="note-usage-donut-size-value">{formatSize(size)}</span> as React.ReactElement
+ }}
+ />
+ );
+}
+
/** "Title (1.2 MiB)", prefixed with its case ("Attachment: ", "Child note: ") where one applies. */
export function segmentTooltip(kind: UsageTooltipKind, title: string, size: number) {
const key = kind === "attachment" ? "space_usage.attachment_tooltip"