From 17bb338c2ccfbcef1b721ec98f902f9a033c3f19 Mon Sep 17 00:00:00 2001 From: Joost Hofman Date: Wed, 6 Jul 2022 11:39:02 +0200 Subject: [PATCH] Simplify the return statement Signed-off-by: Joost Hofman --- plugins/tech-radar/README.md | 45 +++++++++--------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/plugins/tech-radar/README.md b/plugins/tech-radar/README.md index 824f098104..d2d5e99486 100644 --- a/plugins/tech-radar/README.md +++ b/plugins/tech-radar/README.md @@ -77,43 +77,12 @@ When defining the radar entries you can see the available properties on the file The `TechRadar` plugin uses the `techRadarApiRef` to get a client which implements the `TechRadarApi` interface. The default sample one is located [here](https://github.com/backstage/backstage/blob/master/plugins/tech-radar/src/sample.ts). To load your own data, you'll need to provide a class that implements the `TechRadarApi` and override the `techRadarApiRef` in the `app/src/apis.ts`. -```ts -// app/src/lib/DataConverter.ts -import { TechRadarLoaderResponse } from '@backstage/plugin-tech-radar'; - -export function convertTechRadarData(json: any): TechRadarLoaderResponse { - const { entries, rings, quadrants } = json; - - const normalizedEntries = entries.map(entry => { - // convert date of timeline - const timelineEntries = entry.timeline.map(timeline => { - return { - ...timeline, - date: new Date(timeline.date), - }; - }); - - return { - ...entry, - timeline: timelineEntries, - }; - }); - - return { - entries: normalizedEntries, - rings, - quadrants, - }; -} -``` - ```ts // app/src/lib/MyClient.ts import { TechRadarApi, TechRadarLoaderResponse, } from '@backstage/plugin-tech-radar'; -import { convertTechRadarData } from './DataConverter'; export class MyOwnClient implements TechRadarApi { async load(id: string | undefined): Promise { @@ -121,9 +90,17 @@ export class MyOwnClient implements TechRadarApi { const data = await fetch('https://mydata.json').then(res => res.json()); - // maybe you'll need to do some data transformation here to make it look like TechRadarLoaderResponse - // Need a converter for the Date object - return convertTechRadarData(data); + // For example, this converts the timeline dates into date objects + return { + ...data, + entries: data.entries.map(entry => ({ + ...entry, + timeline: entry.timeline.map(timeline => ({ + ...timeline, + date: new Date(timeline.date), + })) + })) + } } }