import { css } from '@emotion/css'; import { FormEvent, useState, ChangeEvent } from 'react'; import { DataFrameSchema, FieldSchema, GrafanaTheme2 } from '@grafana/data'; import { useStyles2, TextArea, InlineField, Input, FieldSet, InlineSwitch } from '@grafana/ui'; type Config = Record; interface SchemaFormProps { config: Config; schema: DataFrameSchema; onChange: (config: Config) => void; } const renderInput = (field: FieldSchema, onChange: SchemaFormProps['onChange'], config: SchemaFormProps['config']) => { switch (field.type) { case 'number': return ( ) => { const newValue = e.currentTarget.valueAsNumber; onChange({ ...config, [field.name]: newValue }); }} /> ); case 'boolean': return ( { onChange({ ...config, [field.name]: !config[field.name] }); }} /> ); default: return ( ) => { const newValue = e.target.value; onChange({ ...config, [field.name]: newValue }); }} /> ); } }; const getStyles = (theme: GrafanaTheme2) => { return { jsonView: css({ marginBottom: theme.spacing(1), }), }; }; export const SimulationSchemaForm = ({ config, schema, onChange }: SchemaFormProps) => { const [jsonView, setJsonView] = useState(false); const styles = useStyles2(getStyles); const onUpdateTextArea = (event: FormEvent) => { const element = event.currentTarget; onChange(JSON.parse(element.value)); }; return (
setJsonView(!jsonView)} /> {jsonView ? (