From a42b9f8520fcd24dee752111e606ad9ae9bd88f5 Mon Sep 17 00:00:00 2001 From: pianist <26953709+Pianist038801@users.noreply.github.com> Date: Mon, 13 Sep 2021 17:45:55 +0200 Subject: [PATCH] fix: show field types on json launch form (#199) Signed-off-by: Pianist038801 Co-authored-by: Pianist038801 --- .../Launch/LaunchForm/StructInput.tsx | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components/Launch/LaunchForm/StructInput.tsx b/src/components/Launch/LaunchForm/StructInput.tsx index 6149a7cc78..fd27c327c4 100644 --- a/src/components/Launch/LaunchForm/StructInput.tsx +++ b/src/components/Launch/LaunchForm/StructInput.tsx @@ -21,6 +21,25 @@ muiTheme.typography.h5 = { fontWeight: 400 }; +const formatJson = data => { + const keys = Object.keys(data); + + if (keys.includes('title')) { + const { title, type, format } = data; + data['title'] = `${title} (${format ?? type})`; + if (!keys.includes('additionalProperties')) return data; + } + + keys.forEach(key => { + const item = data[`${key}`]; + if (typeof item === 'object') { + data = { ...data, [key]: formatJson(item) }; + } + }); + + return data; +}; + /** Handles rendering of the input component for a Struct */ export const StructInput: React.FC = props => { const { @@ -55,7 +74,10 @@ export const StructInput: React.FC = props => { ] ); - if (parsedJson) jsonFormRenderable = true; + if (parsedJson) { + parsedJson = formatJson(parsedJson); + jsonFormRenderable = true; + } } }