From 950e080a2c52c6294630f0ffd1410b0e45b50a8d Mon Sep 17 00:00:00 2001
From: pianist <26953709+Pianist038801@users.noreply.github.com>
Date: Thu, 16 Sep 2021 10:27:14 -0700
Subject: [PATCH] fix: repopulate struct input fields on relaunch form (#201)

Signed-off-by: Pianist038801 <steven@union.ai>

Co-authored-by: Pianist038801 <steven@union.ai>
---
 src/components/Launch/LaunchForm/StructInput.tsx | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/components/Launch/LaunchForm/StructInput.tsx b/src/components/Launch/LaunchForm/StructInput.tsx
index fd27c327c..7ef9c91e7 100644
--- a/src/components/Launch/LaunchForm/StructInput.tsx
+++ b/src/components/Launch/LaunchForm/StructInput.tsx
@@ -53,12 +53,6 @@ export const StructInput: React.FC<InputProps> = props => {
     const hasError = !!error;
     const helperText = hasError ? error : props.helperText;
 
-    const [paramData, setParamData] = useState({});
-    const onFormChange = ({ formData }, e) => {
-        onChange(JSON.stringify(formData));
-        setParamData(formData);
-    };
-
     let jsonFormRenderable = false;
     let parsedJson: PrimitiveType = {};
 
@@ -81,6 +75,15 @@ export const StructInput: React.FC<InputProps> = props => {
         }
     }
 
+    const [paramData, setParamData] = useState(
+        jsonFormRenderable ? JSON.parse(value as string) : {}
+    );
+
+    const onFormChange = ({ formData }, e) => {
+        onChange(JSON.stringify(formData));
+        setParamData(formData);
+    };
+
     return jsonFormRenderable ? (
         <MuiThemeProvider theme={muiTheme}>
             <Card>