import React, { useState } from "react"; import { FormControl, FormDescription, FormItem, FormLabel, FormMessage, } from "@/src/components/ui/form"; import { Switch } from "@/src/components/ui/switch"; import { JSONSchemaEditor } from "@/src/components/JSONSchemaEditor"; type DatasetSchemaInputProps = { label: string; description?: string; value: string; initialValue?: string; onChange: (value: string) => void; disabled?: boolean; }; export const DatasetSchemaInput: React.FC = ({ label, description, value, initialValue, onChange, disabled = false, }) => { // Track if schema enforcement is enabled based on whether value is empty const [isEnabled, setIsEnabled] = useState(value !== ""); const handleToggle = (checked: boolean) => { setIsEnabled(checked); if (!checked) { // Clear schema when disabling onChange(""); } else if (value === "") { // Set default empty schema when enabling onChange( initialValue || JSON.stringify( { type: "object", properties: {}, required: [], additionalProperties: false, }, null, 2, ), ); } }; return (
{label}
{isEnabled ? "Enabled" : "Disabled"}
{description && {description}} {isEnabled && ( )}
); };