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 = {
base: {
sectionDocs: "/configuration/object_detectors",
restartRequired: [],
fieldOrder: [],
advancedFields: [],
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;
}

View File

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