Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(client): give each sidebar card a ? that answers in place
Elian Doran7457869be160
diff --git a/apps/client/src/services/in_app_help.ts b/apps/client/src/services/in_app_help.tsindex 658c4f9260..a77cb1aabf 100644--- a/apps/client/src/services/in_app_help.ts+++ b/apps/client/src/services/in_app_help.ts@@ -34,6 +34,48 @@ export const byBookType: Record<ViewTypeOptions, string | null> = {dashboard: "IF7Q6I9x7zuw"};+/** What one card of the right sidebar offers when its `?` is pressed. */+export interface SidebarSectionHelp {+ /** In-app help note the "Open help page" link at the foot of the popup goes to. */+ helpPage: string;+ /** Translation keys of the explanation shown in place, a paragraph each. */+ paragraphs: string[];+}++/**+ * The help each card of the right sidebar carries, keyed by the card's widget id: a section gains a+ * `?` in its header by being named here and rendering a `SidebarHelp` beside its other buttons.+ *+ * The help belongs to the card rather than to the pane or the tab, because the cards answer unrelated+ * questions — what is drawn on the map, why a note has two paths, what counts as a backlink — and each+ * has an in-app help page of its own. A single `?` beside the pane's close button would have to stand+ * for whichever tab happens to be on show, and then pick one of those pages out of several.+ */+export const bySidebarSection = {+ noteMap: {+ // Note Map (Link map, Tree map).+ helpPage: "BCkXAVs63Ttv",+ paragraphs: [ "sidebar_help.note_map_what", "sidebar_help.note_map_interaction" ]+ },+ notePaths: {+ // Cloning Notes, which is what a second path amounts to.+ helpPage: "IakOLONlIfGI",+ paragraphs: [ "sidebar_help.note_paths_what", "sidebar_help.note_paths_cloning" ]+ },+ backlinks: {+ // Links, covering both kinds a backlink can come from.+ helpPage: "QEAPj01N5f7w",+ paragraphs: [ "sidebar_help.backlinks_what", "sidebar_help.backlinks_listing" ]+ },+ similarNotes: {+ // Similar Notes.+ helpPage: "xWtq5NUHOwql",+ paragraphs: [ "sidebar_help.similar_notes_what", "sidebar_help.similar_notes_how" ]+ }+} satisfies Record<string, SidebarSectionHelp>;++export type SidebarSectionId = keyof typeof bySidebarSection;+export function getHelpUrlForNote(note: FNote | null | undefined) {if (note?.isMarkdown()) {return "6RM1Q7ppFVoj";diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 717d8816e1..630d70e909 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1310,6 +1310,7 @@},"note_map": {"open_full": "Expand to full",+ "expand": "Expand map","collapse": "Collapse to normal size","title": "Note Map","fix-nodes": "Fix nodes",@@ -1387,6 +1388,16 @@"title": "Similar Notes","no_similar_notes_found": "No similar notes found."},+ "sidebar_help": {+ "note_map_what": "A map of what this note connects to. The link map draws the internal links and relations going in and out of it; the tree map draws where it sits in the note tree. The switcher in this header chooses between the two.",+ "note_map_interaction": "Hovering a note brings its own connections forward and fades the rest. The expand button opens the same map at the size of the window.",+ "note_paths_what": "A note can sit in more than one place in the note tree at once, and each of those places is listed here as a path.",+ "note_paths_cloning": "Adding a place is called cloning: nothing is copied, so an edit made under one path shows under all of them, and removing one path leaves the note under the others.",+ "backlinks_what": "The notes pointing at this one, either through a link in their text or through a relation naming it.",+ "backlinks_listing": "A text link is listed with the passage around it, a relation with the name it points by. This side of a link is not editable: it goes away when the note that made it drops the link.",+ "similar_notes_what": "Notes that look related to this one even where nothing links them.",+ "similar_notes_how": "The likeness is worked out from the content of the notes, the attributes and relations they carry, and how close together they were created."+ },"abstract_search_option": {"remove_this_search_option": "Remove this search option","failed_rendering": "Failed rendering search option: {{dto}} with error: {{error}} {{stack}}"diff --git a/apps/client/src/widgets/sidebar/Backlinks.tsx b/apps/client/src/widgets/sidebar/Backlinks.tsxindex 574d5decda..73d01c3d44 100644--- a/apps/client/src/widgets/sidebar/Backlinks.tsx+++ b/apps/client/src/widgets/sidebar/Backlinks.tsx@@ -4,12 +4,18 @@ import { t } from "../../services/i18n";import { BacklinksList } from "../FloatingButtonsDefinitions";import { useActiveNoteContext } from "../react/hooks";import RightPanelWidget from "./RightPanelWidget";+import SidebarHelp from "./SidebarHelp";export default function Backlinks() {const { note } = useActiveNoteContext();return (- <RightPanelWidget id="backlinks" title={t("right_pane.backlinks")} grow>+ <RightPanelWidget+ id="backlinks"+ title={t("right_pane.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">diff --git a/apps/client/src/widgets/sidebar/NoteMap.tsx b/apps/client/src/widgets/sidebar/NoteMap.tsxindex 26576165c9..2e2ad4d5f4 100644--- a/apps/client/src/widgets/sidebar/NoteMap.tsx+++ b/apps/client/src/widgets/sidebar/NoteMap.tsx@@ -2,12 +2,15 @@// wanted before it has finished loading, so they cannot wait for that module to arrive.import "./NoteMap.css";+import appContext from "../../components/app_context";import { t } from "../../services/i18n";import MapTypeSwitcher from "../note_map/MapTypeSwitcher";import { toMapType } from "../note_map/utils";+import ActionButton from "../react/ActionButton";import { useActiveNoteContext, useNoteLabel } from "../react/hooks";import LazyComponent from "../react/LazyComponent";import RightPanelWidget from "./RightPanelWidget";+import SidebarHelp from "./SidebarHelp";/*** The card is rendered here and the map itself loaded on demand from within it, rather than the whole@@ -21,14 +24,32 @@ import RightPanelWidget from "./RightPanelWidget";* The map reads the same label, so the two stay of one mind without being told.*/export default function NoteMap() {- const { note } = useActiveNoteContext();+ const { note, notePath } = useActiveNoteContext();const [ mapTypeLabel, setMapType ] = useNoteLabel(note, "mapType");return (<RightPanelWidgetid="noteMap"title={t("note_map.title")}- buttons={<MapTypeSwitcher mapType={toMapType(mapTypeLabel)} setMapType={setMapType} />}+ buttons={<>+ <SidebarHelp section="noteMap" />+ <MapTypeSwitcher mapType={toMapType(mapTypeLabel)} setMapType={setMapType} />+ {/* One rung of the same ladder the quick-edit popup already offers: a press here takes the+ map from a card to the greater part of the window, and the popup's own expand takes it+ on to a tab. The popup rather than a split, because a map that sits beside the note+ being read looks as though it follows it and doesn't; a glance that goes away when it+ has sent the reader somewhere makes no such promise. */}+ {notePath && (+ <ActionButton+ icon="bx bx-expand-alt"+ text={t("note_map.expand")}+ onClick={() => void appContext.triggerCommand("openInPopup", {+ noteIdOrPath: notePath,+ viewScope: { viewMode: "note-map" }+ })}+ />+ )}+ </>}noPadding><LazyComponent loader={() => import("./NoteMapGraph.jsx")} />diff --git a/apps/client/src/widgets/sidebar/NotePaths.tsx b/apps/client/src/widgets/sidebar/NotePaths.tsxindex 8c1a85a340..4493210fa0 100644--- a/apps/client/src/widgets/sidebar/NotePaths.tsx+++ b/apps/client/src/widgets/sidebar/NotePaths.tsx@@ -10,6 +10,7 @@ import { ParentComponent } from "../react/react_utils";// bar's badge has no list of its own — it opens this one.import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";import RightPanelWidget from "./RightPanelWidget";+import SidebarHelp from "./SidebarHelp";export default function NotePaths() {const { note, notePath, hoistedNoteId } = useActiveNoteContext();@@ -23,13 +24,14 @@ export default function NotePaths() {// Cloning the note is what one does about its paths, so it sits where the card keeps what// one does — its header — rather than as a line of its own below the list. The icon is the// tree context menu's for the same action.- buttons={+ buttons={<>+ <SidebarHelp section="notePaths" /><ActionButtonicon="bx bx-duplicate"text={t("note_paths.clone_button")}onClick={() => void parentComponent?.triggerCommand("cloneNoteIdsTo")}/>- }+ </>}><NotePathsWidget sortedNotePaths={sortedNotePaths} currentNotePath={notePath} cloneButton={false} /></RightPanelWidget>diff --git a/apps/client/src/widgets/sidebar/SidebarHelp.css b/apps/client/src/widgets/sidebar/SidebarHelp.cssnew file mode 100644index 0000000000..ad77b7c561--- /dev/null+++ b/apps/client/src/widgets/sidebar/SidebarHelp.css@@ -0,0 +1,7 @@+.sidebar-help p {+ margin: 0;++ &:not(:last-child) {+ margin-bottom: 8px;+ }+}diff --git a/apps/client/src/widgets/sidebar/SidebarHelp.tsx b/apps/client/src/widgets/sidebar/SidebarHelp.tsxnew file mode 100644index 0000000000..50840784f2--- /dev/null+++ b/apps/client/src/widgets/sidebar/SidebarHelp.tsx@@ -0,0 +1,32 @@+import "./SidebarHelp.css";++import { t } from "../../services/i18n";+import { bySidebarSection, SidebarSectionId } from "../../services/in_app_help";+import HelpDropdown from "../react/HelpDropdown";++/**+ * The `?` of one card of the right sidebar: the short answer given in place, with a link on to the+ * in-app help page the section belongs to. What it says of each section is kept with the rest of the+ * in-app help pointers, in {@link bySidebarSection}.+ *+ * Goes in the card's `buttons`, ahead of whatever else the header holds — so it sits in the same place+ * from one card to the next, the way the attributes card already has it.+ *+ * A dropdown rather than a plain `HelpButton`: the questions a sidebar card raises are short-answer+ * ones, and sending the reader of a glance-sized pane off into a help page over the note they were+ * reading is a long way round for a sentence. The full page is still a press away at the foot of the+ * popup.+ */+export default function SidebarHelp({ section }: { section: SidebarSectionId }) {+ const { helpPage, paragraphs } = bySidebarSection[section];++ return (+ <HelpDropdown helpPage={helpPage}>+ {/* The popup is portalled to the body, so the styling has to hang off a class within it+ rather than off the dropdown's own. */}+ <div class="sidebar-help">+ {paragraphs.map((key) => <p key={key}>{t(key)}</p>)}+ </div>+ </HelpDropdown>+ );+}diff --git a/apps/client/src/widgets/sidebar/SimilarNotes.tsx b/apps/client/src/widgets/sidebar/SimilarNotes.tsxindex 7c3740a20b..e8d7c113ef 100644--- a/apps/client/src/widgets/sidebar/SimilarNotes.tsx+++ b/apps/client/src/widgets/sidebar/SimilarNotes.tsx@@ -6,12 +6,17 @@ import { useActiveNoteContext } from "../react/hooks";// framing differs here. The status bar has no panel of its own for them — it opens this one.import SimilarNotesTab from "../ribbon/SimilarNotesTab";import RightPanelWidget from "./RightPanelWidget";+import SidebarHelp from "./SidebarHelp";export default function SimilarNotes() {const { note } = useActiveNoteContext();return (- <RightPanelWidget id="similarNotes" title={t("similar_notes.title")}>+ <RightPanelWidget+ id="similarNotes"+ title={t("similar_notes.title")}+ buttons={<SidebarHelp section="similarNotes" />}+ >{note && <SimilarNotesTab note={note} />}</RightPanelWidget>);