Skip to content

Build your personal knowledge base with Trilium Notes

refactor(badges/content): integrate run options using additional options

Elian Doran6b78bfecb4d7
diff --git a/apps/client/src/widgets/layout/ActiveContentBadges.tsx b/apps/client/src/widgets/layout/ActiveContentBadges.tsx
index 781f827553..473cae9a85 100644
--- a/apps/client/src/widgets/layout/ActiveContentBadges.tsx
+++ b/apps/client/src/widgets/layout/ActiveContentBadges.tsx
@@ -38,12 +38,41 @@ const typeMappings: Record<ActiveContentInfo["type"], {
helpPage: "SPirpZypehBG",
apiDocsPage: "MEtfsqa5VwNi",
isExecutable: true,
+ additionalOptions: [
+ {
+ type: "combobox",
+ bindToLabel: "run",
+ label: t("active_content_badges.menu_run"),
+ icon: "bx bx-rss",
+ dropStart: true,
+ options: [
+ { value: null, label: t("active_content_badges.menu_run_disabled") },
+ { value: "backendStartup", label: t("active_content_badges.menu_run_backend_startup") },
+ { value: "daily", label: t("active_content_badges.menu_run_daily") },
+ { value: "hourly", label: t("active_content_badges.menu_run_hourly") }
+ ]
+ }
+ ]
},
frontendScript: {
icon: "bx bx-window",
helpPage: "yIhgI5H7A2Sm",
apiDocsPage: "Q2z6av6JZVWm",
- isExecutable: true
+ isExecutable: true,
+ additionalOptions: [
+ {
+ type: "combobox",
+ bindToLabel: "run",
+ label: t("active_content_badges.menu_run"),
+ icon: "bx bx-rss",
+ dropStart: true,
+ options: [
+ { value: null, label: t("active_content_badges.menu_run_disabled") },
+ { value: "frontendStartup", label: t("active_content_badges.menu_run_frontend_startup") },
+ { value: "mobileStartup", label: t("active_content_badges.menu_run_mobile_startup") }
+ ]
+ }
+ ]
},
widget: {
icon: "bx bxs-widget",
@@ -109,7 +138,6 @@ function ActiveContentBadge({ info, note }: { note: FNote, info: ActiveContentIn
icon="bx bx-play"
triggerCommand="runActiveNote"
>{t("active_content_badges.menu_execute_now")}</FormListItem>
- <ScriptRunOptions note={note} info={info} />
<FormDropdownDivider />
</>
)}
@@ -143,59 +171,6 @@ function ActiveContentBadge({ info, note }: { note: FNote, info: ActiveContentIn
);
}
-function ScriptRunOptions({ info, note }: { note: FNote, info: ActiveContentInfo }) {
- const [ run, setRun ] = useNoteLabel(note, "run");
-
- const options: {
- title: string;
- value: string | null;
- type: "both" | "backendScript" | "frontendScript";
- }[] = ([
- {
- title: t("active_content_badges.menu_run_disabled"),
- value: null,
- type: "both"
- },
- {
- title: t("active_content_badges.menu_run_backend_startup"),
- value: "backendStartup",
- type: "backendScript"
- },
- {
- title: t("active_content_badges.menu_run_daily"),
- value: "daily",
- type: "backendScript"
- },
- {
- title: t("active_content_badges.menu_run_hourly"),
- value: "hourly",
- type: "backendScript"
- },
- {
- title: t("active_content_badges.menu_run_frontend_startup"),
- value: "frontendStartup",
- type: "frontendScript"
- },
- {
- title: t("active_content_badges.menu_run_mobile_startup"),
- value: "mobileStartup",
- type: "frontendScript"
- }
- ] as const).filter(option => option.type === "both" || option.type === info.type);
-
- return (
- <FormDropdownSubmenu title={t("active_content_badges.menu_run")} icon="bx bx-rss" dropStart>
- {options.map(({ title, value }) => (
- <FormListItem
- key={value}
- onClick={() => setRun(value)}
- checked={run ? run === value : value === null }
- >{title}</FormListItem>
- ))}
- </FormDropdownSubmenu>
- );
-}
-
function WidgetSwitcher({ note }: { note: FNote }) {
const [ widget, setWidget ] = useNoteLabelBoolean(note, "widget");
const [ disabledWidget, setDisabledWidget ] = useNoteLabelBoolean(note, "disabled:widget");
diff --git a/apps/client/src/widgets/react/NotePropertyMenu.tsx b/apps/client/src/widgets/react/NotePropertyMenu.tsx
index 5384c400a4..6a5bba1bf8 100644
--- a/apps/client/src/widgets/react/NotePropertyMenu.tsx
+++ b/apps/client/src/widgets/react/NotePropertyMenu.tsx
@@ -7,7 +7,7 @@ import FNote from "../../entities/fnote";
import NoteContextAwareWidget from "../note_context_aware_widget";
import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListToggleableItem } from "./FormList";
import FormTextBox from "./FormTextBox";
-import { useNoteLabelBoolean, useNoteLabelWithDefault } from "./hooks";
+import { useNoteLabel, useNoteLabelBoolean, useNoteLabelWithDefault } from "./hooks";
import { ParentComponent } from "./react_utils";
export interface ClickContext {
@@ -153,13 +153,14 @@ function NumberPropertyView({ note, property }: { note: FNote, property: NumberP
}
function ComboBoxPropertyView({ note, property }: { note: FNote, property: ComboBoxProperty }) {
- const [ value, setValue ] = useNoteLabelWithDefault(note, property.bindToLabel, property.defaultValue ?? "");
+ const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
+ const valueWithDefault = value ?? property.defaultValue ?? null;
function renderItem(option: ComboBoxItem) {
return (
<FormListItem
key={option.value}
- checked={value === option.value}
+ checked={valueWithDefault === option.value}
onClick={() => setValue(option.value)}
>
{option.label}