From 8d9eb22ef06326ca6858c27944fb2774ae3dd459 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 Co-authored-by: Pianist038801 Signed-off-by: Jason Porter --- 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 = 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 = props => { } } + const [paramData, setParamData] = useState( + jsonFormRenderable ? JSON.parse(value as string) : {} + ); + + const onFormChange = ({ formData }, e) => { + onChange(JSON.stringify(formData)); + setParamData(formData); + }; + return jsonFormRenderable ? (