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
refactor(client): give a link to another page a component of its own
Elian Doranec6c5a76b3f2
diff --git a/.claude/skills/building-client-ui/SKILL.md b/.claude/skills/building-client-ui/SKILL.mdindex 2fb18b5f1c..c17706151b 100644--- a/.claude/skills/building-client-ui/SKILL.md+++ b/.claude/skills/building-client-ui/SKILL.md@@ -1,11 +1,11 @@---name: building-client-ui-description: Use when building or changing any UI in the Trilium client (`apps/client`) — a dialog, a settings pane, a form, a toolbar, a badge, a dropdown menu, a type widget, a control floating over a note's content (map, mind map, image, diagram, presentation), or any component that reads/writes a note's title, label, relation, blob or option. Catalogues the froca-reactive hooks (useNoteProperty / useNoteLabel / useNoteBlob / useChildNotes / useTriliumOption / useNoteContext) and which `loadResults` filter each already wires, the reusable Preact components under `apps/client/src/widgets/react/` (which one to reach for instead of a hand-rolled `<input>`/`<button>`/pill), the `Dropdown` backdrop-blur rules (`noDropdownListStyle` / `portalToBody`), the `OverlayControlGroup` / `OverlayToolbar` contract for controls over a canvas, the event-summoned Modal/LazyDialog wiring, and how to boot a login-free fixture instance to inspect real computed styles when a style, placement or stacking bug cannot be read off the stylesheets. The home for client UI guidance that outgrows CLAUDE.md.+description: Use when building or changing any UI in the Trilium client (`apps/client`) — a dialog, a settings pane, a form, a toolbar, a badge, a link, a dropdown menu, a type widget, a control floating over a note's content (map, mind map, image, diagram, presentation), or any component that reads/writes a note's title, label, relation, blob or option. Catalogues the froca-reactive hooks (useNoteProperty / useNoteLabel / useNoteBlob / useChildNotes / useTriliumOption / useNoteContext) and which `loadResults` filter each already wires, the reusable Preact components under `apps/client/src/widgets/react/` (which one to reach for instead of a hand-rolled `<input>`/`<button>`/`<a>`/pill), the `Dropdown` backdrop-blur rules (`noDropdownListStyle` / `portalToBody`), the `OverlayControlGroup` / `OverlayToolbar` contract for controls over a canvas, the event-summoned Modal/LazyDialog wiring, and how to boot a login-free fixture instance to inspect real computed styles when a style, placement or stacking bug cannot be read off the stylesheets. The home for client UI guidance that outgrows CLAUDE.md.---# Building client UI-The client is a Preact app (legacy widgets are jQuery `BasicWidget`s; new UI is Preact). Shared components live in `apps/client/src/widgets/react/`. **Always reuse them instead of writing raw HTML elements or a custom implementation** — every hand-rolled `<input>`, `<select>`, `<button>`, pill or overlay button is a second copy of styling, focus handling and accessibility that drifts.+The client is a Preact app (legacy widgets are jQuery `BasicWidget`s; new UI is Preact). Shared components live in `apps/client/src/widgets/react/`. **Always reuse them instead of writing raw HTML elements or a custom implementation** — every hand-rolled `<input>`, `<select>`, `<button>`, `<a>`, pill or overlay button is a second copy of styling, focus handling and accessibility that drifts.The general styling rules (no inline styles, one `.css` file per component imported at the top, scope by root class + native CSS nesting) are in the repo `CLAUDE.md`; this skill is about *which component* and *how to drive it*.@@ -68,10 +68,23 @@ Form controls:Buttons and links:-- `Button` — the general button (also carries the tooltip for a *disabled* control via a wrapper, since a disabled `<button>` emits no pointer events). `ActionButton` — icon button with consistent styling; `LinkButton` — a link that acts as a button.+- `Button` — the general button (also carries the tooltip for a *disabled* control via a wrapper, since a disabled `<button>` emits no pointer events). `ActionButton` — icon button with consistent styling.- `HelpButton`, `HelpTooltipButton`, `HelpDropdown` — open in-app help pages; don't invent a new "?" affordance.- `KeyboardShortcut` — renders a shortcut as keycaps.+**Never hand-roll `<a className="tn-link">`.** Which link component to reach for depends on what the link *is*:++| What the link does | Component |+| --- | --- |+| Runs an action, worded as a link rather than a button | `LinkButton` (`href="#"`, `onClick` or `triggerCommand`; already `role="button"` and Space-activated) |+| Goes to a note path with wording of your own — a summary sentence, "see the backup page" | `PageLink` (in `LinkButton.tsx`; suppresses the note preview, since text that already says what is there gains nothing from one) |+| Goes to a note, named by the note's own title | `NoteLink` (icon, color class, note path, hover preview) or `NewNoteLink` for the Preact-native variant |+| Opens a filesystem location in the OS file manager | `DirectoryLink` / `FileLink` (degrade to plain selectable text off Electron) |++A raw `<a>` is right only for an **external** URL, which no component covers: write it as `<a className="tn-link external" target="_blank" rel="noopener noreferrer">` (the theme appends the ↗ arrow from the `external` class or an `http(s)` href; `no-arrow` opts out). For a block of prose whose links come from elsewhere — rendered note content, a help page — put `use-tn-links` on the container instead of classing each anchor.++`no-tooltip-preview` is the class that keeps the note-hover preview away from a link into the note tree; `PageLink` and `NoteLink`'s `noPreview` set it for you, so it should rarely be written by hand.+Display and layout:- `NoItems` — empty state placeholder with icon and message ("no results", "too many items", error states).@@ -81,7 +94,7 @@ Display and layout:- `Card` — a titled group of sections (filter-aware under `FilterProvider`). `Collapsible` — animated, theme-styled expandable section with self-managed `initiallyExpanded`; `ExternallyControlledCollapsible` is the controlled variant (caller owns `expanded`/`setExpanded`).- `TabStrip` — a row of icon-only tabs named by tooltips, heading a panel divided into groups.- `Modal`, `WizardModal` — dialogs; `Popover` — a small surface anchored beside something (portaled to the body, so no scroll container clips it).-- `LoadingSpinner`, `LazyComponent`, `Icon`, `MaskedIcon`, `NoteLink`, `NoteList`, `SiblingNavigator`, `ImageViewer`, `CodeBlock`, `charts/DonutChart`, `charts/Treemap`.+- `LoadingSpinner`, `LazyComponent`, `Icon`, `MaskedIcon`, `NoteList`, `SiblingNavigator`, `ImageViewer`, `CodeBlock`, `charts/DonutChart`, `charts/Treemap`.Data grids and calendars (outside `widgets/react/`, but equally generic):diff --git a/apps/client/src/widgets/react/LinkButton.tsx b/apps/client/src/widgets/react/LinkButton.tsxindex 81b33280af..e9feefacc6 100644--- a/apps/client/src/widgets/react/LinkButton.tsx+++ b/apps/client/src/widgets/react/LinkButton.tsx@@ -24,4 +24,20 @@ export default function LinkButton({ onClick, text, triggerCommand }: LinkButton{text}</a>)-}\ No newline at end of file+}++interface PageLinkProps {+ /** Where the link goes, as a note path such as `#root/_hidden/_options/_optionsBackup`. */+ href: string;+ /** The words the link is read as. */+ text: ComponentChild;+}++/**+ * A way to another page of the application, worded as what is found there rather than as the title+ * of the page it goes to. That wording is also why the note preview is left out: the text has+ * already said what the page holds, so the preview would only repeat it in less readable form.+ */+export function PageLink({ href, text }: PageLinkProps) {+ return <a className="tn-link no-tooltip-preview" href={href}>{text}</a>;+}diff --git a/apps/client/src/widgets/type_widgets/options/database.spec.tsx b/apps/client/src/widgets/type_widgets/options/database.spec.tsxindex a957496978..a0fdefc4d2 100644--- a/apps/client/src/widgets/type_widgets/options/database.spec.tsx+++ b/apps/client/src/widgets/type_widgets/options/database.spec.tsx@@ -222,7 +222,12 @@ describe("what the database is", () => {renderPage();await settle();- expect(container.querySelector(".database-info a[href]")?.textContent).toBe("database.info_no_backup");+ const link = container.querySelector(".database-info a[href]");+ expect(link?.textContent).toBe("database.info_no_backup");+ // The row is the way to the backup page, and says on its own what is there: a preview of a+ // page of settings would tell the reader nothing.+ expect(link?.getAttribute("href")).toBe("#root/_hidden/_options/_optionsBackup");+ expect(link?.classList.contains("no-tooltip-preview")).toBe(true);});it("reads the figures again once the database has been compacted", async () => {diff --git a/apps/client/src/widgets/type_widgets/options/database.tsx b/apps/client/src/widgets/type_widgets/options/database.tsxindex 4f82133957..4e3bb9f661 100644--- a/apps/client/src/widgets/type_widgets/options/database.tsx+++ b/apps/client/src/widgets/type_widgets/options/database.tsx@@ -31,6 +31,7 @@ import Admonition from "../../react/Admonition";import Button from "../../react/Button";import { Card, OptionCardSection } from "../../react/Card";import DirectoryLink, { FileLink } from "../../react/DirectoryLink";+import { PageLink } from "../../react/LinkButton";import { useFetch } from "../../react/use_fetch";import { showCleanupDialog } from "../space_usage/cleanup_dialog";import DatabaseFileList from "./components/DatabaseFileList";@@ -161,9 +162,10 @@ function BackupStanding({ refreshToken }: { refreshToken: number }) {{/* The whole value is the way to the page that acts on it: this row states how thebackups stand, and everything else about them is done there. */}<span className="tn-card-option-value">- <a className="tn-link no-tooltip-preview" href={BACKUP_PAGE_LINK}>- {summarizeBackups(backups.backups) ?? t("database.info_no_backup")}- </a>+ <PageLink+ href={BACKUP_PAGE_LINK}+ text={summarizeBackups(backups.backups) ?? t("database.info_no_backup")}+ /></span></OptionCardSection>);