don't save model config back to yaml when saving detectors

This commit is contained in:
Josh Hawkins 2026-02-06 09:34:10 -06:00
parent 19acfe0f7c
commit d1422f295b
3 changed files with 27 additions and 8 deletions

View File

@ -10,7 +10,6 @@ const detectorHiddenFields = [
const detectors: SectionConfigOverrides = { const detectors: SectionConfigOverrides = {
base: { base: {
sectionDocs: "/configuration/object_detectors", sectionDocs: "/configuration/object_detectors",
restartRequired: [],
fieldOrder: [], fieldOrder: [],
advancedFields: [], advancedFields: [],
hiddenFields: detectorHiddenFields, hiddenFields: detectorHiddenFields,

View File

@ -146,5 +146,26 @@ export function sanitizeOverridesForSection(
}; };
} }
// detectors: Strip readonly model fields that are generated on startup
// and should never be persisted back to the config file.
if (sectionPath === "detectors") {
const overridesObj = overrides as JsonObject;
const cleaned: JsonObject = {};
Object.entries(overridesObj).forEach(([key, value]) => {
if (!isJsonObject(value)) {
cleaned[key] = value;
return;
}
const cleanedValue = { ...value } as JsonObject;
delete cleanedValue.model;
delete cleanedValue.model_path;
cleaned[key] = cleanedValue;
});
return cleaned;
}
return overrides; return overrides;
} }

View File

@ -6,6 +6,7 @@ import type {
UiSchema, UiSchema,
} from "@rjsf/utils"; } from "@rjsf/utils";
import { toFieldPathId } from "@rjsf/utils"; import { toFieldPathId } from "@rjsf/utils";
import { cloneDeep, set as lodashSet } from "lodash";
import { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { import {
@ -297,8 +298,8 @@ export function DetectorHardwareField(props: FieldProps) {
}, [detectors]); }, [detectors]);
const updateDetectors = useCallback( const updateDetectors = useCallback(
(nextDetectors: JsonObject) => { (nextDetectors: JsonObject, path?: FieldPathList) => {
onChange(nextDetectors as unknown, [] as FieldPathList); onChange(nextDetectors as unknown, path ?? ([] as FieldPathList));
}, },
[onChange], [onChange],
); );
@ -562,14 +563,12 @@ export function DetectorHardwareField(props: FieldProps) {
const handleInstanceChange = ( const handleInstanceChange = (
nextValue: unknown, nextValue: unknown,
_path: FieldPathList, path: FieldPathList,
_errors?: ErrorSchema, _errors?: ErrorSchema,
_id?: string, _id?: string,
) => { ) => {
const nextDetectors = { const nextDetectors = cloneDeep(detectors);
...detectors, lodashSet(nextDetectors, path, nextValue);
[key]: nextValue ?? {},
} as JsonObject;
updateDetectors(nextDetectors); updateDetectors(nextDetectors);
}; };