mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-23 16:48:23 +03:00
consolidate utils
This commit is contained in:
parent
8cb3575100
commit
a48304d3a2
@ -51,7 +51,7 @@ import {
|
|||||||
buildOverrides,
|
buildOverrides,
|
||||||
sanitizeSectionData as sharedSanitizeSectionData,
|
sanitizeSectionData as sharedSanitizeSectionData,
|
||||||
requiresRestartForOverrides as sharedRequiresRestartForOverrides,
|
requiresRestartForOverrides as sharedRequiresRestartForOverrides,
|
||||||
} from "@/utils/configSaveUtil";
|
} from "@/utils/configUtil";
|
||||||
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
||||||
import { useRestart } from "@/api/ws";
|
import { useRestart } from "@/api/ws";
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { ConfigSection } from "./BaseSection";
|
import { ConfigSection } from "./BaseSection";
|
||||||
import type { BaseSectionProps, SectionConfig } from "./BaseSection";
|
import type { BaseSectionProps, SectionConfig } from "./BaseSection";
|
||||||
import { getSectionConfig } from "@/utils/sectionConfigsUtils";
|
import { getSectionConfig } from "@/utils/configUtil";
|
||||||
|
|
||||||
export type ConfigSectionTemplateProps = BaseSectionProps & {
|
export type ConfigSectionTemplateProps = BaseSectionProps & {
|
||||||
sectionKey: string;
|
sectionKey: string;
|
||||||
|
|||||||
@ -84,7 +84,7 @@ import axios from "axios";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { mutate } from "swr";
|
import { mutate } from "swr";
|
||||||
import { RJSFSchema } from "@rjsf/utils";
|
import { RJSFSchema } from "@rjsf/utils";
|
||||||
import { prepareSectionSavePayload } from "@/utils/configSaveUtil";
|
import { prepareSectionSavePayload } from "@/utils/configUtil";
|
||||||
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
||||||
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
||||||
import { useRestart } from "@/api/ws";
|
import { useRestart } from "@/api/ws";
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import get from "lodash/get";
|
|||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "lodash/cloneDeep";
|
||||||
import unset from "lodash/unset";
|
import unset from "lodash/unset";
|
||||||
import isEqual from "lodash/isEqual";
|
import isEqual from "lodash/isEqual";
|
||||||
|
import mergeWith from "lodash/mergeWith";
|
||||||
import { isJsonObject } from "@/lib/utils";
|
import { isJsonObject } from "@/lib/utils";
|
||||||
import { applySchemaDefaults } from "@/lib/config-schema";
|
import { applySchemaDefaults } from "@/lib/config-schema";
|
||||||
import { normalizeConfigValue } from "@/hooks/use-config-override";
|
import { normalizeConfigValue } from "@/hooks/use-config-override";
|
||||||
@ -16,7 +17,6 @@ import {
|
|||||||
getEffectiveDefaultsForSection,
|
getEffectiveDefaultsForSection,
|
||||||
sanitizeOverridesForSection,
|
sanitizeOverridesForSection,
|
||||||
} from "@/components/config-form/sections/section-special-cases";
|
} from "@/components/config-form/sections/section-special-cases";
|
||||||
import { getSectionConfig } from "@/utils/sectionConfigsUtils";
|
|
||||||
import type { RJSFSchema } from "@rjsf/utils";
|
import type { RJSFSchema } from "@rjsf/utils";
|
||||||
import type { FrigateConfig } from "@/types/frigateConfig";
|
import type { FrigateConfig } from "@/types/frigateConfig";
|
||||||
import type {
|
import type {
|
||||||
@ -24,6 +24,8 @@ import type {
|
|||||||
JsonObject,
|
JsonObject,
|
||||||
JsonValue,
|
JsonValue,
|
||||||
} from "@/types/configForm";
|
} from "@/types/configForm";
|
||||||
|
import type { SectionConfig } from "../components/config-form/sections/BaseSection";
|
||||||
|
import { sectionConfigs } from "../components/config-form/sectionConfigs";
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// cameraUpdateTopicMap — maps config section paths to MQTT/WS update topics
|
// cameraUpdateTopicMap — maps config section paths to MQTT/WS update topics
|
||||||
@ -397,3 +399,32 @@ export function prepareSectionSavePayload(opts: {
|
|||||||
pendingDataKey,
|
pendingDataKey,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mergeSectionConfig = (
|
||||||
|
base: SectionConfig | undefined,
|
||||||
|
overrides: Partial<SectionConfig> | undefined,
|
||||||
|
): SectionConfig =>
|
||||||
|
mergeWith({}, base ?? {}, overrides ?? {}, (objValue, srcValue, key) => {
|
||||||
|
if (Array.isArray(objValue) || Array.isArray(srcValue)) {
|
||||||
|
return srcValue ?? objValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key === "uiSchema" && srcValue !== undefined) {
|
||||||
|
return srcValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
export function getSectionConfig(
|
||||||
|
sectionKey: string,
|
||||||
|
level: "global" | "camera",
|
||||||
|
): SectionConfig {
|
||||||
|
const entry = sectionConfigs[sectionKey];
|
||||||
|
if (!entry) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const overrides = level === "global" ? entry.global : entry.camera;
|
||||||
|
return mergeSectionConfig(entry.base, overrides);
|
||||||
|
}
|
||||||
@ -1,32 +0,0 @@
|
|||||||
import mergeWith from "lodash/mergeWith";
|
|
||||||
import type { SectionConfig } from "../components/config-form/sections/BaseSection";
|
|
||||||
import { sectionConfigs } from "../components/config-form/sectionConfigs";
|
|
||||||
|
|
||||||
const mergeSectionConfig = (
|
|
||||||
base: SectionConfig | undefined,
|
|
||||||
overrides: Partial<SectionConfig> | undefined,
|
|
||||||
): SectionConfig =>
|
|
||||||
mergeWith({}, base ?? {}, overrides ?? {}, (objValue, srcValue, key) => {
|
|
||||||
if (Array.isArray(objValue) || Array.isArray(srcValue)) {
|
|
||||||
return srcValue ?? objValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key === "uiSchema" && srcValue !== undefined) {
|
|
||||||
return srcValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
export function getSectionConfig(
|
|
||||||
sectionKey: string,
|
|
||||||
level: "global" | "camera",
|
|
||||||
): SectionConfig {
|
|
||||||
const entry = sectionConfigs[sectionKey];
|
|
||||||
if (!entry) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const overrides = level === "global" ? entry.global : entry.camera;
|
|
||||||
return mergeSectionConfig(entry.base, overrides);
|
|
||||||
}
|
|
||||||
@ -5,7 +5,7 @@ import { ConfigSectionTemplate } from "@/components/config-form/sections";
|
|||||||
import type { PolygonType } from "@/types/canvas";
|
import type { PolygonType } from "@/types/canvas";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import type { ConfigSectionData } from "@/types/configForm";
|
import type { ConfigSectionData } from "@/types/configForm";
|
||||||
import { getSectionConfig } from "@/utils/sectionConfigsUtils";
|
import { getSectionConfig } from "@/utils/configUtil";
|
||||||
import { useDocDomain } from "@/hooks/use-doc-domain";
|
import { useDocDomain } from "@/hooks/use-doc-domain";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { LuExternalLink } from "react-icons/lu";
|
import { LuExternalLink } from "react-icons/lu";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user