From 90426cfba859667239efbdae40da442c5364f67b Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Mon, 28 Sep 2026 09:04:04 -0500 Subject: [PATCH] fix model card state and camera counts in the models editor Model cards were keyed by index, so deleting one handed its state (such as the selected model source tab) to the card after it. Cards are keyed by scene now, which is unique per model. The camera count on each card also ignored the backend's fallback to the `all` model, so a camera whose detect scene had no model of its own wasn't counted anywhere. It's counted under `all` now, which also feeds the recommended detector count. --- .../config-form/theme/fields/ModelsField.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/web/src/components/config-form/theme/fields/ModelsField.tsx b/web/src/components/config-form/theme/fields/ModelsField.tsx index f03f3f494b..83342a0a05 100644 --- a/web/src/components/config-form/theme/fields/ModelsField.tsx +++ b/web/src/components/config-form/theme/fields/ModelsField.tsx @@ -169,20 +169,23 @@ export function ModelsField(props: FieldProps) { [savedModels], ); - // a model serves the cameras naming its scene, plus every camera that names - // no scene at all when it is the "all" model + // a model serves the cameras naming its scene, and like the backend, the + // "all" model also serves every camera whose scene has no model of its own const cameraCountForScene = useCallback( (scene: string | undefined): number => { if (!cameras) { return 0; } + const modelScenes = new Set(models.map((model) => model.scene ?? "all")); + return Object.values(cameras).filter((camera) => { - const cameraScene = camera?.detect?.scene; - return cameraScene ? cameraScene === scene : scene === "all"; + const cameraScene = camera?.detect?.scene ?? "all"; + const servedBy = modelScenes.has(cameraScene) ? cameraScene : "all"; + return servedBy === (scene ?? "all"); }).length; }, - [cameras], + [cameras, models], ); const claimedByOtherModels = useCallback( @@ -314,7 +317,9 @@ export function ModelsField(props: FieldProps) { ); return ( - + // keyed by scene, which is unique per model, so deleting a card + // doesn't hand its state (such as the model source tab) to the next +