import { ADDITIONAL_PROPERTY_FLAG, FormContextType, getUiOptions, RJSFSchema, StrictRJSFSchema, WrapIfAdditionalTemplateProps, } from "@rjsf/utils"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { cn } from "@/lib/utils"; import { useTranslation } from "react-i18next"; import { LuTrash2 } from "react-icons/lu"; export function WrapIfAdditionalTemplate< T = unknown, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = FormContextType, >(props: WrapIfAdditionalTemplateProps) { const { classNames, style, children, disabled, id, label, displayLabel, onRemoveProperty, onKeyRenameBlur, readonly, required, schema, uiSchema, } = props; const { t } = useTranslation(["views/settings"]); const additional = ADDITIONAL_PROPERTY_FLAG in schema; if (!additional) { return (
{children}
); } const keyId = `${id}-key`; const keyLabel = t("configForm.additionalProperties.keyLabel", { ns: "views/settings", }); const valueLabel = t("configForm.additionalProperties.valueLabel", { ns: "views/settings", }); const keyPlaceholder = t("configForm.additionalProperties.keyPlaceholder", { ns: "views/settings", }); const removeLabel = t("configForm.additionalProperties.remove", { ns: "views/settings", }); const uiOptions = getUiOptions(uiSchema); const keyIsReadonly = uiOptions.additionalPropertyKeyReadonly === true; return (
{!keyIsReadonly && (
{displayLabel && } {keyIsReadonly ? (
{label}
) : ( )}
)}
{!keyIsReadonly && displayLabel && ( )}
{children}
{!keyIsReadonly && (
)}
); } export default WrapIfAdditionalTemplate;