Skip to content

Commit

Permalink
fix: show field types on json launch form (flyteorg#199)
Browse files Browse the repository at this point in the history
Signed-off-by: Pianist038801 <[email protected]>

Co-authored-by: Pianist038801 <[email protected]>
  • Loading branch information
Pianist038801 and Pianist038801 authored Sep 13, 2021
1 parent 67dd183 commit a42b9f8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/components/Launch/LaunchForm/StructInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputProps> = props => {
const {
Expand Down Expand Up @@ -55,7 +74,10 @@ export const StructInput: React.FC<InputProps> = props => {
]
);

if (parsedJson) jsonFormRenderable = true;
if (parsedJson) {
parsedJson = formatJson(parsedJson);
jsonFormRenderable = true;
}
}
}

Expand Down

0 comments on commit a42b9f8

Please sign in to comment.