From 584f1a04f5a1cf739e7aa8330c8229e62ce04324 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Mon, 8 Mar 2021 14:08:17 +0100 Subject: [PATCH] Render description and oneOf fields Signed-off-by: Johan Haals --- plugins/scaffolder/package.json | 1 + .../components/ActionsPage/ActionsPage.tsx | 38 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/plugins/scaffolder/package.json b/plugins/scaffolder/package.json index 53716fd1dc..d0dc0d70d7 100644 --- a/plugins/scaffolder/package.json +++ b/plugins/scaffolder/package.json @@ -43,6 +43,7 @@ "@rjsf/core": "^2.4.0", "@rjsf/material-ui": "^2.4.0", "classnames": "^2.2.6", + "json-schema": "^0.3.0", "git-url-parse": "^11.4.4", "humanize-duration": "^3.25.1", "luxon": "^1.25.0", diff --git a/plugins/scaffolder/src/components/ActionsPage/ActionsPage.tsx b/plugins/scaffolder/src/components/ActionsPage/ActionsPage.tsx index a9f96d8d09..07d1bd2ec4 100644 --- a/plugins/scaffolder/src/components/ActionsPage/ActionsPage.tsx +++ b/plugins/scaffolder/src/components/ActionsPage/ActionsPage.tsx @@ -37,12 +37,9 @@ import { makeStyles, } from '@material-ui/core'; import { JSONSchema } from '@backstage/catalog-model'; +import { JSONSchema7Definition } from 'json-schema'; const useStyles = makeStyles(theme => ({ - table: { - // minWidth: 650, - }, - code: { fontFamily: 'Menlo, monospaced', padding: theme.spacing(1), @@ -96,7 +93,8 @@ export const ActionsPage = () => { const required = input.required ? input.required : []; return Object.entries(properties).map(entry => { - const [key, props] = entry; + const [key] = entry; + const props = (entry[0] as unknown) as JSONSchema; const isRequired = required.includes(key); const codeClassname = `${classes.code} ${ @@ -118,9 +116,12 @@ export const ActionsPage = () => { }; const renderTable = (input: JSONSchema) => { + if (!input.properties) { + return undefined; + } return ( - +
Name @@ -135,24 +136,43 @@ export const ActionsPage = () => { ); }; + const renderTables = (name: string, input?: JSONSchema7Definition[]) => { + if (!input) { + return undefined; + } + + return ( + <> + {name} + {input.map((i, index) => ( +
{renderTable((i as unknown) as JSONSchema)}
+ ))} + + ); + }; + const items = value?.map(action => { if (action.id.startsWith('legacy:')) { return undefined; } + + const oneOf = renderTables('oneOf', action.schema?.input?.oneOf); return ( - + {action.id} + {action.description} {action.schema?.input && ( - Input + Input {renderTable(action.schema.input)} + {oneOf} )} {action.schema?.output && ( - Output + Output {renderTable(action.schema.output)} )}