chore: adding documentation for loading data

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2021-06-03 10:54:06 +02:00
parent 9b4b405095
commit 313071b974
3 changed files with 37 additions and 29 deletions
+9
View File
@@ -34,6 +34,13 @@ import {
GraphQLEndpoints,
} from '@backstage/plugin-graphiql';
import { techRadarApiRef, TechRadarApi } from '@backstage/plugin-tech-radar';
class MyOwnClient implements TechRadarApi {
async load() {
throw new Error('blah');
}
}
export const apis: AnyApiFactory[] = [
createApiFactory({
api: scmIntegrationsApiRef,
@@ -61,4 +68,6 @@ export const apis: AnyApiFactory[] = [
}),
createApiFactory(costInsightsApiRef, new ExampleCostInsightsClient()),
createApiFactory(),
];
+26 -27
View File
@@ -72,36 +72,35 @@ export interface TechRadarPageProps {
### How do I load in my own data?
It's simple, you can pass through a `getData` prop which expects a `Promise<TechRadarLoaderResponse>` signature.
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`.
Here's an example:
```ts
// app/src/lib/MyClient.ts
import {
TechRadarApi,
TechRadarLoaderResponse,
} from '@backstage/plugin-tech-radar';
```tsx
const getHardCodedData = () =>
Promise.resolve({
quadrants: [{ id: 'infrastructure', name: 'Infrastructure' }],
rings: [{ id: 'use', name: 'USE', color: '#93c47d' }],
entries: [
{
url: '#',
key: 'github-actions',
id: 'github-actions',
title: 'GitHub Actions',
quadrant: 'infrastructure',
timeline: [
{
moved: 0,
ringId: 'use',
date: new Date('2020-08-06'),
description:
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat',
},
],
},
],
});
class MyOwnClient implements TechRadarApi {
async load(): Promise<TechRadarLoaderResponse> {
const data = await fetch('https://mydata.json').then(res => res.json());
<TechRadarComponent width={1400} height={800} getData={getHardCodedData} />;
// maybe you'll need to do some data transformation here to make it look like TechRadarLoaderResponse
return data;
}
}
// app/src/apis.ts
import { MyOwnClient } from './lib/MyClient';
import { techRadarApiRef } from '@backstage/plugin-tech-radar';
export const apis: AnyApiFactory[] = [
/*
...
*/
createApiFactory(techRadarApiRef, new MyOwnClient()),
];
```
### How do I write tests?
+2 -2
View File
@@ -165,8 +165,8 @@ entries.push({
],
url: '#',
key: 'github-actions',
id: 'github-actiosns',
title: 'GitHub Acssstions',
id: 'github-actions',
title: 'GitHub Actions',
quadrant: 'infrastructure',
});