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
feat(toast): add a "More info" help button to the backend-scripting toast
Elian Dorane7a4e8f5536c
diff --git a/apps/client/src/services/frontend_script_api.spec.ts b/apps/client/src/services/frontend_script_api.spec.tsindex 8824b2423a..a4860c71e3 100644--- a/apps/client/src/services/frontend_script_api.spec.ts+++ b/apps/client/src/services/frontend_script_api.spec.ts@@ -16,7 +16,7 @@ import searchService from "./search.js";import server from "./server.js";import shortcutService from "./shortcuts.js";import toastService from "./toast.js";-import utils from "./utils.js";+import utils, * as clientUtils from "./utils.js";import ws from "./ws.js";// The global ws mock from setup.ts does not define waitForMaxKnownEntityChangeId.@@ -193,10 +193,15 @@ describe("runOnBackend / __runOnBackendInner", () => {expect(post).not.toHaveBeenCalled();expect(showPersistent).toHaveBeenCalledWith(expect.objectContaining({ id: "backend-scripting-disabled", wide: true }));- // The toast's action opens Security settings in the options modal, not a hoisted tab.+ // The first action opens Security settings in the options modal, not a hoisted tab.const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockReturnValue(undefined as never);showPersistent.mock.calls[0][0].buttons?.[0].onClick({ dismissToast: vi.fn() });expect(triggerCommand).toHaveBeenCalledWith("showOptions", { section: "_optionsSecurity" });++ // The second action opens the corresponding help note.+ const openHelp = vi.spyOn(clientUtils, "openInAppHelpFromUrl").mockReturnValue(undefined as never);+ showPersistent.mock.calls[0][0].buttons?.[1].onClick({ dismissToast: vi.fn() });+ expect(openHelp).toHaveBeenCalledWith("fiHicjpHjIRJ");});it("lists the attempting scripts as reference notes and accumulates them across attempts", async () => {diff --git a/apps/client/src/services/frontend_script_api.ts b/apps/client/src/services/frontend_script_api.tsindex 6dd9a25c81..ae986e709c 100644--- a/apps/client/src/services/frontend_script_api.ts+++ b/apps/client/src/services/frontend_script_api.ts@@ -23,7 +23,7 @@ import server from "./server.js";import shortcutService from "./shortcuts.js";import SpacedUpdate from "./spaced_update.js";import toastService from "./toast.js";-import utils from "./utils.js";+import utils, { openInAppHelpFromUrl } from "./utils.js";import ws from "./ws.js";/**@@ -842,6 +842,14 @@ function showBackendScriptingDisabledToast(noteId: string) {appContext.triggerCommand("showOptions", { section: "_optionsSecurity" });dismissToast();}+ },+ {+ text: t("frontend_script_api.backend_scripting_disabled_more_info"),+ onClick: ({ dismissToast }) => {+ // openInAppHelpFromUrl takes the help note ID without the "_help_" prefix.+ openInAppHelpFromUrl("fiHicjpHjIRJ");+ dismissToast();+ }}]});diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 05bec9bfb7..e6234d8407 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2403,7 +2403,8 @@"backend_scripting_disabled_title": "Backend scripting is disabled","backend_scripting_disabled_message": "A script tried to run code on the server, but backend scripting is turned off for security reasons. Enable it in Options → Security if you trust this script.","backend_scripting_disabled_notes_heading": "Scripts that tried to run backend code:",- "backend_scripting_disabled_open_settings": "Open security settings"+ "backend_scripting_disabled_open_settings": "Open security settings",+ "backend_scripting_disabled_more_info": "More info"},"ws": {"sync-check-failed": "Sync check failed!",diff --git a/apps/client/src/widgets/Toast.css b/apps/client/src/widgets/Toast.cssindex c89b136cef..684b09270a 100644--- a/apps/client/src/widgets/Toast.css+++ b/apps/client/src/widgets/Toast.css@@ -67,13 +67,15 @@.toast {.toast-buttons {- padding: 0 var(--bs-toast-padding-x) var(--bs-toast-padding-y) var(--bs-toast-padding-x);+ padding: 0.5em var(--bs-toast-padding-x) var(--bs-toast-padding-y) var(--bs-toast-padding-x);display: flex;- flex-direction: column;- gap: 0.5em;+ flex-direction: row;+ flex-wrap: wrap;+ gap: 1em;.btn {- width: 100%;+ /* Share the row equally; a lone button still spans the full width. */+ flex: 1;color: var(--bs-toast-color);background: var(--modal-control-button-background);