From 6977ed06d79a401f5741a567969864b1952154af Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Thu, 22 Dec 2022 09:02:33 +0000 Subject: [PATCH] expand changeset and use accordian for examples Signed-off-by: Brian Fletcher --- .changeset/metal-nails-punch.md | 66 ++++++++++++++++++- .../components/ActionsPage/ActionsPage.tsx | 42 +++++++----- 2 files changed, 91 insertions(+), 17 deletions(-) diff --git a/.changeset/metal-nails-punch.md b/.changeset/metal-nails-punch.md index 07265d1343..a34c340c0a 100644 --- a/.changeset/metal-nails-punch.md +++ b/.changeset/metal-nails-punch.md @@ -2,4 +2,68 @@ '@backstage/plugin-scaffolder-backend': patch --- -Changes to provide examples alongside scaffolder task actions. +This patch adds changes to provide examples alongside scaffolder task actions. + +The `createTemplateAction` function now takes a list of examples e.g. + +```typescript +const actionExamples = [ + { + description: 'Example 1', + example: yaml.stringify({ + steps: [ + { + action: 'test:action', + id: 'test', + input: { + input1: 'value', + }, + }, + ], + }), + }, +]; + +export function createTestAction() { + return createTemplateAction({ + id: 'test:action', + examples: [ + { + description: 'Example 1', + examples: actionExamples + } + ], + ..., + }); +``` + +These examples can be retrieved later from the api. + +```bash +curl http://localhost:7007/api/scaffolder/v2/actions +``` + +```json +[ + { + "id": "test:action", + "examples": [ + { + "description": "Example 1", + "example": "steps:\n - action: test:action\n id: test\n input:\n input1: value\n" + } + ], + "schema": { + "input": { + "type": "object", + "properties": { + "input1": { + "title": "Input 1", + "type": "string" + } + } + } + } + } +] +``` diff --git a/plugins/scaffolder/src/components/ActionsPage/ActionsPage.tsx b/plugins/scaffolder/src/components/ActionsPage/ActionsPage.tsx index 7a16337d09..234ba1951f 100644 --- a/plugins/scaffolder/src/components/ActionsPage/ActionsPage.tsx +++ b/plugins/scaffolder/src/components/ActionsPage/ActionsPage.tsx @@ -29,9 +29,13 @@ import { TableRow, Grid, makeStyles, + Accordion, + AccordionSummary, + AccordionDetails, } from '@material-ui/core'; import { JSONSchema7, JSONSchema7Definition } from 'json-schema'; import classNames from 'classnames'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import { useApi } from '@backstage/core-plugin-api'; import { @@ -209,22 +213,28 @@ export const ActionsPage = () => { )} {action.examples && ( - - Examples - - + + }> + Examples + + + + + + + )} );