mirror of
https://github.com/zadam/trilium.git
synced 2026-02-19 20:24:28 +01:00
refactor(badges/content): integrate run options using additional options
This commit is contained in:
parent
d3c0a44c00
commit
6b78bfecb4
@ -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");
|
||||
|
||||
@ -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}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user