mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-10 10:33:11 +03:00
consolidate utils
This commit is contained in:
parent
8cb3575100
commit
a48304d3a2
@ -51,7 +51,7 @@ import {
|
||||
buildOverrides,
|
||||
sanitizeSectionData as sharedSanitizeSectionData,
|
||||
requiresRestartForOverrides as sharedRequiresRestartForOverrides,
|
||||
} from "@/utils/configSaveUtil";
|
||||
} from "@/utils/configUtil";
|
||||
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
||||
import { useRestart } from "@/api/ws";
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { useMemo } from "react";
|
||||
import { ConfigSection } from "./BaseSection";
|
||||
import type { BaseSectionProps, SectionConfig } from "./BaseSection";
|
||||
import { getSectionConfig } from "@/utils/sectionConfigsUtils";
|
||||
import { getSectionConfig } from "@/utils/configUtil";
|
||||
|
||||
export type ConfigSectionTemplateProps = BaseSectionProps & {
|
||||
sectionKey: string;
|
||||
|
||||
@ -84,7 +84,7 @@ import axios from "axios";
|
||||
import { toast } from "sonner";
|
||||
import { mutate } from "swr";
|
||||
import { RJSFSchema } from "@rjsf/utils";
|
||||
import { prepareSectionSavePayload } from "@/utils/configSaveUtil";
|
||||
import { prepareSectionSavePayload } from "@/utils/configUtil";
|
||||
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
||||
import RestartDialog from "@/components/overlay/dialog/RestartDialog";
|
||||
import { useRestart } from "@/api/ws";
|
||||
|
||||
@ -8,6 +8,7 @@ import get from "lodash/get";
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import unset from "lodash/unset";
|
||||
import isEqual from "lodash/isEqual";
|
||||
import mergeWith from "lodash/mergeWith";
|
||||
import { isJsonObject } from "@/lib/utils";
|
||||
import { applySchemaDefaults } from "@/lib/config-schema";
|
||||
import { normalizeConfigValue } from "@/hooks/use-config-override";
|
||||
@ -16,7 +17,6 @@ import {
|
||||
getEffectiveDefaultsForSection,
|
||||
sanitizeOverridesForSection,
|
||||
} from "@/components/config-form/sections/section-special-cases";
|
||||
import { getSectionConfig } from "@/utils/sectionConfigsUtils";
|
||||
import type { RJSFSchema } from "@rjsf/utils";
|
||||
import type { FrigateConfig } from "@/types/frigateConfig";
|
||||
import type {
|
||||
@ -24,6 +24,8 @@ import type {
|
||||
JsonObject,
|
||||
JsonValue,
|
||||
} 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
|
||||
@ -397,3 +399,32 @@ export function prepareSectionSavePayload(opts: {
|
||||
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 { Badge } from "@/components/ui/badge";
|
||||
import type { ConfigSectionData } from "@/types/configForm";
|
||||
import { getSectionConfig } from "@/utils/sectionConfigsUtils";
|
||||
import { getSectionConfig } from "@/utils/configUtil";
|
||||
import { useDocDomain } from "@/hooks/use-doc-domain";
|
||||
import { Link } from "react-router-dom";
|
||||
import { LuExternalLink } from "react-icons/lu";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user