Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): remove the ribbon's note paths tab

Elian Dorana2bedf306af2
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index b219dece60..4f35cf803c 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1377,7 +1377,6 @@
"note_paths": {
"title": "Note Paths",
"clone_button": "Clone note to new location...",
- "intro_placed": "This note is placed into the following paths:",
"intro_not_placed": "This note is not yet placed into the note tree.",
"outside_hoisted": "This path is outside of hoisted note and you would have to unhoist.",
"archived": "Archived",
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index c18e0861db..9b185e7ab5 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -29,8 +29,8 @@ import Icon from "../react/Icon";
import LinkButton from "../react/LinkButton";
import { ParentComponent } from "../react/react_utils";
import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab";
-import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
import SimilarNotesTab from "../ribbon/SimilarNotesTab";
+import { NotePathsWidget, useSortedNotePaths } from "../sidebar/NotePaths";
import type { RightPaneTabId } from "../sidebar/RightPaneTabs";
import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";
import Breadcrumb from "./Breadcrumb";
diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
index 94a0f4ffbc..79abd427a2 100644
--- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
+++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
@@ -19,8 +19,8 @@ import { MenuItemRows } from "../react/Menu";
import Modal from "../react/Modal";
import { NoteContextMenu } from "../ribbon/NoteActions";
import NoteActionsCustom from "../ribbon/NoteActionsCustom";
-import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
import SimilarNotesTab from "../ribbon/SimilarNotesTab";
+import { NotePathsWidget, useSortedNotePaths } from "../sidebar/NotePaths";
import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";
export default function MobileDetailMenu() {
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.css b/apps/client/src/widgets/ribbon/NotePathsTab.css
deleted file mode 100644
index e8339a1370..0000000000
--- a/apps/client/src/widgets/ribbon/NotePathsTab.css
+++ /dev/null
@@ -1,81 +0,0 @@
-body.experimental-feature-new-layout .note-paths-widget {
- .note-path-intro {
- color: var(--muted-text-color);
- }
-
- .note-path-list {
- margin: 8px 0;
- padding: 0;
- list-style: none;
-
- /* The room is for what the list is set between — the intro line, the clone link. Where it is
- all the widget holds, as in the sidebar's card, the card's own padding is the room. */
- &:first-child { margin-top: 0; }
- &:last-child { margin-bottom: 0; }
-
- /* A path is framed already by what holds the list — a card, or the mobile note menu — so it
- carries no frame of its own: what tells one path from the next is the room around it, and
- the gutter each hangs its marks in. */
- li {
- position: relative;
- padding-block: 5px;
- padding-inline-start: 17px;
- /* A path is read for where the note sits, not for the words themselves, so it is set a
- step below the text around it — the separators and the marks with it, hence the size
- on the path rather than on its links. */
- font-size: .9em;
-
- /* Current path arrow, in the gutter the paths are indented for. */
- &.path-current::before {
- position: absolute;
- display: flex;
- justify-content: flex-end;
- align-items: center;
- content: "\ee8f";
- top: 0;
- inset-inline-start: 0;
- width: 12px;
- bottom: 0;
- font-family: "boxicons";
- font-size: .75em;
- color: var(--menu-item-icon-color);
- }
- }
-
- /* Note path segment */
- a {
- padding-inline: 1px;
- color: currentColor;
- font-weight: normal;
- text-decoration: none;
-
- /* The last segment of the note path */
- &.basename {
- color: var(--muted-text-color);
- }
- }
-
- }
-}
-
-.note-paths-widget {
- padding: 12px;
- max-height: 300px;
- overflow-y: auto;
-}
-
-.note-path-list {
- margin-top: 10px;
-}
-
-.note-path-list .path-current a {
- font-weight: bold;
-}
-
-.note-path-list .path-archived a {
- color: var(--muted-text-color) !important;
-}
-
-.note-path-list .path-search a {
- font-style: italic;
-}
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.tsx b/apps/client/src/widgets/ribbon/NotePathsTab.tsx
deleted file mode 100644
index a18ffba7d9..0000000000
--- a/apps/client/src/widgets/ribbon/NotePathsTab.tsx
+++ /dev/null
@@ -1,147 +0,0 @@
-import "./NotePathsTab.css";
-
-import clsx from "clsx";
-import { useContext, useEffect, useMemo, useState } from "preact/hooks";
-
-import FNote, { NotePathRecord } from "../../entities/fnote";
-import { isExperimentalFeatureEnabled } from "../../services/experimental_features";
-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, { NewNoteLink } from "../react/NoteLink";
-import { joinElements, ParentComponent } from "../react/react_utils";
-import { TabContext } from "./ribbon-interface";
-
-export default function NotePathsTab({ note, hoistedNoteId, notePath }: TabContext) {
- const sortedNotePaths = useSortedNotePaths(note, hoistedNoteId);
- return <NotePathsWidget sortedNotePaths={sortedNotePaths} currentNotePath={notePath} />;
-}
-
-export function NotePathsWidget({ sortedNotePaths, currentNotePath, cloneButton = true }: {
- sortedNotePaths: NotePathRecord[] | undefined;
- currentNotePath?: string | null | undefined;
- /**
- * Offer cloning the note below the list. Turned off by whoever offers it elsewhere — the sidebar's
- * card puts the action in its header, where the widget's own buttons go.
- */
- cloneButton?: boolean;
-}) {
- const parentComponent = useContext(ParentComponent);
- // What holds the list in the new layout — the sidebar's card, the mobile note menu's modal, the
- // badge the status bar's dropdown hangs off — names the paths already, so the line saying the note
- // is placed in them is left to the ribbon's tab, which carries no title of its own. A note placed
- // nowhere still says so wherever it is shown: the list is then empty, and nothing else would
- // account for it.
- const intro = sortedNotePaths?.length
- ? (isExperimentalFeatureEnabled("new-layout") ? null : t("note_paths.intro_placed"))
- : t("note_paths.intro_not_placed");
-
- return (
- <div class="note-paths-widget">
- <>
- {intro && <div className="note-path-intro">{intro}</div>}
-
- <ul className="note-path-list">
- {sortedNotePaths?.length ? sortedNotePaths.map(sortedNotePath => (
- <NotePath
- // Keyed by the joined path, not the array: `getAllNotePaths()` hands back
- // fresh arrays on every refresh, so an array key never matches the previous
- // one and each row would remount — blanking its links until they resolve.
- key={sortedNotePath.notePath.join("/")}
- currentNotePath={currentNotePath}
- notePathRecord={sortedNotePath}
- />
- )) : undefined}
- </ul>
-
- {cloneButton && (
- <LinkButton
- text={t("note_paths.clone_button")}
- onClick={() => void parentComponent?.triggerCommand("cloneNoteIdsTo")}
- />
- )}
- </>
- </div>
- );
-}
-
-export function useSortedNotePaths(note: FNote | null | undefined, hoistedNoteId?: string) {
- const [ sortedNotePaths, setSortedNotePaths ] = useState<NotePathRecord[]>();
-
- function refresh() {
- if (!note) return;
- setSortedNotePaths(note
- .getSortedNotePathRecords(hoistedNoteId)
- .filter((notePath) => !notePath.isHidden));
- }
-
- useEffect(refresh, [ note, hoistedNoteId ]);
- useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
- const noteId = note?.noteId;
- if (!noteId) return;
- if (loadResults.getBranchRows().find((branch) => branch.noteId === noteId)
- || loadResults.isNoteReloaded(noteId)) {
- refresh();
- }
- });
-
- return sortedNotePaths;
-}
-
-function NotePath({ currentNotePath, notePathRecord }: { currentNotePath?: string | null, notePathRecord?: NotePathRecord }) {
- const notePath = notePathRecord?.notePath;
- const notePathString = useMemo(() => (notePath ?? []).join("/"), [ notePath ]);
-
- const [ classes, icons ] = useMemo(() => {
- const classes: string[] = [];
- const icons: { icon: string, title: string }[] = [];
-
- if (notePathString === currentNotePath) {
- classes.push("path-current");
- }
-
- if (!notePathRecord || notePathRecord.isInHoistedSubTree) {
- classes.push("path-in-hoisted-subtree");
- } else {
- icons.push({ icon: "bx bx-trending-up", title: t("note_paths.outside_hoisted") });
- }
-
- if (notePathRecord?.isArchived) {
- classes.push("path-archived");
- icons.push({ icon: "bx bx-archive", title: t("note_paths.archived") });
- }
-
- if (notePathRecord?.isSearch) {
- classes.push("path-search");
- icons.push({ icon: "bx bx-search", title: t("note_paths.search") });
- }
-
- return [ classes.join(" "), icons ];
- }, [ notePathString, currentNotePath, notePathRecord ]);
-
- // Determine the full note path (for the links) of every component of the current note path.
- const pathSegments: string[] = [];
- const fullNotePaths: string[] = [];
- for (const noteId of notePath ?? []) {
- pathSegments.push(noteId);
- fullNotePaths.push(pathSegments.join("/"));
- }
-
- return (
- <li class={classes}>
- {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}
- noPreview />
- )), NOTE_PATH_TITLE_SEPARATOR)}
-
- {icons.map(({ icon, title }) => (
- <i key={title} class={icon} title={title} />
- ))}
- </li>
- );
-}
diff --git a/apps/client/src/widgets/ribbon/RibbonDefinition.ts b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
index ae42990610..ec440fa81d 100644
--- a/apps/client/src/widgets/ribbon/RibbonDefinition.ts
+++ b/apps/client/src/widgets/ribbon/RibbonDefinition.ts
@@ -5,7 +5,6 @@ import FilePropertiesTab from "./FilePropertiesTab";
import ImagePropertiesTab from "./ImagePropertiesTab";
import NoteInfoTab from "./NoteInfoTab";
import NoteMapTab from "./NoteMapTab";
-import NotePathsTab from "./NotePathsTab";
import NotePropertiesTab from "./NotePropertiesTab";
import { TabConfiguration } from "./ribbon-interface";
import ScriptTab from "./ScriptTab";
@@ -59,13 +58,6 @@ export const RIBBON_TAB_DEFINITIONS: TabConfiguration[] = [
toggleCommand: "toggleRibbonTabImageProperties",
activate: true,
},
- {
- title: t("note_paths.title"),
- icon: "bx bx-collection",
- content: NotePathsTab,
- show: true,
- toggleCommand: "toggleRibbonTabNotePaths"
- },
{
title: t("note_map.title"),
icon: "bx bxs-network-chart",
diff --git a/apps/client/src/widgets/sidebar/NotePaths.css b/apps/client/src/widgets/sidebar/NotePaths.css
index 47e806f9b8..2e3b743f92 100644
--- a/apps/client/src/widgets/sidebar/NotePaths.css
+++ b/apps/client/src/widgets/sidebar/NotePaths.css
@@ -1,3 +1,75 @@
+.note-paths-widget {
+ padding: 12px;
+ max-height: 300px;
+ overflow-y: auto;
+
+ .note-path-intro {
+ color: var(--muted-text-color);
+ }
+
+ .note-path-list {
+ margin: 8px 0;
+ padding: 0;
+ list-style: none;
+
+ /* The room is for what the list is set between — the intro line, the clone link. Where it is
+ all the widget holds, as in the sidebar's card, the card's own padding is the room. */
+ &:first-child { margin-top: 0; }
+ &:last-child { margin-bottom: 0; }
+
+ /* A path is framed already by what holds the list — a card, or the mobile note menu — so it
+ carries no frame of its own: what tells one path from the next is the room around it, and
+ the gutter each hangs its marks in. */
+ li {
+ position: relative;
+ padding-block: 5px;
+ padding-inline-start: 17px;
+ /* A path is read for where the note sits, not for the words themselves, so it is set a
+ step below the text around it — the separators and the marks with it, hence the size
+ on the path rather than on its links. */
+ font-size: .9em;
+
+ /* Current path arrow, in the gutter the paths are indented for. */
+ &.path-current::before {
+ position: absolute;
+ display: flex;
+ justify-content: flex-end;
+ align-items: center;
+ content: "\ee8f";
+ top: 0;
+ inset-inline-start: 0;
+ width: 12px;
+ bottom: 0;
+ font-family: "boxicons";
+ font-size: .75em;
+ color: var(--menu-item-icon-color);
+ }
+ }
+
+ /* Note path segment */
+ a {
+ padding-inline: 1px;
+ color: currentColor;
+ font-weight: normal;
+ text-decoration: none;
+
+ /* The last segment of the note path */
+ &.basename {
+ color: var(--muted-text-color);
+ }
+ }
+
+ }
+}
+
+.note-path-list .path-archived a {
+ color: var(--muted-text-color) !important;
+}
+
+.note-path-list .path-search a {
+ font-style: italic;
+}
+
#right-pane .note-paths-widget {
padding: 0;
}
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.spec.tsx b/apps/client/src/widgets/sidebar/NotePaths.spec.tsx
similarity index 97%
rename from apps/client/src/widgets/ribbon/NotePathsTab.spec.tsx
rename to apps/client/src/widgets/sidebar/NotePaths.spec.tsx
index d43805f95a..1bcc86b989 100644
--- a/apps/client/src/widgets/ribbon/NotePathsTab.spec.tsx
+++ b/apps/client/src/widgets/sidebar/NotePaths.spec.tsx
@@ -3,7 +3,7 @@ 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";
+import { NotePathsWidget } from "./NotePaths";
describe("NotePathsWidget", () => {
it("shows the root note as its icon, titled with the root note's name", async () => {
diff --git a/apps/client/src/widgets/sidebar/NotePaths.tsx b/apps/client/src/widgets/sidebar/NotePaths.tsx
index 32b0c885f0..238e5ba600 100644
--- a/apps/client/src/widgets/sidebar/NotePaths.tsx
+++ b/apps/client/src/widgets/sidebar/NotePaths.tsx
@@ -1,14 +1,16 @@
import "./NotePaths.css";
-import { useContext } from "preact/hooks";
+import clsx from "clsx";
+import { useContext, useEffect, useMemo, useState } from "preact/hooks";
+import FNote, { NotePathRecord } from "../../entities/fnote";
import { t } from "../../services/i18n";
+import { NOTE_PATH_TITLE_SEPARATOR } from "../../services/tree";
import ActionButton from "../react/ActionButton";
-import { useActiveNoteContext } from "../react/hooks";
-import { ParentComponent } from "../react/react_utils";
-// The paths list is shared with the ribbon's note paths tab, the status bar's badge and the mobile
-// note menu; only the framing differs here.
-import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
+import { useActiveNoteContext, useTriliumEvent } from "../react/hooks";
+import LinkButton from "../react/LinkButton";
+import NoteLink, { NewNoteLink } from "../react/NoteLink";
+import { joinElements, ParentComponent } from "../react/react_utils";
import RightPanelWidget from "./RightPanelWidget";
import SidebarHelp from "./SidebarHelp";
@@ -37,3 +39,123 @@ export default function NotePaths() {
</RightPanelWidget>
);
}
+
+export function NotePathsWidget({ sortedNotePaths, currentNotePath, cloneButton = true }: {
+ sortedNotePaths: NotePathRecord[] | undefined;
+ currentNotePath?: string | null | undefined;
+ /**
+ * Offer cloning the note below the list. Turned off by whoever offers it elsewhere — the sidebar's
+ * card puts the action in its header, where the widget's own buttons go.
+ */
+ cloneButton?: boolean;
+}) {
+ const parentComponent = useContext(ParentComponent);
+
+ return (
+ <div class="note-paths-widget">
+ <>
+ {!sortedNotePaths?.length && <div className="note-path-intro">{t("note_paths.intro_not_placed")}</div>}
+
+ <ul className="note-path-list">
+ {sortedNotePaths?.length ? sortedNotePaths.map(sortedNotePath => (
+ <NotePath
+ // Keyed by the joined path, not the array: `getAllNotePaths()` hands back
+ // fresh arrays on every refresh, so an array key never matches the previous
+ // one and each row would remount — blanking its links until they resolve.
+ key={sortedNotePath.notePath.join("/")}
+ currentNotePath={currentNotePath}
+ notePathRecord={sortedNotePath}
+ />
+ )) : undefined}
+ </ul>
+
+ {cloneButton && (
+ <LinkButton
+ text={t("note_paths.clone_button")}
+ onClick={() => void parentComponent?.triggerCommand("cloneNoteIdsTo")}
+ />
+ )}
+ </>
+ </div>
+ );
+}
+
+export function useSortedNotePaths(note: FNote | null | undefined, hoistedNoteId?: string) {
+ const [ sortedNotePaths, setSortedNotePaths ] = useState<NotePathRecord[]>();
+
+ function refresh() {
+ if (!note) return;
+ setSortedNotePaths(note
+ .getSortedNotePathRecords(hoistedNoteId)
+ .filter((notePath) => !notePath.isHidden));
+ }
+
+ useEffect(refresh, [ note, hoistedNoteId ]);
+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
+ const noteId = note?.noteId;
+ if (!noteId) return;
+ if (loadResults.getBranchRows().find((branch) => branch.noteId === noteId)
+ || loadResults.isNoteReloaded(noteId)) {
+ refresh();
+ }
+ });
+
+ return sortedNotePaths;
+}
+
+function NotePath({ currentNotePath, notePathRecord }: { currentNotePath?: string | null, notePathRecord?: NotePathRecord }) {
+ const notePath = notePathRecord?.notePath;
+ const notePathString = useMemo(() => (notePath ?? []).join("/"), [ notePath ]);
+
+ const [ classes, icons ] = useMemo(() => {
+ const classes: string[] = [];
+ const icons: { icon: string, title: string }[] = [];
+
+ if (notePathString === currentNotePath) {
+ classes.push("path-current");
+ }
+
+ if (!notePathRecord || notePathRecord.isInHoistedSubTree) {
+ classes.push("path-in-hoisted-subtree");
+ } else {
+ icons.push({ icon: "bx bx-trending-up", title: t("note_paths.outside_hoisted") });
+ }
+
+ if (notePathRecord?.isArchived) {
+ classes.push("path-archived");
+ icons.push({ icon: "bx bx-archive", title: t("note_paths.archived") });
+ }
+
+ if (notePathRecord?.isSearch) {
+ classes.push("path-search");
+ icons.push({ icon: "bx bx-search", title: t("note_paths.search") });
+ }
+
+ return [ classes.join(" "), icons ];
+ }, [ notePathString, currentNotePath, notePathRecord ]);
+
+ // Determine the full note path (for the links) of every component of the current note path.
+ const pathSegments: string[] = [];
+ const fullNotePaths: string[] = [];
+ for (const noteId of notePath ?? []) {
+ pathSegments.push(noteId);
+ fullNotePaths.push(pathSegments.join("/"));
+ }
+
+ return (
+ <li class={classes}>
+ {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}
+ noPreview />
+ )), NOTE_PATH_TITLE_SEPARATOR)}
+
+ {icons.map(({ icon, title }) => (
+ <i key={title} class={icon} title={title} />
+ ))}
+ </li>
+ );
+}