From 740b02952f86c5a6beff60707769a14ba0527b2f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 14 Feb 2026 12:22:27 +0200 Subject: [PATCH] feat(badges/content): disable toggle when not necessary --- apps/client/src/entities/fnote.ts | 4 ++ .../widgets/layout/ActiveContentBadges.tsx | 37 ++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.ts index f161d7adb1..fbe9493128 100644 --- a/apps/client/src/entities/fnote.ts +++ b/apps/client/src/entities/fnote.ts @@ -700,6 +700,10 @@ export default class FNote { return this.hasAttribute(LABEL, name); } + hasLabelOrDisabled(name: string) { + return this.hasLabel(name) || this.hasLabel(`disabled:${name}`); + } + /** * @param name - label name * @returns true if label exists (including inherited) and does not have "false" value. diff --git a/apps/client/src/widgets/layout/ActiveContentBadges.tsx b/apps/client/src/widgets/layout/ActiveContentBadges.tsx index ae5dc4ca0f..35160eee8d 100644 --- a/apps/client/src/widgets/layout/ActiveContentBadges.tsx +++ b/apps/client/src/widgets/layout/ActiveContentBadges.tsx @@ -51,8 +51,8 @@ export function ActiveContentBadges() { return (note && info && <> + {info.canToggleEnabled && } - ); } @@ -151,15 +151,23 @@ function ScriptRunOptions({ info, note }: { note: FNote, info: ActiveContentInfo function WidgetSwitcher({ note }: { note: FNote }) { const [ widget, setWidget ] = useNoteLabelBoolean(note, "widget"); + const [ disabledWidget, setDisabledWidget ] = useNoteLabelBoolean(note, "disabled:widget"); - return ( - { + setWidget(false); + setDisabledWidget(false); + }} + >{t("active_content_badges.menu_change_to_frontend_script")} + : setWidget(!widget)} - > - {widget ? t("active_content_badges.menu_change_to_frontend_script") : t("active_content_badges.menu_change_to_widget")} - - ); + onClick={() => { + setWidget(true); + }} + >{t("active_content_badges.menu_change_to_widget")}; + } function getTranslationForType(type: ActiveContentInfo["type"]) { @@ -213,6 +221,7 @@ function getNameWithoutPrefix(name: string) { interface ActiveContentInfo { type: "iconPack" | "backendScript" | "frontendScript" | "widget" | "appCss"; isEnabled: boolean; + canToggleEnabled: boolean; } function useActiveContentInfo(note: FNote | null | undefined) { @@ -221,6 +230,7 @@ function useActiveContentInfo(note: FNote | null | undefined) { function refresh() { let type: ActiveContentInfo["type"] | null = null; let isEnabled = true; + let canToggleEnabled = false; if (!note) { setInfo(null); @@ -229,8 +239,17 @@ function useActiveContentInfo(note: FNote | null | undefined) { if (note.type === "code" && note.mime === "application/javascript;env=backend") { type = "backendScript"; + for (const backendLabel of [ "run", "customRequestHandler", "customResourceProvider" ]) { + isEnabled ||= note.hasLabel(backendLabel); + + if (!canToggleEnabled && note.hasLabelOrDisabled(backendLabel)) { + canToggleEnabled = true; + } + } } else if (note.type === "code" && note.mime === "application/javascript;env=frontend") { type = "frontendScript"; + isEnabled = note.hasLabel("widget") || note.hasLabel("run"); + canToggleEnabled = note.hasLabelOrDisabled("widget") || note.hasLabelOrDisabled("run"); } for (const labelToCheck of activeContentLabels ) { @@ -245,7 +264,7 @@ function useActiveContentInfo(note: FNote | null | undefined) { } if (type) { - setInfo({ type, isEnabled }); + setInfo({ type, isEnabled, canToggleEnabled }); } else { setInfo(null); }