hide switch in optionalfieldwidget if editing a profile

This commit is contained in:
Josh Hawkins 2026-05-12 16:43:14 -05:00
parent 389ee73ad0
commit 3bc1ae2f77
3 changed files with 13 additions and 1 deletions

View File

@ -1047,6 +1047,7 @@ export function ConfigSection({
hiddenFields: effectiveHiddenFields, hiddenFields: effectiveHiddenFields,
restartRequired: sectionConfig.restartRequired, restartRequired: sectionConfig.restartRequired,
requiresRestart, requiresRestart,
isProfile: !!profileName,
}} }}
/> />

View File

@ -6,6 +6,7 @@ import { getWidget } from "@rjsf/utils";
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { getNonNullSchema } from "../fields/nullableUtils"; import { getNonNullSchema } from "../fields/nullableUtils";
import type { ConfigFormContext } from "@/types/configForm";
export function OptionalFieldWidget(props: WidgetProps) { export function OptionalFieldWidget(props: WidgetProps) {
const { id, value, disabled, readonly, onChange, schema, options, registry } = const { id, value, disabled, readonly, onChange, schema, options, registry } =
@ -13,6 +14,8 @@ export function OptionalFieldWidget(props: WidgetProps) {
const innerWidgetName = (options.innerWidget as string) || undefined; const innerWidgetName = (options.innerWidget as string) || undefined;
const isEnabled = value !== undefined && value !== null; const isEnabled = value !== undefined && value !== null;
const formContext = registry?.formContext as ConfigFormContext | undefined;
const isProfile = !!formContext?.isProfile;
// Extract the non-null branch from anyOf [Type, null] // Extract the non-null branch from anyOf [Type, null]
const innerSchema = getNonNullSchema(schema) ?? schema; const innerSchema = getNonNullSchema(schema) ?? schema;
@ -42,10 +45,17 @@ export function OptionalFieldWidget(props: WidgetProps) {
const innerProps: WidgetProps = { const innerProps: WidgetProps = {
...props, ...props,
schema: innerSchema, schema: innerSchema,
disabled: disabled || readonly || !isEnabled, disabled: disabled || readonly || (!isProfile && !isEnabled),
value: isEnabled ? value : getDefaultValue(), value: isEnabled ? value : getDefaultValue(),
}; };
// don't show the switch if we're editing in a profile
// to disable in a profile, users should edit the config manually, eg:
// skip_motion_threshold: None
if (isProfile) {
return <InnerWidget {...innerProps} />;
}
return ( return (
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<Switch <Switch

View File

@ -44,4 +44,5 @@ export type ConfigFormContext = {
requiresRestart?: boolean; requiresRestart?: boolean;
t?: (key: string, options?: Record<string, unknown>) => string; t?: (key: string, options?: Record<string, unknown>) => string;
renderers?: Record<string, RendererComponent>; renderers?: Record<string, RendererComponent>;
isProfile?: boolean;
}; };