Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show field types on json launch form #199

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we have other fields but don't have additionalProperties?
Just to make sure what this means on my end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'additionalProperties' is all I can see from the api response for now. If there is anything more, we can cope with it later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can do that later.

}

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