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
client/collections/board: add help tooltip for board config menu -> Inbox column
Adorian Doranb99e4f136dc4
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 435b79d1ef..9701eb9c0a 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3348,6 +3348,7 @@},"book_properties_config": {"board-inbox-column": "Inbox column",+ "board-inbox-column-help": "Shows the inbox column, which lists the notes descendant to this board that were not assigned to a board column.","hide-weekends": "Hide weekends","display-week-numbers": "Display week numbers","map-style": "Map style",diff --git a/apps/client/src/widgets/react/NotePropertyMenu.spec.tsx b/apps/client/src/widgets/react/NotePropertyMenu.spec.tsxnew file mode 100644index 0000000000..7385b09147--- /dev/null+++ b/apps/client/src/widgets/react/NotePropertyMenu.spec.tsx@@ -0,0 +1,73 @@+import { render } from "preact";+import { act } from "preact/test-utils";+import { afterEach, describe, expect, it } from "vitest";++import { buildNote } from "../../test/easy-froca";+import type FNote from "../../entities/fnote";+import { ViewProperty } from "./NotePropertyMenu";++describe("A collection property's explanation", () => {+ let container: HTMLElement | undefined;++ afterEach(() => {+ if (container) {+ render(null, container);+ container.remove();+ container = undefined;+ }+ });++ async function draw(property: Parameters<typeof ViewProperty>[0]["property"]) {+ const note = buildNote({ title: "Board" }) as unknown as FNote;+ const element = document.createElement("div");+ container = element;+ document.body.appendChild(element);++ await act(async () => {+ render(<ViewProperty note={note} property={property} />, element);+ });+ return element;+ }++ /**+ * The note belongs to a property of any kind, so a button carries one the same way a checkbox+ * does. The label is what it stands beside, which is what this asserts alongside it.+ */+ it("stands beside the label of a property that is not a checkbox", async () => {+ const element = await draw({+ type: "button",+ label: "Collapse",+ icon: "bx bx-layer-minus",+ helpTooltip: "Folds every note under this one.",+ onClick() {}+ });++ expect(element.textContent).toContain("Collapse");+ expect(element.querySelector(".help-tooltip-button")).not.toBeNull();+ });++ it("is left out where the property carries none", async () => {+ const element = await draw({+ type: "button",+ label: "Collapse",+ icon: "bx bx-layer-minus",+ onClick() {}+ });++ expect(element.textContent).toContain("Collapse");+ expect(element.querySelector(".help-tooltip-button")).toBeNull();+ });++ it("stands on a checkbox too, whose label is the switch's own", async () => {+ const element = await draw({+ type: "checkbox",+ label: "Inbox column",+ icon: "bx bx-inbox",+ helpTooltip: "Shows the notes with no column yet.",+ bindToLabel: "enableInboxColumn"+ });++ expect(element.textContent).toContain("Inbox column");+ expect(element.querySelector(".help-tooltip-button")).not.toBeNull();+ });+});diff --git a/apps/client/src/widgets/react/NotePropertyMenu.tsx b/apps/client/src/widgets/react/NotePropertyMenu.tsxindex fdcfb96cf8..f36380a141 100644--- a/apps/client/src/widgets/react/NotePropertyMenu.tsx+++ b/apps/client/src/widgets/react/NotePropertyMenu.tsx@@ -6,6 +6,7 @@ import Component from "../../components/component";import FNote from "../../entities/fnote";import NoteContextAwareWidget from "../note_context_aware_widget";import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListToggleableItem } from "./FormList";+import HelpTooltipButton from "./HelpTooltipButton";import FormTextBox from "./FormTextBox";import { useNoteLabel, useNoteLabelBoolean } from "./hooks";import { ParentComponent } from "./react_utils";@@ -15,6 +16,12 @@ export interface ClickContext {triggerCommand: NoteContextAwareWidget["triggerCommand"];}+/** Carried by a property of any kind, for one whose label does not say enough on its own. */+export interface PropertyHelp {+ /** What the property does, shown on hover beside its label. */+ helpTooltip?: string;+}+export interface CheckBoxProperty {type: "checkbox",label: string;@@ -22,6 +29,8 @@ export interface CheckBoxProperty {icon?: string;/** When true, the checkbox will be checked when the label value is false. Useful when the label represents a "hide" action, without exposing double negatives to the user. */reverseValue?: boolean;+ /** What the setting does, shown on hover beside the label. */+ helpTooltip?: string;}export interface ButtonProperty {@@ -95,13 +104,26 @@ export interface OptionGroupProperty {options: ComboBoxItem[];}-export type BookProperty = CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty | SplitButtonProperty | SubmenuProperty | OptionGroupProperty | Separator;+export type BookProperty = (+ CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty+ | SplitButtonProperty | SubmenuProperty | OptionGroupProperty | Separator+) & PropertyHelp;/** Whether a property should render for the given note, honouring an optional `isVisible` predicate. */export function isPropertyVisible(property: BookProperty, note: FNote): boolean {return !("isVisible" in property) || (property.isVisible?.(note) ?? true);}+/** A property's label, and beside it the explanation the property carries, where it carries one. */+function PropertyLabel({ property }: { property: BookProperty & { label: string } }) {+ return (+ <>+ {property.label}+ {property.helpTooltip && <HelpTooltipButton description={property.helpTooltip} />}+ </>+ );+}+export function ViewProperty({ note, property }: { note: FNote, property: BookProperty }) {if (!isPropertyVisible(property, note)) {return null;@@ -130,7 +152,7 @@ export function ViewProperty({ note, property }: { note: FNote, property: BookPrfunction SubmenuPropertyView({ note, property }: { note: FNote, property: SubmenuProperty }) {return (<FormDropdownSubmenu- title={property.label}+ title={<PropertyLabel property={property} />}icon={property.icon ?? "bx bx-empty"}>{property.children.map((child, index) => (@@ -146,7 +168,7 @@ function OptionGroupPropertyView({ note, property }: { note: FNote, property: Opreturn (<Fragment>- <FormListItem disabled>{property.label}</FormListItem>+ <FormListItem disabled><PropertyLabel property={property} /></FormListItem>{property.options.map((option) => (<FormListItemkey={option.value}@@ -178,7 +200,7 @@ function ButtonPropertyView({ note, property }: { note: FNote, property: ButtonPtriggerCommand: parentComponent.triggerCommand.bind(parentComponent)});}}- >{property.label}</FormListItem>+ ><PropertyLabel property={property} /></FormListItem>);}@@ -193,7 +215,7 @@ function SplitButtonPropertyView({ note, property }: { note: FNote, property: Spreturn (parentComponent &&<FormDropdownSubmenuicon={property.icon ?? "bx bx-empty"}- title={property.label}+ title={<PropertyLabel property={property} />}onDropdownToggleClicked={() => clickContext && property.onClick(clickContext)}><ItemsComponent note={note} parentComponent={parentComponent} />@@ -212,7 +234,7 @@ function NumberPropertyView({ note, property }: { note: FNote, property: NumberPdisabled={disabled}onClick={(e) => e.stopPropagation()}>- {property.label}+ <PropertyLabel property={property} /><FormTextBoxtype="number"currentValue={value ?? ""} onChange={setValue}@@ -242,7 +264,7 @@ function ComboBoxPropertyView({ note, property }: { note: FNote, property: Comboreturn (<FormDropdownSubmenu- title={property.label}+ title={<PropertyLabel property={property} />}icon={property.icon ?? "bx bx-empty"}dropStart={property.dropStart}>@@ -273,6 +295,7 @@ function CheckBoxPropertyView({ note, property }: { note: FNote, property: Check<FormListToggleableItemicon={property.icon}title={property.label}+ helpTooltip={property.helpTooltip}currentValue={ property.reverseValue ? !value : value }onChange={newValue => setValue(property.reverseValue ? !newValue : newValue)}/>diff --git a/apps/client/src/widgets/ribbon/collection-properties-config.tsx b/apps/client/src/widgets/ribbon/collection-properties-config.tsxindex 33dac784e1..65fa6cd537 100644--- a/apps/client/src/widgets/ribbon/collection-properties-config.tsx+++ b/apps/client/src/widgets/ribbon/collection-properties-config.tsx@@ -153,6 +153,7 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {label: t("book_properties_config.board-inbox-column"),type: "checkbox",icon: "bx bx-inbox",+ helpTooltip: t("book_properties_config.board-inbox-column-help"),bindToLabel: "enableInboxColumn"}]