2026-01-23 17:23:52 +03:00
|
|
|
// Description Field Template
|
|
|
|
|
import type { DescriptionFieldProps } from "@rjsf/utils";
|
2026-01-31 17:50:24 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import { ConfigFormContext } from "@/types/configForm";
|
2026-01-23 17:23:52 +03:00
|
|
|
|
|
|
|
|
export function DescriptionFieldTemplate(props: DescriptionFieldProps) {
|
|
|
|
|
const { description, id } = props;
|
2026-01-31 17:50:24 +03:00
|
|
|
const formContext = (
|
|
|
|
|
props as { registry?: { formContext?: ConfigFormContext } }
|
|
|
|
|
).registry?.formContext;
|
2026-01-23 17:23:52 +03:00
|
|
|
|
2026-01-31 17:50:24 +03:00
|
|
|
const isCameraLevel = formContext?.level === "camera";
|
|
|
|
|
const sectionI18nPrefix = formContext?.sectionI18nPrefix;
|
2026-01-31 19:18:38 +03:00
|
|
|
const effectiveNamespace = isCameraLevel ? "config/cameras" : "config/global";
|
2026-01-31 17:50:24 +03:00
|
|
|
|
2026-01-31 19:18:38 +03:00
|
|
|
const { t, i18n } = useTranslation([effectiveNamespace, "common"]);
|
2026-01-31 17:50:24 +03:00
|
|
|
|
|
|
|
|
let resolvedDescription = description;
|
|
|
|
|
|
2026-01-31 18:58:10 +03:00
|
|
|
// Support nested keys for both camera-level and consolidated global namespace
|
|
|
|
|
if (sectionI18nPrefix && effectiveNamespace) {
|
2026-01-31 17:50:24 +03:00
|
|
|
const descriptionKey = `${sectionI18nPrefix}.description`;
|
|
|
|
|
if (i18n.exists(descriptionKey, { ns: effectiveNamespace })) {
|
|
|
|
|
resolvedDescription = t(descriptionKey, { ns: effectiveNamespace });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!resolvedDescription) {
|
2026-01-23 17:23:52 +03:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-02-01 05:44:53 +03:00
|
|
|
<span id={id} className="text-sm text-muted-foreground">
|
2026-01-31 17:50:24 +03:00
|
|
|
{resolvedDescription}
|
2026-02-01 05:44:53 +03:00
|
|
|
</span>
|
2026-01-23 17:23:52 +03:00
|
|
|
);
|
|
|
|
|
}
|