Skip to content

Build your personal knowledge base with Trilium Notes

refactor(attributes): replace the editor help tooltip with a ? button

Elian Dorana1105fb93795
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 40438121ee..5bb5b8b5c1 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2245,6 +2245,7 @@
"title": "Full width"
},
"open-help-page": "Open help page",
+ "show-help": "Show help",
"find": {
"case_sensitive": "Case sensitive",
"match_words": "Match words",
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index 9659eb4ca6..9a5ab530d1 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -20,6 +20,7 @@ import { formatDateTime } from "../../utils/formatters";
import { BacklinksList, useBacklinkCount } from "../FloatingButtonsDefinitions";
import Dropdown, { DropdownProps } from "../react/Dropdown";
import { FormDropdownDivider, FormListHeader, FormListItem } from "../react/FormList";
+import HelpDropdown from "../react/HelpDropdown";
import { useActiveNoteContext, useLegacyImperativeHandlers, useNoteLabel, useNoteLabelInt, useNoteLabelOptionalBool, useNoteProperty, useStaticTooltip, useTriliumEvent, useTriliumEvents, useTriliumOptionBool, useTriliumOptionInt } from "../react/hooks";
import Icon from "../react/Icon";
import LinkButton from "../react/LinkButton";
@@ -27,6 +28,7 @@ import { ParentComponent } from "../react/react_utils";
import AutoLinkAttributesTab from "../ribbon/AutoLinkAttributesTab";
import { ContentLanguagesModal, NoteTypeCodeNoteList, NoteTypeOptionsModal, useLanguageSwitcher, useMimeTypes } from "../ribbon/BasicPropertiesTab";
import AttributeEditor, { AttributeEditorImperativeHandlers } from "../ribbon/components/AttributeEditor";
+import AttributeHelp, { ATTRIBUTE_HELP_PAGE } from "../ribbon/components/AttributeHelp";
import InheritedAttributesTab from "../ribbon/InheritedAttributesTab";
import { NoteSizeWidget, useNoteMetadata } from "../ribbon/NoteInfoTab";
import { NotePathsWidget, useSortedNotePaths } from "../ribbon/NotePathsTab";
@@ -408,7 +410,8 @@ function AttributesPane({ note, noteContext, attributesShown, setAttributesShown
className="attribute-list"
visible={attributesShown}
setVisible={setAttributesShown}
- helpPage="zEY4DaJG4YT5">
+ helpPage={ATTRIBUTE_HELP_PAGE}
+ helpContent={<AttributeHelp />}>
<span class="attributes-panel-label">{t("inherited_attribute_list.title")}</span>
<InheritedAttributesTab {...context} emptyListString="inherited_attribute_list.none" />
@@ -422,6 +425,8 @@ function AttributesPane({ note, noteContext, attributesShown, setAttributesShown
{...context}
api={api}
ntxId={noteContext.ntxId}
+ // The panel's title bar already carries the same help.
+ hideHelpButton
/>}
</BottomPanel>
);
@@ -595,13 +600,17 @@ interface BottomPanelParams {
setVisible?: (visible: boolean) => void;
className?: string;
helpPage?: string;
+ /** Inline help shown by the title bar's `?`; without it the `?` opens {@link helpPage} directly. */
+ helpContent?: ComponentChildren;
}
-function BottomPanel({ children, title, visible, setVisible, className, helpPage }: BottomPanelParams) {
+function BottomPanel({ children, title, visible, setVisible, className, helpPage, helpContent }: BottomPanelParams) {
return <div className={clsx("bottom-panel", className, {"hidden-ext": !visible})}>
<div className="bottom-panel-title-bar">
<span className="bottom-panel-title-bar-caption">{title}</span>
- {helpPage && <button class="icon-action bx bx-question-mark" onClick={() => openInAppHelpFromUrl(helpPage)} title={t("open-help-page")} />}
+ {helpContent
+ ? <HelpDropdown helpPage={helpPage}>{helpContent}</HelpDropdown>
+ : helpPage && <button class="icon-action bx bx-question-mark" onClick={() => openInAppHelpFromUrl(helpPage)} title={t("open-help-page")} />}
<button class="icon-action bx bx-x" onClick={() => setVisible?.(false)} />
</div>
<div class={clsx("bottom-panel-content")}>
diff --git a/apps/client/src/widgets/react/HelpDropdown.css b/apps/client/src/widgets/react/HelpDropdown.css
new file mode 100644
index 0000000000..1ad8a23d18
--- /dev/null
+++ b/apps/client/src/widgets/react/HelpDropdown.css
@@ -0,0 +1,25 @@
+.dropdown.help-dropdown {
+ display: inline-flex;
+}
+
+.dropdown-menu.help-dropdown-content {
+ /* Dropdowns sit at 999, just under the popups anchored to the same widgets (e.g. the attribute
+ detail at 1000). Help is always an explicit, transient request, so it has to win over
+ whatever it was opened on top of. */
+ --bs-dropdown-zindex: 1001;
+
+ max-width: 340px;
+ padding: 12px;
+ white-space: normal;
+ font-size: var(--main-font-size);
+ line-height: 1.5;
+
+ code {
+ white-space: nowrap;
+ }
+
+ .tn-link {
+ display: inline-block;
+ margin-top: 10px;
+ }
+}
diff --git a/apps/client/src/widgets/react/HelpDropdown.tsx b/apps/client/src/widgets/react/HelpDropdown.tsx
new file mode 100644
index 0000000000..3e0e453551
--- /dev/null
+++ b/apps/client/src/widgets/react/HelpDropdown.tsx
@@ -0,0 +1,55 @@
+import "./HelpDropdown.css";
+
+import { ComponentChildren } from "preact";
+
+import { t } from "../../services/i18n";
+import { openInAppHelpFromUrl } from "../../services/utils";
+import Dropdown from "./Dropdown";
+import LinkButton from "./LinkButton";
+
+interface HelpDropdownProps {
+ /** The help content itself, rendered inside the popup. */
+ children: ComponentChildren;
+ /** In-app help note ID; when set, a link to the full help page is appended below the content. */
+ helpPage?: string;
+ className?: string;
+ /** Called as the popup opens, for hosts that need to dismiss their own popups first. */
+ onShown?: () => void;
+}
+
+/**
+ * A `?` icon button revealing a popup with inline help, optionally linking to the full help page.
+ *
+ * Prefer this over {@link HelpButton} when there is a short explanation worth showing in place, and
+ * over a Bootstrap tooltip whenever the help is more than a few words: the popup is dismissed
+ * explicitly (click outside or <kbd>Escape</kbd>) instead of on blur, so its content stays readable
+ * and selectable.
+ */
+export default function HelpDropdown({ children, helpPage, className, onShown }: HelpDropdownProps) {
+ return (
+ <Dropdown
+ onShown={onShown}
+ className={`help-dropdown ${className ?? ""}`}
+ buttonClassName="bx bx-question-mark"
+ dropdownContainerClassName="help-dropdown-content"
+ title={t("show-help")}
+ iconAction
+ hideToggleArrow
+ noSelectButtonStyle
+ noDropdownListStyle
+ // Hosts like the ribbon establish their own stacking context (`.ribbon-container` sits at
+ // z-index 998), which would clamp the popup below the body-level widgets it overlaps —
+ // e.g. the attribute detail at 1000. Rendering into the body lets its z-index actually apply.
+ portalToBody
+ >
+ {children}
+
+ {helpPage && (
+ <LinkButton
+ text={t("open-help-page")}
+ onClick={() => void openInAppHelpFromUrl(helpPage)}
+ />
+ )}
+ </Dropdown>
+ );
+}
diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.css b/apps/client/src/widgets/ribbon/components/AttributeEditor.css
index 617f2349cb..30445552b4 100644
--- a/apps/client/src/widgets/ribbon/components/AttributeEditor.css
+++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.css
@@ -15,7 +15,7 @@
border: 0 !important;
outline: 0 !important;
box-shadow: none !important;
- padding: 0 100px 0 5px !important;
+ padding: 0 140px 0 5px !important;
margin: 0 !important;
max-height: 100px;
overflow: auto;
@@ -23,7 +23,7 @@
}
body[dir=rtl] .attribute-list-editor {
- padding: 0 5px 0 100px !important;
+ padding: 0 5px 0 140px !important;
text-align: right !important;
}
@@ -48,5 +48,5 @@ body[dir=rtl] .attribute-list-editor {
.attribute-errors {
color: red;
- padding: 5px 100px 0px 5px; /* large right padding to avoid buttons */
+ padding: 5px 140px 0px 5px; /* large right padding to avoid buttons */
}
diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx
index 355ec9ec2b..601ec14934 100644
--- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx
+++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx
@@ -2,7 +2,6 @@ import "./AttributeEditor.css";
import type { AttributeEditor as CKEditorAttributeEditor, MentionFeed, ModelElement, ModelNode, ModelPosition } from "@triliumnext/ckeditor5";
import { AttributeType } from "@triliumnext/commons";
-import type { Tooltip } from "bootstrap";
import { createPortal } from "preact/compat";
import { MutableRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "preact/hooks";
@@ -24,15 +23,12 @@ import { escapeQuotes, getErrorMessage } from "../../../services/utils";
import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";
import ActionButton from "../../react/ActionButton";
import CKEditor, { CKEditorApi } from "../../react/CKEditor";
-import { useLegacyImperativeHandlers, useLegacyWidget, useTooltip, useTriliumEvent, useTriliumOption } from "../../react/hooks";
+import HelpDropdown from "../../react/HelpDropdown";
+import { useLegacyImperativeHandlers, useLegacyWidget, useTriliumEvent } from "../../react/hooks";
+import AttributeHelp, { ATTRIBUTE_HELP_PAGE } from "./AttributeHelp";
type AttributeCommandNames = FilteredCommandNames<CommandData>;
-const HELP_TEXT = `
-<p>${t("attribute_editor.help_text_body1")}</p>
-<p>${t("attribute_editor.help_text_body2")}</p>
-<p>${t("attribute_editor.help_text_body3")}</p>`;
-
const mentionSetup: MentionFeed[] = [
{
marker: "@",
@@ -85,6 +81,11 @@ interface AttributeEditorProps {
notePath?: string | null;
ntxId?: string | null;
hidden?: boolean;
+ /**
+ * Suppresses the editor's own `?` button, for hosts that already offer the same help elsewhere
+ * (the new layout's attributes panel carries it in its title bar).
+ */
+ hideHelpButton?: boolean;
}
export interface AttributeEditorImperativeHandlers {
@@ -94,9 +95,8 @@ export interface AttributeEditorImperativeHandlers {
renderOwnedAttributes(ownedAttributes: FAttribute[]): Promise<void>;
}
-export default function AttributeEditor({ api, note, componentId, notePath, ntxId, hidden }: AttributeEditorProps) {
+export default function AttributeEditor({ api, note, componentId, notePath, ntxId, hidden, hideHelpButton }: AttributeEditorProps) {
const [ currentValue, setCurrentValue ] = useState("");
- const [ state, setState ] = useState<"normal" | "showHelpTooltip" | "showAttributeDetail">();
const [ error, setError ] = useState<unknown>();
const [ needsSaving, setNeedsSaving ] = useState(false);
const [isMenuOpen, setIsMenuOpen] = useState(false);
@@ -106,7 +106,6 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
const currentValueRef = useRef(currentValue);
const wrapperRef = useRef<HTMLDivElement>(null);
const editorRef = useRef<CKEditorApi>();
- const [ locale ] = useTriliumOption("locale");
// The CKEditor bundle is heavy and this component mounts in always-visible containers
// (e.g. the status bar), so the editor class is loaded on demand to keep CKEditor out
@@ -125,30 +124,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
};
}, []);
- // Stable config so `useTooltip`'s effect doesn't dispose/recreate the tooltip
- // on every render (it runs on each keystroke). `focus` shows the help when the
- // editor is focused; `state` below force-hides it when the attribute-detail
- // popup takes over.
- const tooltipConfig = useMemo<Partial<Tooltip.Options>>(() => ({
- trigger: "focus",
- html: true,
- title: HELP_TEXT,
- placement: "bottom",
- offset: "0,30"
- }), []);
-
- const { showTooltip, hideTooltip } = useTooltip(wrapperRef, tooltipConfig);
-
const [ attributeDetailWidgetEl, attributeDetailWidget ] = useLegacyWidget(() => new AttributeDetailWidget());
- useEffect(() => {
- if (state === "showHelpTooltip") {
- showTooltip();
- } else {
- hideTooltip();
- }
- }, [ state ]);
-
async function renderOwnedAttributes(ownedAttributes: FAttribute[], saved: boolean) {
// attrs are not resorted if position changes after the initial load
ownedAttributes.sort((a, b) => a.position - b.position);
@@ -377,16 +354,13 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
y: e.pageY,
parent: wrapperRef.current ?? undefined
});
- setState("showAttributeDetail");
} else {
// Presses inside the editor no longer dismiss the popup, so
// clicking next to an attribute has to close it explicitly.
attributeDetailWidget.hide();
- setState("showHelpTooltip");
}
} else {
attributeDetailWidget.hide();
- setState("showHelpTooltip");
}
}}
onKeyDown={() => attributeDetailWidget.hide()}
@@ -403,6 +377,18 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
onClick={save}
/> }
+ { !hideHelpButton && (
+ // This button lives inside the wrapper the detail popup treats as its
+ // spawner, so its outside-click dismissal exempts it. Close it by hand to
+ // match the hosts whose help button sits outside (the attributes panel).
+ <HelpDropdown
+ helpPage={ATTRIBUTE_HELP_PAGE}
+ onShown={() => attributeDetailWidget.hide()}
+ >
+ <AttributeHelp />
+ </HelpDropdown>
+ ) }
+
<ActionButton
icon="bx bx-plus"
className="add-new-attribute-button tn-tool-button"
diff --git a/apps/client/src/widgets/ribbon/components/AttributeHelp.css b/apps/client/src/widgets/ribbon/components/AttributeHelp.css
new file mode 100644
index 0000000000..208aeda681
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/components/AttributeHelp.css
@@ -0,0 +1,3 @@
+.attribute-help > div:not(:last-child) {
+ margin-bottom: 8px;
+}
diff --git a/apps/client/src/widgets/ribbon/components/AttributeHelp.tsx b/apps/client/src/widgets/ribbon/components/AttributeHelp.tsx
new file mode 100644
index 0000000000..e04b2f0c0d
--- /dev/null
+++ b/apps/client/src/widgets/ribbon/components/AttributeHelp.tsx
@@ -0,0 +1,21 @@
+import "./AttributeHelp.css";
+
+import { t } from "../../../services/i18n";
+import { RawHtmlBlock } from "../../react/RawHtml";
+
+/** In-app help note describing labels and relations. */
+export const ATTRIBUTE_HELP_PAGE = "zEY4DaJG4YT5";
+
+/**
+ * Quick reference on how to type attributes into the attribute editor. Rendered inside a
+ * `HelpDropdown`, either the editor's own `?` button or the attributes panel's one in the new layout.
+ */
+export default function AttributeHelp() {
+ return (
+ <div className="attribute-help">
+ <RawHtmlBlock html={t("attribute_editor.help_text_body1")} />
+ <RawHtmlBlock html={t("attribute_editor.help_text_body2")} />
+ <RawHtmlBlock html={t("attribute_editor.help_text_body3")} />
+ </div>
+ );
+}