Ensure detections are cleared when limit box is unchecked (#12412)

This commit is contained in:
Josh Hawkins 2024-07-12 10:07:01 -05:00 committed by GitHub
parent 2ebd2dfcc7
commit e7ec014502
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -110,33 +110,36 @@ export default function CameraSettingsView({
if (!isChecked) { if (!isChecked) {
form.reset({ form.reset({
alerts_zones: watchedAlertsZones, alerts_zones: watchedAlertsZones,
detections_zones: detections_zones: [],
cameraConfig?.review.detections.required_zones || [],
}); });
} }
setChangedValue(true); setChangedValue(true);
setSelectDetections(isChecked as boolean); setSelectDetections(isChecked as boolean);
}, },
[watchedAlertsZones, cameraConfig, form], // we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
[watchedAlertsZones],
); );
const saveToConfig = useCallback( const saveToConfig = useCallback(
async ( async (
{ alerts_zones, detections_zones }: CameraReviewSettingsValueType, // values submitted via the form { alerts_zones, detections_zones }: CameraReviewSettingsValueType, // values submitted via the form
) => { ) => {
const alertQueries = [...alerts_zones] const createQuery = (zones: string[], type: "alerts" | "detections") =>
.map( zones.length
(zone) => ? zones
`&cameras.${selectedCamera}.review.alerts.required_zones=${zone}`, .map(
) (zone) =>
.join(""); `&cameras.${selectedCamera}.review.${type}.required_zones=${zone}`,
)
.join("")
: cameraConfig?.review[type]?.required_zones &&
cameraConfig?.review[type]?.required_zones.length > 0
? `&cameras.${selectedCamera}.review.${type}.required_zones`
: "";
const detectionQueries = [...detections_zones] const alertQueries = createQuery(alerts_zones, "alerts");
.map( const detectionQueries = createQuery(detections_zones, "detections");
(zone) =>
`&cameras.${selectedCamera}.review.detections.required_zones=${zone}`,
)
.join("");
axios axios
.put(`config/set?${alertQueries}${detectionQueries}`, { .put(`config/set?${alertQueries}${detectionQueries}`, {
@ -167,7 +170,7 @@ export default function CameraSettingsView({
setIsLoading(false); setIsLoading(false);
}); });
}, },
[updateConfig, setIsLoading, selectedCamera], [updateConfig, setIsLoading, selectedCamera, cameraConfig],
); );
const onCancel = useCallback(() => { const onCancel = useCallback(() => {
@ -188,7 +191,9 @@ export default function CameraSettingsView({
setSelectDetections( setSelectDetections(
!!cameraConfig?.review.detections.required_zones?.length, !!cameraConfig?.review.detections.required_zones?.length,
); );
}, [removeMessage, selectedCamera, setUnsavedChanges, form, cameraConfig]); // we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [removeMessage, selectedCamera, setUnsavedChanges, cameraConfig]);
useEffect(() => { useEffect(() => {
onCancel(); onCancel();