mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-06-27 06:41:53 +03:00
hide switch in optionalfieldwidget if editing a profile
This commit is contained in:
parent
389ee73ad0
commit
3bc1ae2f77
@ -1047,6 +1047,7 @@ export function ConfigSection({
|
||||
hiddenFields: effectiveHiddenFields,
|
||||
restartRequired: sectionConfig.restartRequired,
|
||||
requiresRestart,
|
||||
isProfile: !!profileName,
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import { getWidget } from "@rjsf/utils";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { getNonNullSchema } from "../fields/nullableUtils";
|
||||
import type { ConfigFormContext } from "@/types/configForm";
|
||||
|
||||
export function OptionalFieldWidget(props: WidgetProps) {
|
||||
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 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]
|
||||
const innerSchema = getNonNullSchema(schema) ?? schema;
|
||||
@ -42,10 +45,17 @@ export function OptionalFieldWidget(props: WidgetProps) {
|
||||
const innerProps: WidgetProps = {
|
||||
...props,
|
||||
schema: innerSchema,
|
||||
disabled: disabled || readonly || !isEnabled,
|
||||
disabled: disabled || readonly || (!isProfile && !isEnabled),
|
||||
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 (
|
||||
<div className="flex items-center gap-3">
|
||||
<Switch
|
||||
|
||||
@ -44,4 +44,5 @@ export type ConfigFormContext = {
|
||||
requiresRestart?: boolean;
|
||||
t?: (key: string, options?: Record<string, unknown>) => string;
|
||||
renderers?: Record<string, RendererComponent>;
|
||||
isProfile?: boolean;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user