Update tech radar docs on using an external datasource
Signed-off-by: Joost Hofman <joost.hofman@ah.nl>
This commit is contained in:
@@ -77,12 +77,43 @@ 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<TechRadarLoaderResponse> {
|
||||
@@ -91,8 +122,8 @@ 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
|
||||
|
||||
return data;
|
||||
// Need a converter for the Date object
|
||||
return convertTechRadarData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,4 +159,4 @@ You can use the `svgProps` option to pass custom React props to the `<svg>` elem
|
||||
|
||||
### How do I support multiple radars
|
||||
|
||||
The `TechRadarPage` and `TechRadarComponent` components both take an optional `id` prop which is subsequently passed to the `load` method of the API to distinguish which radar's data to load.
|
||||
The `TechRadarPage` and `TechRadarComponent` components both take an optional `id` prop which is subsequently passed to the `load` method of the API to distinguish which radar's data to load.
|
||||
Reference in New Issue
Block a user