Skip to content

Build your personal knowledge base with Trilium Notes

feat(mind-map): say on the memo's tab whether anything is written there

Elian Dorandb2c728ddfc2
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
index 7274db304d..f77b1e0093 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
@@ -265,10 +265,24 @@ describe("the memo field of the panel", () => {
/**
* The panel opens on the formatting tab, and the editor is built only when the memo's own is
* first opened — so there is nothing to read or write into before this.
+ *
+ * Found by either face it wears: the tab says on itself whether anything is written about the
+ * node, so naming one icon would be naming only the nodes that carry a memo.
*/
- const openMemoTab = (container: HTMLElement) => openTab(container, "bx-notepad");
+ async function openMemoTab(container: HTMLElement) {
+ const tab = memoTabIcon(container)?.closest("button");
+ if (!tab) throw new Error("the panel has no memo tab");
+
+ await act(async () => tab.click());
+ }
+
const openFormatTab = (container: HTMLElement) => openTab(container, "bx-palette");
+ /** The face the memo's tab wears, which is what it says about the node without being opened. */
+ function memoTabIcon(container: HTMLElement) {
+ return container.querySelector('[role="tab"] .bx-notepad, [role="tab"] .bx-calendar-alt');
+ }
+
/** The tabs' bodies, in the order they are laid into the panel — all of them, shown or not. */
function tabBodies(container: HTMLElement) {
return [ ...container.querySelectorAll('[role="tabpanel"]') ];
@@ -429,6 +443,21 @@ describe("the memo field of the panel", () => {
return container;
}
+ it("says on the tab whether there is anything written about the node", async () => {
+ // The map draws everything else a node holds and draws nothing of a memo, so the tab is the
+ // only place one is ever announced — worth saying before it is opened.
+ const faceOf = (nodes: NodeObj[]) => {
+ const panel = renderInto(<NodePanel mind={buildMind(nodes).mind} noteId="map" nodes={nodes} />);
+ return [ ...memoTabIcon(panel)?.classList ?? [] ].find((name) => name.startsWith("bx-"));
+ };
+ const written = (id: string, memo: string) => buildNode({ id, memo } as Partial<NodeObj>);
+
+ expect(faceOf([ buildNode() ])).toBe("bx-calendar-alt");
+ expect(faceOf([ written("a", "<p>About A</p>") ])).toBe("bx-notepad");
+ // A selection whose memos differ carries one all the same: there is something to go and read.
+ expect(faceOf([ written("a", "<p>About A</p>"), buildNode({ id: "b" }) ])).toBe("bx-notepad");
+ });
+
it("holds the memo alone, and nothing to edit with, on a map that can only be read", async () => {
const node = buildNode({ id: "a", memo: "<p>About A</p>" } as Partial<NodeObj>);
diff --git a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
index ce1883b385..8bd99eddee 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
@@ -168,7 +168,9 @@ export default function NodePanel({ mind, noteId, nodes, readOnly }: NodePanelPr
) : (
<TabStrip
className="mind-map-node-panel-tabs"
- tabs={buildTabs()}
+ // A selection whose memos differ carries one all the same, which is what the
+ // tab is saying: that there is something written to go and read.
+ tabs={buildTabs(memo !== null)}
activeTabId={activeTabId}
onSelect={setActiveTabId}
/>
@@ -322,13 +324,25 @@ type NodePanelTabId = "format" | "memo";
* rather than picked from, and a paragraph of prose wants the room the whole panel has — which, at
* the foot of eight other fields, meant scrolling to the bottom to reach a box three lines tall.
*/
-function buildTabs(): TabStripTabDefinition<NodePanelTabId>[] {
+function buildTabs(hasMemo: boolean): TabStripTabDefinition<NodePanelTabId>[] {
return [
{ id: "format", title: t("mind-map.tab-format"), icon: "bx bx-palette" },
- { id: "memo", title: t("mind-map.memo"), icon: "bx bx-notepad" }
+ { id: "memo", title: t("mind-map.memo"), icon: hasMemo ? MEMO_WRITTEN_ICON : MEMO_BLANK_ICON }
];
}
+/**
+ * What the memo's tab wears: a pad with writing on it where the selection carries a memo, and the
+ * same pad blank where it carries none.
+ *
+ * The tab is the only place a memo is ever announced — the map draws every other thing a node holds,
+ * and draws nothing of this — so whether there is one to read is worth saying before the tab is
+ * opened. The two are one shape and differ only in that one has been written on, which is the whole
+ * of what the pair has to say; the blank comes from the calendar, its outline being the pad's own.
+ */
+const MEMO_WRITTEN_ICON = "bx bx-notepad";
+const MEMO_BLANK_ICON = "bx bx-calendar-alt";
+
/**
* A node of medium size is one with no size of its own: that is what a node comes with, and it
* leaves the root, which is larger by default, at the size its level implies rather than pinning