Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): title the execute badge from the note's labels

Elian Doran395dd62c32de
diff --git a/apps/client/src/widgets/layout/NoteBadges.spec.tsx b/apps/client/src/widgets/layout/NoteBadges.spec.tsx
index 6f395cf349..6915661a76 100644
--- a/apps/client/src/widgets/layout/NoteBadges.spec.tsx
+++ b/apps/client/src/widgets/layout/NoteBadges.spec.tsx
@@ -22,7 +22,7 @@ vi.mock("../../services/i18n", () => ({
import { buildNote } from "../../test/easy-froca";
import { renderInto } from "../../test/render";
-import { getShareScope, OfficePreviewBadge } from "./NoteBadges";
+import { ExecuteBadge, getShareScope, OfficePreviewBadge } from "./NoteBadges";
const DOCX_MIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
@@ -53,6 +53,23 @@ describe("OfficePreviewBadge", () => {
}
});
+describe("ExecuteBadge", () => {
+ it("titles the button with #executeTitle or the value of #executeButton, falling back to the wording for the note's language", () => {
+ expect(renderBadge({ "#executeButton": "", "#executeTitle": "Deploy" })?.textContent).toBe("Deploy");
+ expect(renderBadge({ "#executeButton": "Create launcher" })?.textContent).toBe("Create launcher");
+ expect(renderBadge({ "#executeButton": "true", "#executeTitle": "Deploy" })?.textContent).toBe("Deploy");
+ expect(renderBadge({ "#executeButton": "true" })?.textContent).toBe("breadcrumb_badges.execute_script");
+ expect(renderBadge({ "#executeButton": "" })?.textContent).toBe("breadcrumb_badges.execute_script");
+ expect(renderBadge({ "#executeDescription": "Rebuilds the index" })?.textContent).toBe("breadcrumb_badges.execute_script");
+ expect(renderBadge({})).toBeNull();
+ });
+
+ function renderBadge(labels: Record<`#${string}`, string>) {
+ shownNote.current = buildNote({ title: "Script", type: "code", mime: "application/javascript;env=frontend", ...labels });
+ return renderInto(<ExecuteBadge />).querySelector(".execute-badge .text");
+ }
+});
+
describe("getShareScope", () => {
it("tells a public share from a local one, a standalone preview and one only an export publishes", () => {
const syncServerHost = "https://sync.example.com";
diff --git a/apps/client/src/widgets/layout/NoteBadges.tsx b/apps/client/src/widgets/layout/NoteBadges.tsx
index 30871764a0..d0cd84907c 100644
--- a/apps/client/src/widgets/layout/NoteBadges.tsx
+++ b/apps/client/src/widgets/layout/NoteBadges.tsx
@@ -18,7 +18,7 @@ import { isElectron, isMobileApp, isStandalone } from "../../services/utils";
import { Badge, BadgeWithDropdown } from "../react/Badge";
import { FormDropdownDivider, FormListItem } from "../react/FormList";
import {
- useGetContextDataFrom, useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty,
+ useGetContextDataFrom, useIsNoteReadOnly, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteLabelByName, useNoteProperty,
useTriliumEvent, useTriliumOption
} from "../react/hooks";
import { ActiveContentBadges } from "./ActiveContentBadges";
@@ -165,19 +165,23 @@ function ClippedNoteBadge() {
);
}
-function ExecuteBadge() {
+export function ExecuteBadge() {
const { note, parentComponent } = useNoteContext();
const isScript = note?.isTriliumScript();
const isSql = note?.isTriliumSqlite();
const isExecutable = isScript || isSql;
const [ executeDescription ] = useNoteLabel(note, "executeDescription");
const [ executeButton ] = useNoteLabelBoolean(note, "executeButton");
+ const [ executeTitle ] = useNoteLabel(note, "executeTitle");
+ // `#executeButton` is typed as a flag, but the User Guide documents its value as the button's title.
+ const [ executeButtonValue ] = useNoteLabelByName(note, "executeButton");
+ const title = executeTitle || (executeButtonValue !== "true" && executeButtonValue !== "false" && executeButtonValue);
return (note && isExecutable && (executeDescription || executeButton) &&
<Badge
className="execute-badge"
icon="bx bx-play"
- text={isScript ? t("breadcrumb_badges.execute_script") : t("breadcrumb_badges.execute_sql")}
+ text={title || (isScript ? t("breadcrumb_badges.execute_script") : t("breadcrumb_badges.execute_sql"))}
tooltip={executeDescription || (isScript ? t("breadcrumb_badges.execute_script_description") : t("breadcrumb_badges.execute_sql_description"))}
onClick={() => parentComponent.triggerCommand("runActiveNote")}
/>