Skip to content

Build your personal knowledge base with Trilium Notes

feat(note_paths): show the root note as its icon

Elian Doran43bfd893ca0e
diff --git a/apps/client/src/widgets/react/NoteLink.css b/apps/client/src/widgets/react/NoteLink.css
index 477cd9daaf..62528b492e 100644
--- a/apps/client/src/widgets/react/NoteLink.css
+++ b/apps/client/src/widgets/react/NoteLink.css
@@ -1,4 +1,8 @@
/* The gap is a margin rather than a space, so the link's hover underline does not run under it. */
.tn-link > .note-link-icon {
margin-inline-end: 0.25em;
+
+ &:only-child {
+ margin-inline-end: 0;
+ }
}
diff --git a/apps/client/src/widgets/react/NoteLink.tsx b/apps/client/src/widgets/react/NoteLink.tsx
index 846e8575af..b13e060562 100644
--- a/apps/client/src/widgets/react/NoteLink.tsx
+++ b/apps/client/src/widgets/react/NoteLink.tsx
@@ -100,16 +100,18 @@ interface NewNoteLinkProps extends Pick<HTMLAttributes<HTMLAnchorElement>, "onCo
viewScope?: ViewScope;
noContextMenu?: boolean;
showNoteIcon?: boolean;
+ /** Shows only the note's icon, with the title as its tooltip and accessible name. */
+ iconOnly?: boolean;
noPreview?: boolean;
}
-export function NewNoteLink({ notePath, viewScope, noContextMenu, showNoteIcon, noPreview, ...linkProps }: NewNoteLinkProps) {
+export function NewNoteLink({ notePath, viewScope, noContextMenu, showNoteIcon, iconOnly, noPreview, ...linkProps }: NewNoteLinkProps) {
const { noteId, parentNoteId } = tree.getNoteIdAndParentIdFromUrl(notePath);
const note = useNote(noteId);
const title = useNoteTitle(noteId, parentNoteId);
- const icon = useNoteIcon(showNoteIcon ? note : null);
+ const icon = useNoteIcon(showNoteIcon || iconOnly ? note : null);
const colorClass = useNoteColorClass(note);
const [ archived ] = useNoteLabelBoolean(note, "archived");
@@ -121,10 +123,12 @@ export function NewNoteLink({ notePath, viewScope, noContextMenu, showNoteIcon,
})}
href={calculateHash({ notePath, viewScope })}
data-no-context-menu={noContextMenu}
+ title={iconOnly ? title : undefined}
+ aria-label={iconOnly ? title : undefined}
{...linkProps}
>
{icon && <Icon icon={icon} className="note-link-icon" />}
- {title}
+ {!iconOnly && title}
</a>
);
}
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.spec.tsx b/apps/client/src/widgets/ribbon/NotePathsTab.spec.tsx
new file mode 100644
index 0000000000..d43805f95a
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/NotePathsTab.spec.tsx
@@ -0,0 +1,41 @@
+import { describe, expect, it, vi } from "vitest";
+
+import froca from "../../services/froca";
+import { buildNote } from "../../test/easy-froca";
+import { renderInto } from "../../test/render";
+import { NotePathsWidget } from "./NotePathsTab";
+
+describe("NotePathsWidget", () => {
+ it("shows the root note as its icon, titled with the root note's name", async () => {
+ buildNote({
+ id: "root",
+ title: "My Knowledge Base",
+ children: [ { id: "calendar", title: "Calendar", children: [ { id: "leaf", title: "Leaf" } ] } ]
+ });
+ const rootIcon = froca.getNoteFromCache("root")?.getIcon();
+
+ const container = renderInto(
+ <NotePathsWidget
+ cloneButton={false}
+ currentNotePath="root/calendar/leaf"
+ sortedNotePaths={[ {
+ notePath: [ "root", "calendar", "leaf" ],
+ isArchived: false,
+ isInHoistedSubTree: true,
+ isHidden: false
+ } ]}
+ />
+ );
+ const path = container.querySelector(".note-path-list li");
+ await vi.waitFor(() => expect(path?.textContent).toContain("Leaf"));
+
+ const rootLink = path?.querySelector("a.tn-link");
+ expect(rootLink?.getAttribute("href")).toBe("#root");
+ expect(rootLink?.getAttribute("aria-label")).toBe("My Knowledge Base");
+ expect(rootLink?.getAttribute("title")).toBe("My Knowledge Base");
+ expect(rootLink?.textContent).toBe("");
+ expect(rootLink?.querySelector(".note-link-icon")?.className).toContain(rootIcon);
+ expect(path?.textContent).not.toContain("My Knowledge Base");
+ expect(path?.textContent).toContain("› Calendar › Leaf");
+ });
+});
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.tsx b/apps/client/src/widgets/ribbon/NotePathsTab.tsx
index 6486fca977..a18ffba7d9 100644
--- a/apps/client/src/widgets/ribbon/NotePathsTab.tsx
+++ b/apps/client/src/widgets/ribbon/NotePathsTab.tsx
@@ -9,7 +9,7 @@ import { t } from "../../services/i18n";
import { NOTE_PATH_TITLE_SEPARATOR } from "../../services/tree";
import { useTriliumEvent } from "../react/hooks";
import LinkButton from "../react/LinkButton";
-import NoteLink from "../react/NoteLink";
+import NoteLink, { NewNoteLink } from "../react/NoteLink";
import { joinElements, ParentComponent } from "../react/react_utils";
import { TabContext } from "./ribbon-interface";
@@ -130,7 +130,9 @@ function NotePath({ currentNotePath, notePathRecord }: { currentNotePath?: strin
return (
<li class={classes}>
- {joinElements(fullNotePaths.map((notePath, index, arr) => (
+ {joinElements(fullNotePaths.map((notePath, index, arr) => notePath === "root" ? (
+ <NewNoteLink key={notePath} notePath={notePath} iconOnly noPreview />
+ ) : (
<NoteLink key={notePath}
className={clsx({"basename": (index === arr.length - 1)})}
notePath={notePath}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Right Sidebar/Connections tab.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Right Sidebar/Connections tab.html
index 86bcdb8ed9..ca2af3f825 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Right Sidebar/Connections tab.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Right Sidebar/Connections tab.html
@@ -44,7 +44,9 @@ class="admonition note">
<h2>Note paths</h2>
<p>The note paths section displays the locations in which the current note
is <a href="#root/_help_IakOLONlIfGI">cloned</a>. Each segment of the note
- path is clickable, in order to navigate to that note or clone.</p>
+ path is clickable, in order to navigate to that note or clone. The root
+ note is shown as its icon, the same as in the <a class="reference-link"
+ href="#root/_help_I6p2a06hdnL6">Breadcrumb</a>; hovering it shows its title.</p>
<p>A new clone can be created from the top-right button.</p>
<h2>Backlinks</h2>
<p>Backlinks list the notes that refer to the current note, as well as a
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Right Sidebar/Connections tab.md b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Right Sidebar/Connections tab.md
index 691e76f0b2..588d7cfd61 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Right Sidebar/Connections tab.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Right Sidebar/Connections tab.md
@@ -26,7 +26,7 @@ See also:
## Note paths
-The note paths section displays the locations in which the current note is [cloned](../../Notes/Cloning%20Notes.md). Each segment of the note path is clickable, in order to navigate to that note or clone.
+The note paths section displays the locations in which the current note is [cloned](../../Notes/Cloning%20Notes.md). Each segment of the note path is clickable, in order to navigate to that note or clone. The root note is shown as its icon, the same as in the <a class="reference-link" href="../New%20Layout/Breadcrumb.md">Breadcrumb</a>; hovering it shows its title.
A new clone can be created from the top-right button.