Skip to content

Build your personal knowledge base with Trilium Notes

refactor(badges/content): integrate widget switcher using additional options

Elian Doran178ac088b45b
diff --git a/apps/client/src/widgets/layout/ActiveContentBadges.tsx b/apps/client/src/widgets/layout/ActiveContentBadges.tsx
index edf93b2653..0c874f72d5 100644
--- a/apps/client/src/widgets/layout/ActiveContentBadges.tsx
+++ b/apps/client/src/widgets/layout/ActiveContentBadges.tsx
@@ -9,7 +9,7 @@ import { openInAppHelpFromUrl } from "../../services/utils";
import { BadgeWithDropdown } from "../react/Badge";
import { FormDropdownDivider, FormListItem } from "../react/FormList";
import FormToggle from "../react/FormToggle";
-import { useNoteContext, useNoteLabelBoolean, useTriliumEvent } from "../react/hooks";
+import { useNoteContext, useTriliumEvent } from "../react/hooks";
import { BookProperty, ViewProperty } from "../react/NotePropertyMenu";
const NON_DANGEROUS_ACTIVE_CONTENT = [ "appCss", "appTheme" ];
@@ -78,14 +78,32 @@ const typeMappings: Record<ActiveContentInfo["type"], {
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") }
+ { value: "mobileStartup", label: t("active_content_badges.menu_run_mobile_startup") },
]
+ },
+ { type: "separator" },
+ {
+ type: "button",
+ label: t("active_content_badges.menu_change_to_widget"),
+ icon: "bx bxs-widget",
+ onClick: ({ note }) => attributes.setLabel(note.noteId, "widget")
}
]
},
widget: {
icon: "bx bxs-widget",
- helpPage: "MgibgPcfeuGz"
+ helpPage: "MgibgPcfeuGz",
+ additionalOptions: [
+ {
+ type: "button",
+ label: t("active_content_badges.menu_change_to_frontend_script"),
+ icon: "bx bx-window",
+ onClick: ({ note }) => {
+ attributes.removeOwnedLabelByName(note, "widget");
+ attributes.removeOwnedLabelByName(note, "disabled:widget");
+ }
+ }
+ ]
},
appCss: {
icon: "bx bxs-file-css",
@@ -141,13 +159,6 @@ function ActiveContentBadge({ info, note }: { note: FNote, info: ActiveContentIn
icon={icon}
text={getTranslationForType(info.type)}
>
- {(info.type === "frontendScript" || info.type === "widget") && (
- <>
- <WidgetSwitcher note={note} />
- <FormDropdownDivider />
- </>
- )}
-
{additionalOptions?.length && (
<>
{additionalOptions?.map((property, i) => (
@@ -170,27 +181,6 @@ function ActiveContentBadge({ info, note }: { note: FNote, info: ActiveContentIn
);
}
-function WidgetSwitcher({ note }: { note: FNote }) {
- const [ widget, setWidget ] = useNoteLabelBoolean(note, "widget");
- const [ disabledWidget, setDisabledWidget ] = useNoteLabelBoolean(note, "disabled:widget");
-
- return (widget || disabledWidget)
- ? <FormListItem
- icon="bx bx-window"
- onClick={() => {
- setWidget(false);
- setDisabledWidget(false);
- }}
- >{t("active_content_badges.menu_change_to_frontend_script")}</FormListItem>
- : <FormListItem
- icon={widget ? "bx bx-window" : "bx bxs-widget"}
- onClick={() => {
- setWidget(true);
- }}
- >{t("active_content_badges.menu_change_to_widget")}</FormListItem>;
-
-}
-
function getTranslationForType(type: ActiveContentInfo["type"]) {
switch (type) {
case "iconPack":
diff --git a/apps/client/src/widgets/react/NotePropertyMenu.tsx b/apps/client/src/widgets/react/NotePropertyMenu.tsx
index 6a5bba1bf8..cbc4985e68 100644
--- a/apps/client/src/widgets/react/NotePropertyMenu.tsx
+++ b/apps/client/src/widgets/react/NotePropertyMenu.tsx
@@ -58,7 +58,7 @@ interface ComboBoxGroup {
items: ComboBoxItem[];
}
-interface ComboBoxSeparator {
+interface Separator {
type: "separator"
}
@@ -71,11 +71,11 @@ export interface ComboBoxProperty {
* The default value is used when the label is not set.
*/
defaultValue?: string;
- options: (ComboBoxItem | ComboBoxSeparator | ComboBoxGroup)[];
+ options: (ComboBoxItem | Separator | ComboBoxGroup)[];
dropStart?: boolean;
}
-export type BookProperty = CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty | SplitButtonProperty;
+export type BookProperty = CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty | SplitButtonProperty | Separator;
export function ViewProperty({ note, property }: { note: FNote, property: BookProperty }) {
switch (property.type) {
@@ -89,6 +89,8 @@ export function ViewProperty({ note, property }: { note: FNote, property: BookPr
return <NumberPropertyView note={note} property={property} />;
case "combobox":
return <ComboBoxPropertyView note={note} property={property} />;
+ case "separator":
+ return <FormDropdownDivider />;
}
}