Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): note paths and backlinks come back as status bar dropdowns

Elian Doran1e48a510999d
diff --git a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
index 74b22151a7..a67b64537e 100644
--- a/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
+++ b/apps/client/src/widgets/FloatingButtonsDefinitions.tsx
@@ -441,6 +441,21 @@ export function BacklinksList({ note }: { note: FNote }) {
));
}
+/**
+ * {@link BacklinksList} in the markup its styling hangs off (see Backlinks.css), for the places that
+ * frame the list rather than build it: the sidebar's card, the mobile note menu's modal, the status
+ * bar's dropdown. The floating button keeps its own container, being a popup it also sizes by hand.
+ */
+export function BacklinksWidget({ note }: { note: FNote }) {
+ return (
+ <div class="tn-backlinks-widget">
+ <ul class="backlinks-items">
+ <BacklinksList note={note} />
+ </ul>
+ </div>
+ );
+}
+
function needsRefresh(note: FNote, loadResults: LoadResults) {
return loadResults.getAttributeRows().some(attr =>
attr.type === "relation" &&
diff --git a/apps/client/src/widgets/layout/NoteBadges.css b/apps/client/src/widgets/layout/NoteBadges.css
index cac8acf4df..80f96a90f7 100644
--- a/apps/client/src/widgets/layout/NoteBadges.css
+++ b/apps/client/src/widgets/layout/NoteBadges.css
@@ -61,11 +61,5 @@
--switch-track-width: 30px;
}
}
-
- .dropdown-badge {
- &.dropdown-backlinks-badge .dropdown-menu {
- min-width: 500px;
- }
- }
}
diff --git a/apps/client/src/widgets/layout/StatusBar.css b/apps/client/src/widgets/layout/StatusBar.css
index ab1628b3dc..7203830bcb 100644
--- a/apps/client/src/widgets/layout/StatusBar.css
+++ b/apps/client/src/widgets/layout/StatusBar.css
@@ -62,6 +62,21 @@
.dropdown-note-info {
padding: 1em !important;
}
+
+ .dropdown-note-paths {
+ .note-paths-widget {
+ padding: 0.5em;
+ }
+ }
+
+ .dropdown-backlinks {
+ --menu-padding-size: .9em;
+
+ min-width: 300px;
+ max-width: 500px;
+ max-height: 60vh;
+ overflow-y: auto;
+ }
}
> .attribute-list {
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index 15ad91c29a..82afb9aabf 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -18,7 +18,7 @@ import { NOTE_TYPES } from "../../services/note_types";
import server from "../../services/server";
import { openInAppHelpFromUrl } from "../../services/utils";
import { formatDateTime } from "../../utils/formatters";
-import { useBacklinkCount } from "../FloatingButtonsDefinitions";
+import { BacklinksWidget, useBacklinkCount } from "../FloatingButtonsDefinitions";
import Dropdown, { DropdownProps } from "../react/Dropdown";
import { FormDropdownDivider, FormListHeader, FormListItem } from "../react/FormList";
import HelpDropdown from "../react/HelpDropdown";
@@ -31,7 +31,7 @@ import AttributeEditor, { AttributeEditorImperativeHandlers } from "../ribbon/co
import AttributeHelp from "../ribbon/components/AttributeHelp";
import InheritedAttributesTab from "../ribbon/InheritedAttributesTab";
import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab";
-import { useSortedNotePaths } from "../ribbon/NotePathsTab";
+import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
import { useAttachments } from "../type_widgets/Attachment";
import { useProcessedLocales } from "../type_widgets/options/components/LocaleSelector";
import Breadcrumb from "./Breadcrumb";
@@ -42,14 +42,15 @@ interface StatusBarContext {
noteContext: NoteContext;
viewScope?: ViewScope;
hoistedNoteId?: string;
+ notePath?: string | null;
}
export default function StatusBar() {
- const { note, noteContext, viewScope, hoistedNoteId } = useActiveNoteContext();
- // The attributes are the one thing the status bar still shows in a panel of its own; the rest of
- // what it stands for is shown in the sidebar (see useConnectionsToggle).
+ const { note, noteContext, viewScope, hoistedNoteId, notePath } = useActiveNoteContext();
+ // The attributes are the one thing the status bar shows in a panel of its own, being edited rather
+ // than read; the lists the other badges stand for are read at a glance, so they come as dropdowns.
const [ attributesShown, setAttributesShown ] = useState(false);
- const context: StatusBarContext | undefined | null = note && noteContext && { note, noteContext, viewScope, hoistedNoteId };
+ const context: StatusBarContext | undefined | null = note && noteContext && { note, noteContext, viewScope, hoistedNoteId, notePath };
const attributesContext: AttributesProps | undefined | null = context && { ...context, attributesShown, setAttributesShown };
const isHiddenNote = note?.isHiddenCompletely();
@@ -153,12 +154,12 @@ function StatusBarButton({ className, icon, text, title, active, ...restProps }:
}
/**
- * Opens the sidebar's connections tab at one of its widgets, and closes it again on a second press —
- * what the badges standing for a connection of the note offer instead of a popup copy of the list.
+ * Opens the sidebar's connections tab at one of its widgets, and closes it again on a second press.
+ * The way to the one connection the status bar carries no list of its own for: what a note resembles
+ * is computed rather than counted, so no badge stands for it to hang a dropdown off.
*
* A pane the user keeps closed is peeked rather than docked: the status bar is no place to reflow the
- * content from. Buttons wired to this carry `right-pane-peek-source`, which is what keeps their press
- * from dismissing the very peek it is toggling (see RightPanelContainer's peek dismissal).
+ * content from.
*/
function useConnectionsToggle(expandWidgetId: string) {
return useCallback(() => {
@@ -298,19 +299,23 @@ function NoteInfoValue({ text, title, value }: { text: string; title?: string, v
//#endregion
//#region Backlinks
-/** What points at the note is listed in the sidebar's connections tab, which the badge is the way to. */
+/**
+ * What points at the note, in a dropdown of the badge naming them — the same list the sidebar's
+ * connections tab holds, which stays the place to keep it open beside the note.
+ */
function BacklinksBadge({ note, viewScope }: StatusBarContext) {
const count = useBacklinkCount(note, viewScope?.viewMode === "default");
- const toggleBacklinks = useConnectionsToggle("backlinks");
return (note && count > 0 &&
- <StatusBarButton
- className="backlinks-badge right-pane-peek-source"
+ <StatusBarDropdown
+ className="backlinks-badge"
icon="bx bx-link"
text={t("status_bar.backlinks", { count })}
title={t("status_bar.backlinks_title", { count })}
- onClick={toggleBacklinks}
- />
+ dropdownContainerClassName="dropdown-backlinks"
+ >
+ <BacklinksWidget note={note} />
+ </StatusBarDropdown>
);
}
//#endregion
@@ -426,23 +431,30 @@ function AttributesPane({ note, noteContext, attributesShown, setAttributesShown
//#endregion
//#region Note paths
-/** Where the note sits in the tree is listed in the sidebar's connections tab, which the badge is the way to. */
-function NotePaths({ note, hoistedNoteId }: StatusBarContext) {
+/**
+ * Where the note sits in the tree, in a dropdown of the badge counting the places — the same list the
+ * sidebar's connections tab holds, which stays the place to keep it open beside the note.
+ */
+function NotePaths({ note, hoistedNoteId, notePath }: StatusBarContext) {
+ const dropdownRef = useRef<BootstrapDropdown>(null);
const sortedNotePaths = useSortedNotePaths(note, hoistedNoteId);
const count = sortedNotePaths?.length ?? 0;
- const toggleNotePaths = useConnectionsToggle("notePaths");
// Keyboard shortcut.
- useTriliumEvent("toggleRibbonTabNotePaths", toggleNotePaths);
+ useTriliumEvent("toggleRibbonTabNotePaths", () => dropdownRef.current?.show());
return (
- <StatusBarButton
- className="note-paths-button right-pane-peek-source"
+ <StatusBarDropdown
+ className="note-paths-button"
icon="bx bx-directions"
title={t("status_bar.note_paths_title")}
text={t("status_bar.note_paths", { count })}
- onClick={toggleNotePaths}
- />
+ dropdownRef={dropdownRef}
+ dropdownContainerClassName="dropdown-note-paths"
+ noDropdownListStyle
+ >
+ <NotePathsWidget sortedNotePaths={sortedNotePaths} currentNotePath={notePath} />
+ </StatusBarDropdown>
);
}
//#endregion
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 1c8065e31e..a98c75f2e8 100644
--- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
+++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx
@@ -7,7 +7,7 @@ import FNote, { NotePathRecord } from "../../entities/fnote";
import { t } from "../../services/i18n";
import note_create from "../../services/note_create";
import server from "../../services/server";
-import { BacklinksList, useBacklinkCount } from "../FloatingButtonsDefinitions";
+import { BacklinksWidget, useBacklinkCount } from "../FloatingButtonsDefinitions";
import { getLocaleName, NoteInfoContent } from "../layout/StatusBar";
import ActionButton from "../react/ActionButton";
import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../react/FormList";
@@ -153,15 +153,13 @@ interface WithModal {
function BacklinksModal({ note, modalShown, setModalShown }: { note: FNote | null | undefined } & WithModal) {
return (
<Modal
- className="backlinks-modal tn-backlinks-widget"
+ className="backlinks-modal"
size="md"
title={t("mobile_detail_menu.backlinks")}
show={modalShown}
onHidden={() => setModalShown(false)}
>
- <ul className="backlinks-items">
- {note && <BacklinksList note={note} />}
- </ul>
+ {note && <BacklinksWidget note={note} />}
</Modal>
);
}
diff --git a/apps/client/src/widgets/ribbon/NotePathsTab.tsx b/apps/client/src/widgets/ribbon/NotePathsTab.tsx
index 9573790cb9..6486fca977 100644
--- a/apps/client/src/widgets/ribbon/NotePathsTab.tsx
+++ b/apps/client/src/widgets/ribbon/NotePathsTab.tsx
@@ -28,10 +28,11 @@ export function NotePathsWidget({ sortedNotePaths, currentNotePath, cloneButton
cloneButton?: boolean;
}) {
const parentComponent = useContext(ParentComponent);
- // What holds the list in the new layout — the sidebar's card, the mobile note menu's modal — is
- // titled for 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.
+ // 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");
diff --git a/apps/client/src/widgets/sidebar/Backlinks.tsx b/apps/client/src/widgets/sidebar/Backlinks.tsx
index 73d01c3d44..2cbd51abc9 100644
--- a/apps/client/src/widgets/sidebar/Backlinks.tsx
+++ b/apps/client/src/widgets/sidebar/Backlinks.tsx
@@ -1,7 +1,7 @@
import { t } from "../../services/i18n";
-// The list itself is shared with the floating backlinks button and the mobile menu; only the framing
-// differs here. The status bar's badge has no list of its own — it opens this one.
-import { BacklinksList } from "../FloatingButtonsDefinitions";
+// The list itself is shared with the floating backlinks button, the status bar's badge and the mobile
+// menu; only the framing differs here.
+import { BacklinksWidget } from "../FloatingButtonsDefinitions";
import { useActiveNoteContext } from "../react/hooks";
import RightPanelWidget from "./RightPanelWidget";
import SidebarHelp from "./SidebarHelp";
@@ -16,14 +16,7 @@ export default function Backlinks() {
buttons={<SidebarHelp section="backlinks" />}
grow
>
- {note && (
- // The classes the shared list's card styling hangs off (see ../Backlinks.css).
- <div class="tn-backlinks-widget">
- <ul class="backlinks-items">
- <BacklinksList note={note} />
- </ul>
- </div>
- )}
+ {note && <BacklinksWidget note={note} />}
</RightPanelWidget>
);
}
diff --git a/apps/client/src/widgets/sidebar/NotePaths.tsx b/apps/client/src/widgets/sidebar/NotePaths.tsx
index 4493210fa0..32b0c885f0 100644
--- a/apps/client/src/widgets/sidebar/NotePaths.tsx
+++ b/apps/client/src/widgets/sidebar/NotePaths.tsx
@@ -6,8 +6,8 @@ import { t } from "../../services/i18n";
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; only the framing differs here. The status
-// bar's badge has no list of its own — it opens this one.
+// 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 RightPanelWidget from "./RightPanelWidget";
import SidebarHelp from "./SidebarHelp";
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
index 08fcc49bbe..71571fd932 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
@@ -75,7 +75,7 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
useTriliumEvent("toggleRightPane", toggleDocked);
useTriliumEvent("peekRightPane", togglePeek);
- // An entry point aimed at one tab (the chat launcher, the status bar's connection badges): it opens
+ // An entry point aimed at one tab (the chat launcher, the status bar's similar notes link): it opens
// the pane on that tab, brings it to the front if the pane is already open on another one, and puts
// it away again when it is the tab on show — see reduceTabSelection for what that amounts to.
// `peek` opens it as a glance instead of a dock; `expandWidgetId` opens the one widget the entry
@@ -113,11 +113,8 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
// Outside-press / Esc *soft*-dismisses the peek: it hides but stays mounted, so re-peeking is
// instant and preserves widget state. The × button and the docked toggle hard-close (unmount).
- // A `right-pane-peek-source` control (the status bar's connection badges) peeks the pane itself
- // (see selectRightPaneTab above), so dismissing on its press would only close the pane for the
- // click that follows to reopen it.
usePeekDismiss(mode === "peek", dismiss, {
- keepOpenSelector: "#right-pane, .right-pane-peek-button, .right-pane-peek-source",
+ keepOpenSelector: "#right-pane, .right-pane-peek-button",
focusSelector: ".right-pane-peek-button"
});
diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
index 0856b197b4..ba1eb29f9f 100644
--- a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
@@ -15,7 +15,7 @@ export const CollapsibleWidgets = createContext(true);
/**
* A request to expand one widget of the pane, raised by an entry point aimed at it (the status bar's
- * note paths badge) so that it doesn't land on a widget the user has collapsed. The counter tells
+ * similar notes link) so that it doesn't land on a widget the user has collapsed. The counter tells
* repeated requests apart, so the widget opens again after having been collapsed in between.
*/
export interface ExpandWidgetRequest {