Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): no "change icon" tooltip on an icon picker that is disabled

Elian Doranf0dc96df6d7f
diff --git a/apps/client/src/widgets/note_icon.spec.tsx b/apps/client/src/widgets/note_icon.spec.tsx
index 6246f1f091..3db4ef6651 100644
--- a/apps/client/src/widgets/note_icon.spec.tsx
+++ b/apps/client/src/widgets/note_icon.spec.tsx
@@ -12,13 +12,22 @@ vi.mock("bootstrap", () => ({
Tooltip: class {}
}));
+// i18next is not initialized under test, where t() answers with nothing; echoing the key back keeps
+// the assertions about whether there is a tooltip at all.
+vi.mock("i18next", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("i18next")>()),
+ t: (key: string) => key
+}));
+
const noteContext = vi.hoisted(() => ({
initialNote: undefined as FNote | undefined,
setNote: undefined as ((note: FNote) => void) | undefined
}));
const tooltipStub = vi.hoisted(() => ({ showTooltip: vi.fn(), hideTooltip: vi.fn() }));
+const tooltipConfig = vi.hoisted(() => ({ current: undefined as { title?: unknown } | undefined }));
const iconPickerProps = vi.hoisted(() => ({
current: undefined as undefined | {
+ disabled?: boolean;
onSelect(icon: string): void;
onReset?: () => void;
}
@@ -33,7 +42,10 @@ vi.mock("./react/hooks", async (importOriginal) => ({
},
useNoteLabel: () => [ undefined ],
useStaticTooltip: () => {},
- useTooltip: () => tooltipStub
+ useTooltip: (_ref: unknown, config: { title?: unknown }) => {
+ tooltipConfig.current = config;
+ return tooltipStub;
+ }
}));
vi.mock("../services/server", () => ({
@@ -99,6 +111,17 @@ describe("NoteIcon", () => {
expect(attributes.setLabel).toHaveBeenLastCalledWith("note-b", "workspaceIconClass", "bx-moon");
});
+ it("offers no tooltip to change the icon of a note whose icon cannot be changed", () => {
+ noteContext.initialNote = buildNote("note-a");
+ renderInto(<NoteIcon />);
+ expect(tooltipConfig.current?.title).toBe("note_icon.change_note_icon");
+
+ noteContext.initialNote = { ...buildNote("_help_page"), isMetadataReadOnly: true } as FNote;
+ renderInto(<NoteIcon />);
+ expect(iconPickerProps.current?.disabled).toBe(true);
+ expect(tooltipConfig.current?.title).toBe("");
+ });
+
it("stays in the legacy widget tree when the active note changes", () => {
glob.iconRegistry = { sources: [] };
noteContext.initialNote = buildNote("note-a");
diff --git a/apps/client/src/widgets/react/IconPicker.tsx b/apps/client/src/widgets/react/IconPicker.tsx
index 5aa842c82b..6c2446aa2e 100644
--- a/apps/client/src/widgets/react/IconPicker.tsx
+++ b/apps/client/src/widgets/react/IconPicker.tsx
@@ -175,7 +175,7 @@ function IconPickerDropdownButton({
// picker's own stylesheet reach through it.
className={clsx("note-icon-widget", className)}
buttonClassName={`note-icon tn-focusable-button ${icon}`}
- title={title}
+ title={disabled ? undefined : title}
disabled={disabled}
dropdownRef={dropdownRef}
autoClose="outside"