mirror of
https://github.com/zadam/trilium.git
synced 2026-02-20 04:34:38 +01:00
refactor(badges/content): integrate execute using additional options
This commit is contained in:
parent
6b78bfecb4
commit
ffd5ebbe79
@ -7,9 +7,9 @@ import attributes from "../../services/attributes";
|
||||
import { t } from "../../services/i18n";
|
||||
import { openInAppHelpFromUrl } from "../../services/utils";
|
||||
import { BadgeWithDropdown } from "../react/Badge";
|
||||
import { FormDropdownDivider, FormDropdownSubmenu, FormListItem } from "../react/FormList";
|
||||
import { FormDropdownDivider, FormListItem } from "../react/FormList";
|
||||
import FormToggle from "../react/FormToggle";
|
||||
import { useNoteContext, useNoteLabel, useNoteLabelBoolean, useTriliumEvent } from "../react/hooks";
|
||||
import { useNoteContext, useNoteLabelBoolean, useTriliumEvent } from "../react/hooks";
|
||||
import { BookProperty, ViewProperty } from "../react/NotePropertyMenu";
|
||||
|
||||
const NON_DANGEROUS_ACTIVE_CONTENT = [ "appCss", "appTheme" ];
|
||||
@ -22,6 +22,13 @@ interface ActiveContentInfo {
|
||||
canToggleEnabled: boolean;
|
||||
}
|
||||
|
||||
const executeOption: BookProperty = {
|
||||
type: "button",
|
||||
icon: "bx bx-play",
|
||||
label: t("active_content_badges.menu_execute_now"),
|
||||
onClick: context => context.triggerCommand("runActiveNote")
|
||||
};
|
||||
|
||||
const typeMappings: Record<ActiveContentInfo["type"], {
|
||||
icon: string;
|
||||
helpPage: string;
|
||||
@ -39,6 +46,7 @@ const typeMappings: Record<ActiveContentInfo["type"], {
|
||||
apiDocsPage: "MEtfsqa5VwNi",
|
||||
isExecutable: true,
|
||||
additionalOptions: [
|
||||
executeOption,
|
||||
{
|
||||
type: "combobox",
|
||||
bindToLabel: "run",
|
||||
@ -60,6 +68,7 @@ const typeMappings: Record<ActiveContentInfo["type"], {
|
||||
apiDocsPage: "Q2z6av6JZVWm",
|
||||
isExecutable: true,
|
||||
additionalOptions: [
|
||||
executeOption,
|
||||
{
|
||||
type: "combobox",
|
||||
bindToLabel: "run",
|
||||
@ -125,23 +134,13 @@ export function ActiveContentBadges() {
|
||||
}
|
||||
|
||||
function ActiveContentBadge({ info, note }: { note: FNote, info: ActiveContentInfo }) {
|
||||
const { icon, helpPage, apiDocsPage, isExecutable, additionalOptions } = typeMappings[info.type];
|
||||
const { icon, helpPage, apiDocsPage, additionalOptions } = typeMappings[info.type];
|
||||
return (
|
||||
<BadgeWithDropdown
|
||||
className={clsx("active-content-badge", info.canToggleEnabled && !info.isEnabled && "disabled")}
|
||||
icon={icon}
|
||||
text={getTranslationForType(info.type)}
|
||||
>
|
||||
{isExecutable && (
|
||||
<>
|
||||
<FormListItem
|
||||
icon="bx bx-play"
|
||||
triggerCommand="runActiveNote"
|
||||
>{t("active_content_badges.menu_execute_now")}</FormListItem>
|
||||
<FormDropdownDivider />
|
||||
</>
|
||||
)}
|
||||
|
||||
{(info.type === "frontendScript" || info.type === "widget") && (
|
||||
<>
|
||||
<WidgetSwitcher note={note} />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user