Skip to content

Build your personal knowledge base with Trilium Notes

refactor(toast): show the failing script note as a reference link

Elian Doranc2d1ac3f8b90
diff --git a/apps/client/src/services/toast.spec.ts b/apps/client/src/services/toast.spec.ts
index 3729edd9b0..284164452d 100644
--- a/apps/client/src/services/toast.spec.ts
+++ b/apps/client/src/services/toast.spec.ts
@@ -114,28 +114,23 @@ describe("toast store", () => {
expect(toasts.value).toHaveLength(0);
});
- it("showErrorForScriptNote uses note title/icon and wires the open-script button", async () => {
+ it("showErrorForScriptNote shows the script note as a reference link with a generic error icon", async () => {
const note = buildNote({ title: "My Script" });
- // Force a deterministic icon for assertion.
- note.getIcon = () => "bx bx-code";
await showErrorForScriptNote(note.noteId, "it failed");
const created = toasts.value.find(t => t.id === `custom-widget-failure-${note.noteId}`);
- expect(created).toBeDefined();
expect(created).toMatchObject({
- icon: "bx bx-code",
+ icon: "bx bx-error-circle",
message: "it failed",
- timeout: 15000
+ timeout: 15000,
+ // The script note is attached as a reference link instead of a bespoke open-note button.
+ noteIds: [ note.noteId ]
});
- expect(created?.buttons).toHaveLength(1);
-
- // Invoking the button delegates to the tab manager.
- created!.buttons![0].onClick({ dismissToast: () => {} });
- expect(openInNewTab).toHaveBeenCalledWith(note.noteId, null, true);
+ expect(created?.buttons).toBeUndefined();
});
- it("showErrorForScriptNote falls back when the note cannot be found", async () => {
+ it("showErrorForScriptNote still renders when the note cannot be found", async () => {
const froca = (await import("./froca.js")).default;
const original = froca.getNote;
froca.getNote = vi.fn(async () => null) as typeof froca.getNote;
@@ -143,10 +138,11 @@ describe("toast store", () => {
try {
await showErrorForScriptNote("missing-note", "nope");
const created = toasts.value.find(t => t.id === "custom-widget-failure-missing-note");
- expect(created).toBeDefined();
- // Falls back to the default error icon.
- expect(created?.icon).toBe("bx bx-error-circle");
- expect(created?.message).toBe("nope");
+ expect(created).toMatchObject({
+ icon: "bx bx-error-circle",
+ message: "nope",
+ noteIds: [ "missing-note" ]
+ });
} finally {
froca.getNote = original;
}
diff --git a/apps/client/src/services/toast.ts b/apps/client/src/services/toast.ts
index 55587e514a..eb24e11973 100644
--- a/apps/client/src/services/toast.ts
+++ b/apps/client/src/services/toast.ts
@@ -1,6 +1,5 @@
import { signal } from "@preact/signals";
-import appContext from "../components/app_context.js";
import froca from "./froca.js";
import { t } from "./i18n.js";
import utils, { randomString } from "./utils.js";
@@ -93,15 +92,12 @@ export async function showErrorForScriptNote(noteId: string, message: string) {
showPersistent({
id: `custom-widget-failure-${noteId}`,
title: t("toast.scripting-error", { title: note?.title ?? "" }),
- icon: note?.getIcon() ?? "bx bx-error-circle",
+ icon: "bx bx-error-circle",
message,
- timeout: 15_000,
- buttons: [
- {
- text: t("toast.open-script-note"),
- onClick: () => appContext.tabManager.openInNewTab(noteId, null, true)
- }
- ]
+ // The script note is shown as a reference link (icon + title, click to navigate) rather
+ // than a bespoke "open note" button; ctrl/middle-click still opens it in a new tab.
+ noteIds: [ noteId ],
+ timeout: 15_000
});
}