Add an optional id prop and pass to load API

Signed-off-by: Andrew Shirley <andrew.shirley@sainsburys.co.uk>
This commit is contained in:
Andrew Shirley
2021-06-28 13:51:33 +01:00
parent d1030eb8bb
commit 846168da2c
6 changed files with 58 additions and 16 deletions
+7 -1
View File
@@ -82,7 +82,9 @@ import {
} from '@backstage/plugin-tech-radar';
class MyOwnClient implements TechRadarApi {
async load(): Promise<TechRadarLoaderResponse> {
async load(id: string | undefined): Promise<TechRadarLoaderResponse> {
// if needed id prop can be used to fetch the correct data
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
@@ -120,3 +122,7 @@ You can use the `svgProps` option to pass custom React props to the `<svg>` elem
// const { getByTestId } = render(...);
// expect(getByTestId('tech-radar-svg')).toBeInTheDocument();
```
### 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.