Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager/space usage: consistency fixes

Adorian Doran8e5527b3d4c8
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.spec.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.spec.ts
index edd09d68d3..0f9e9f8e68 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.spec.ts
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.spec.ts
@@ -157,17 +157,22 @@ describe("openSpaceUsageContextMenu", () => {
expect(itemByIcon(DOWNLOAD)?.enabled).toBe(false);
});
- it("disables Export and Delete on the root, which has no parent to place it", async () => {
+ it("drops Delete on the root and disables Export, however it was reached", async () => {
givenNote("root");
await openFor([ "root" ]);
+ // Not merely struck through: the root can never be deleted, so it is not offered.
+ expect(icons()).toEqual([ QUICK_EDIT, NEW_TAB, SHOW_DETAILS, EXPORT ]);
expect(itemByIcon(EXPORT)?.enabled).toBe(false);
- expect(itemByIcon(DELETE)?.enabled).toBe(false);
- invoke(DELETE);
- expect(mocks.deleteNotes).not.toHaveBeenCalled();
// Opening it is still fine.
expect(itemByIcon(QUICK_EDIT)?.enabled).toBeUndefined();
+
+ // The overview builds the root's path as "root/root", making it look parented; the root
+ // is recognised by its ID, so that path fares no differently.
+ mocks.branchIds.set("root/root", "none_root");
+ await openFor([ "root", "root" ]);
+ expect(itemByIcon(DELETE)).toBeUndefined();
});
it("shows no menu at all for a note deleted since the usage was measured", async () => {
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts
index 1a007b3054..e8c2ba6abe 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/context_menu.ts
@@ -9,6 +9,8 @@ import froca from "../../../../../services/froca";
import { t } from "../../../../../services/i18n";
import { downloadFileNote } from "../../../../../services/open";
+const ROOT_NOTE_ID = "root";
+
/** Switches the section to Browse, focused on the given path. */
export type ShowDetailsHandler = (notePath: string[]) => void;
@@ -40,8 +42,10 @@ export async function openSpaceUsageContextMenu(
return;
}
- // The root has no parent, so it has neither a branch to delete nor a path the export dialog can
- // resolve into one.
+ // The root has no parent, so no path the export dialog can resolve into a branch. Note that
+ // `getBranchId` answers the placeholder "none_root" for the root rather than nothing, so the
+ // root is recognised by its ID and never by the absence of a branch.
+ const isRoot = noteId === ROOT_NOTE_ID;
const branchId = parentNoteId ? await froca.getBranchId(parentNoteId, noteId) : null;
const notePathString = notePath.join("/");
@@ -85,18 +89,21 @@ export async function openSpaceUsageContextMenu(
}
},
- { kind: "separator" },
-
- {
- title: t("tree-context-menu.delete"),
- uiIcon: "bx bx-trash destructive-action-icon",
- enabled: !!branchId,
- handler: () => {
- if (branchId) {
- void branches.deleteNotes([ branchId ], false, false);
+ // The root cannot be deleted at all, so it is left out rather than shown struck through —
+ // and its separator goes with it, or the menu would end on a dangling divider.
+ ...(isRoot ? [] : [
+ { kind: "separator" as const },
+ {
+ title: t("tree-context-menu.delete"),
+ uiIcon: "bx bx-trash destructive-action-icon",
+ enabled: !!branchId,
+ handler: () => {
+ if (branchId) {
+ void branches.deleteNotes([ branchId ], false, false);
+ }
}
}
- }
+ ])
];
await contextMenu.show({
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.tsx
index ddf68e454b..243298fc78 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
@@ -12,8 +12,7 @@ import { bucketWeight, buildOverviewModel, type OverviewCell } from "./overview_
* A cell's area covers a note's body and attachments, leaving history out; its tooltip says the
* same. Per-note revision sizes are counted per entity rather than deduplicated, so a revision
* snapshotting an unchanged body reports its full size while costing the database nothing — folding
- * that into the areas would inflate cells by bytes that were never spent. The status line reports
- * the deduplicated revisions total instead.
+ * that into the areas would inflate cells by bytes that were never spent.
*/
const INCLUDE_REVISIONS = false;
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.ts
index c175ad9824..7ba3a30f2c 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
@@ -37,7 +37,12 @@ interface OverviewModelOptions {
* appear near their siblings and share their parent's hue. An entry that is itself an ancestor of
* other entries keeps its own weight as a nested self-cell inside its area. The "other notes",
* "hidden notes", "revisions" and "deleted notes" buckets join at the top level as inert cells, so
- * every byte the status line counts has a cell somewhere.
+ * nothing the database holds is left off the map.
+ *
+ * The areas deliberately do not add up to the status line's total. A note's cell is its own
+ * per-entity size, so content shared byte for byte is counted at every note holding it, while the
+ * revisions and deleted buckets are deduplicated figures. Each basis is the right one for what it
+ * measures — per-note for a cell, whole-database for a total — but the two are not summable.
*
* The cells carry no text — identity comes from hovering: note cells get the note preview tooltip
* via `data-href`, the bucket cells the chart's own tooltip naming the crowd they stand for.