@@ -39,6 +39,8 @@ export const Preview: FC = () => {
3939 const $setError = useStore ( ( state ) => state . setError ) ;
4040 const $parameters = useStore ( ( state ) => state . parameters ) ;
4141 const $setParameters = useStore ( ( state ) => state . setParameters ) ;
42+ const $form = useStore ( ( state ) => state . form ) ;
43+ const $resetForm = useStore ( ( state ) => state . resetForm ) ;
4244
4345 const [ debouncedCode , isDebouncing ] = useDebouncedValue ( $code , 1000 ) ;
4446 const [ output , setOutput ] = useState < PreviewOutput | null > ( ( ) => null ) ;
@@ -77,9 +79,12 @@ export const Preview: FC = () => {
7779
7880 const getOutput = async ( ) => {
7981 try {
80- const rawOutput = await window . go_preview ?.( {
81- "main.tf" : debouncedCode ,
82- } ) ;
82+ const rawOutput = await window . go_preview ?.(
83+ {
84+ "main.tf" : debouncedCode ,
85+ } ,
86+ $form ,
87+ ) ;
8388
8489 if ( rawOutput === undefined ) {
8590 console . error ( "Something went wrong" ) ;
@@ -90,7 +95,7 @@ export const Preview: FC = () => {
9095 const errors = outputToDiagnostics ( output ) ;
9196 $setError ( errors ) ;
9297
93- if ( errors . length === 0 ) {
98+ if ( output . diags . length === 0 ) {
9499 $setParameters ( output . output ?. Parameters ?? [ ] ) ;
95100 }
96101 }
@@ -118,7 +123,7 @@ export const Preview: FC = () => {
118123 } ;
119124
120125 getOutput ( ) ;
121- } , [ debouncedCode , $setError , $wasmState , $setParameters ] ) ;
126+ } , [ debouncedCode , $setError , $wasmState , $setParameters , $form ] ) ;
122127
123128 return (
124129 < Tabs . Root
@@ -206,7 +211,9 @@ export const Preview: FC = () => {
206211 ) : null }
207212 </ AnimatePresence >
208213 </ div >
209- < Button variant = "destructive" > Reset form</ Button >
214+ < Button variant = "destructive" onClick = { $resetForm } >
215+ Reset form
216+ </ Button >
210217 </ div >
211218 }
212219 { ! output ? (
@@ -592,32 +599,7 @@ const FormElement: FC<FormElementProps> = ({ parameter }) => {
592599 value = { value }
593600 autofill = { false }
594601 onChange = { onValueChange }
602+ disabled = { parameter . styling . disabled }
595603 />
596604 ) ;
597-
598- // if (parameter.form_type === ParameterFormType.ParameterFormTypeInput) {
599- // return (
600- // <Input
601- // onChange={(e) => onValueChange(e.target.value)}
602- // id={parameter.name}
603- // value={value}
604- // />
605- // );
606- // }
607- // if (parameter.form_type === ParameterFormType.ParameterFormTypeRadio) {
608- // return (
609- // <RadioGroup value={value} onValueChange={onValueChange}>
610- // {parameter.options
611- // .filter((o) => o !== null)
612- // .map((o, index) => (
613- // <div className="flex items-center gap-2" key={index}>
614- // <RadioGroupItem value={o.value.value} title={"foo"} />
615- // <p className="text-content-primary text-sm">{o.name}</p>
616- // </div>
617- // ))}
618- // </RadioGroup>
619- // );
620- // }
621-
622- // return null;
623605} ;
0 commit comments