Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager/space usage: improve tooltips

Adorian Dorand6646aafb38b
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 04562b9dd1..9e32745c47 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2681,15 +2681,17 @@
"others_attachments_other": "{{count}} more attachments ({{size}})",
"cell_size": "Size: {{size}}",
"cell_size_with_attachments": "Size: {{size}} (of which {{attachmentsSize}} as attachments)",
+ "revisions_subtree": "Revisions (including subtree revisions)",
"segment_tooltip": "{{- title}} ({{size}})",
+ "revisions_tooltip": "{{- title}}: {{size}}",
"attachment_tooltip": "Attachment: {{- title}} ({{size}})",
"child_tooltip": "Child note: {{- title}} ({{size}})",
"center_note_size": "Note: <Size/>",
- "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_note_size_help": "The note size covers only its own body and attachments ({{size}} on disk)",
"center_revisions_size": "Revisions: <Size/>",
- "center_revisions_size_hint": "Space erasing this subtree's history would reclaim, matching the gray segment; snapshots still sharing content with a live note free nothing and count for nothing here",
+ "center_revisions_help": "The revisions size for this note includes descendant notes as well",
"center_subtree_size": "Subtree: <Size/>",
- "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.",
+ "center_subtree_size_help": "The subtree size includes descendant notes, but not their revisions ({{size}} on disk)",
"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/browse.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx
index 1aa54a1f64..3e27c5ac85 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,7 +43,7 @@ export default function Browse({ path, onPathChange }: BrowseProps) {
thickness: CHILDREN_RING_THICKNESS,
segments: usage ? buildChildrenSegments(usage, {
getTitle,
- revisionsLabel: t("space_usage.revisions"),
+ revisionsLabel: t("space_usage.revisions_subtree"),
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.ts
index b68e72ec8c..7b18165e0d 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
@@ -164,10 +164,11 @@ describe("buildChildrenSegments", () => {
expect(segments.map((segment) => segment.id))
.toEqual([ "child/big", "others", "revisions", "/deleted-notes" ]);
+ // Its own tooltip kind: the label already carries parentheses, so the size follows a colon.
expect(segments[2]).toMatchObject({
value: 24,
className: "space-usage-segment-revisions",
- tooltip: "plain:Revisions/24"
+ tooltip: "revisions:Revisions/24"
});
expect(segments[2].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 9792a8bf2a..b3cba33ab3 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
@@ -9,8 +9,12 @@ export interface UsageSegmentData {
attachmentId?: string;
}
-/** Which wording a segment's tooltip gets: a plain label, or one prefixed with its case. */
-export type UsageTooltipKind = "plain" | "attachment" | "child";
+/**
+ * Which wording a segment's tooltip gets: a plain label, one prefixed with its case, or the
+ * revisions one — whose label carries parentheses of its own, so its size cannot follow in another
+ * pair.
+ */
+export type UsageTooltipKind = "plain" | "attachment" | "child" | "revisions";
type MakeTooltip = (kind: UsageTooltipKind, title: string, size: number) => string;
@@ -109,7 +113,7 @@ export function buildChildrenSegments(
id: "revisions",
value: revisionsSize,
className: "space-usage-segment-revisions",
- tooltip: makeTooltip("plain", revisionsLabel, revisionsSize)
+ tooltip: makeTooltip("revisions", revisionsLabel, revisionsSize)
});
}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
index c826d1fb9b..4565974fff 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
@@ -84,7 +84,12 @@ export default function SpaceUsage({ sectionSwitcher }: ContentManagerSectionPro
*/
function StatusEntry({ text, hint }: { text: string, hint: string }) {
const ref = useRef<HTMLSpanElement>(null);
- useStaticTooltip(ref, useMemo(() => ({ title: hint, placement: "top" }), [ hint ]));
+ // `tooltip-top` raises the popup above the settings dialog: Bootstrap appends tooltips to
+ // `<body>`, where the base `.tooltip` z-index sits below a modal.
+ useStaticTooltip(ref, useMemo(
+ () => ({ title: hint, placement: "top", customClass: "tooltip-top" }),
+ [ hint ]
+ ));
return <span ref={ref}>{text}</span>;
}
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 fccaf52a9f..6b41dd17a1 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
@@ -76,4 +76,17 @@
.note-usage-donut-size-value {
font-weight: 600;
}
+
+ /* The same affordance the option lists carry: small, dimmed, and asking to be hovered. */
+ .contextual-help {
+ margin-inline-start: 0.25em;
+ color: var(--contextual-help-icon-color);
+ font-size: 0.75rem;
+ opacity: 0.75;
+ cursor: help;
+ }
+
+ .contextual-help:hover {
+ opacity: 1;
+ }
}
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.tsx
index 6d77fc027c..990acfd566 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
@@ -18,6 +18,12 @@ vi.mock("../../../../../components/app_context", () => ({
}
}));
+// Uninitialized, the real `t` answers undefined for every key — which would silently drop anything
+// the component only renders when its wording resolves, the contextual-help icon included.
+vi.mock("../../../../../services/i18n", () => ({
+ t: (key: string) => key
+}));
+
// The real i18n is not initialized under test, so `Trans` would render the bare key and drop the
// interpolated value; the stub renders exactly what the component wires in.
vi.mock("react-i18next", () => ({
@@ -83,6 +89,23 @@ describe("NoteUsageDonut", () => {
expect(probe.querySelector("circle.space-usage-segment-revisions")).toBeNull();
});
+ it("gives every centre line a contextual-help affordance and no tooltip of its own", () => {
+ const probe = renderDonut();
+ const lines = [ ...probe.querySelectorAll(".note-usage-donut-size") ];
+
+ // Note, Revisions, Subtree — each says what it covers through its own icon.
+ expect(lines).toHaveLength(3);
+ for (const line of lines) {
+ const icon = line.querySelector(".contextual-help");
+ expect(icon?.classList.contains("bx-info-circle")).toBe(true);
+ // The app's tooltip, never the browser's: a native title would style and place itself
+ // apart from every other hint in the hole.
+ expect(icon?.getAttribute("title")).toBeNull();
+ // The hint hangs off the icon alone; hovering the value itself explains nothing.
+ expect(line.getAttribute("title")).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");
@@ -138,5 +161,10 @@ describe("segmentTooltip", () => {
.toBe(t("space_usage.attachment_tooltip", { title: "img.png", size: formatSize(20) }));
expect(segmentTooltip("child", "Projects", 30))
.toBe(t("space_usage.child_tooltip", { title: "Projects", size: formatSize(30) }));
+ expect(segmentTooltip("revisions", "Revisions (including subtree revisions)", 40))
+ .toBe(t("space_usage.revisions_tooltip", {
+ title: "Revisions (including subtree revisions)",
+ size: formatSize(40)
+ }));
});
});
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 d461808ce2..74ea94c1a9 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
@@ -20,6 +20,13 @@ import {
type UsageTooltipKind
} from "./donut_segments";
+/**
+ * The app's "raise above everything" tooltip class. Bootstrap appends tooltips to `<body>`, where
+ * the base `.tooltip` z-index sits below a modal — and this section is usually shown inside the
+ * settings dialog, so without it every hint here opens behind the dialog that triggered it.
+ */
+const RAISED_TOOLTIP = "tooltip-top";
+
export const COMPOSITION_RING_RADIUS = 133;
/** Half the children ring's: the note's own breakdown reads as the quieter, supporting ring. */
export const COMPOSITION_RING_THICKNESS = 23;
@@ -78,23 +85,25 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []
}}
onContextMenu={onTitleContextMenu}
>{title}</a>
- {/* 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. */}
+ {/* Each line is the total of what surrounds it, so the hole reads as the rings' legend,
+ and each carries an icon saying which part of the chart it adds up. */}
<div className="note-usage-donut-sizes">
+ {/* The bracketed figure is the deduplicated one: what the note or subtree really
+ costs on disk, which the drawn per-entity totals overstate wherever content is
+ shared. Revisions need no such aside — their line already draws that figure. */}
<SizeLine
i18nKey="space_usage.center_note_size"
- hint={t("space_usage.center_note_size_hint", { size: formatSize(usage.noteContentSize) })}
+ help={t("space_usage.center_note_size_help", { size: formatSize(usage.noteContentSize) })}
size={noteWeight(usage)}
/>
<SizeLine
i18nKey="space_usage.center_revisions_size"
- hint={t("space_usage.center_revisions_size_hint")}
+ help={t("space_usage.center_revisions_help")}
size={usage.subtreeRevisionsContentSize}
/>
<SizeLine
i18nKey="space_usage.center_subtree_size"
- hint={t("space_usage.center_subtree_size_hint", { size: formatSize(usage.subtreeContentSize) })}
+ help={t("space_usage.center_subtree_size_help", { size: formatSize(usage.subtreeContentSize) })}
size={subtreeWeight(usage)}
/>
</div>
@@ -129,27 +138,41 @@ 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, hint, size }: { i18nKey: string, hint: string, size: number }) {
- const ref = useRef<HTMLSpanElement>(null);
- useStaticTooltip(ref, useMemo(() => ({ title: hint, placement: "bottom" }), [ hint ]));
-
+function SizeLine({ i18nKey, help, size }: { i18nKey: string, help: string, size: number }) {
return (
- <span ref={ref} className="note-usage-donut-size">
+ <span className="note-usage-donut-size">
<Trans
i18nKey={i18nKey}
components={{
Size: <span className="note-usage-donut-size-value">{formatSize(size)}</span> as React.ReactElement
}}
/>
+ <ContextualHelp title={help} />
</span>
);
}
+/**
+ * The info affordance the option lists already use, on the app's tooltip rather than the browser's:
+ * a native one would appear somewhere else, after its own delay, and in its own styling — while the
+ * line's own hint is already the app's. Showing one dismisses the other, so the two never overlap.
+ */
+function ContextualHelp({ title }: { title: string }) {
+ const ref = useRef<HTMLSpanElement>(null);
+ useStaticTooltip(ref, useMemo(
+ () => ({ title, placement: "bottom", customClass: RAISED_TOOLTIP }),
+ [ title ]
+ ));
+
+ return <span ref={ref} className="bx bx-info-circle contextual-help" />;
+}
+
/** "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"
: kind === "child" ? "space_usage.child_tooltip"
- : "space_usage.segment_tooltip";
+ : kind === "revisions" ? "space_usage.revisions_tooltip"
+ : "space_usage.segment_tooltip";
return t(key, { title, size: formatSize(size) });
}