Skip to content

Commit

Permalink
feat(techradar-plugin) add techradar blip history backend support (#3191
Browse files Browse the repository at this point in the history
)

* add techradar entry history data structure

* updated names and added changeset

* fix docs

Co-authored-by: Omer Farooq <17722640+o-farooq@users.noreply.github.com>
  • Loading branch information
o-farooq and o-farooq committed Nov 10, 2020
1 parent b420406 commit a906f20
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-impalas-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-tech-radar': minor
---

Added tech radar blip history backend support and normalized the data structure
12 changes: 9 additions & 3 deletions plugins/tech-radar/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ export interface RadarQuadrant {
export interface RadarEntry {
key: string; // react key
id: string;
moved: MovedState;
quadrant: RadarQuadrant;
ring: RadarRing;
quadrant: string;
title: string;
url: string;
timeline: Array<RadarEntrySnapshot>;
}

export interface RadarEntrySnapshot {
date: Date;
ringId: string;
description?: string;
moved?: MovedState;
}

/**
Expand Down
26 changes: 25 additions & 1 deletion plugins/tech-radar/src/components/RadarComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useAsync } from 'react-use';
import Radar from '../components/Radar';
import { TechRadarComponentProps, TechRadarLoaderResponse } from '../api';
import getSampleData from '../sampleData';
import { Entry } from '../utils/types';

const useTechRadarLoader = (props: TechRadarComponentProps) => {
const errorApi = useApi<ErrorApi>(errorApiRef);
Expand Down Expand Up @@ -47,6 +48,29 @@ const useTechRadarLoader = (props: TechRadarComponentProps) => {
const RadarComponent = (props: TechRadarComponentProps): JSX.Element => {
const { loading, error, value: data } = useTechRadarLoader(props);

const mapToEntries = (
loaderResponse: TechRadarLoaderResponse | undefined,
): Array<Entry> => {
return loaderResponse!.entries.map(entry => {
return {
id: entry.key,
quadrant: loaderResponse!.quadrants.find(q => q.id === entry.quadrant)!,
title: entry.title,
ring: loaderResponse!.rings.find(
r => r.id === entry.timeline[0].ringId,
)!,
history: entry.timeline.map(e => {
return {
date: e.date,
ring: loaderResponse!.rings.find(a => a.id === e.ringId)!,
description: e.description,
moved: e.moved,
};
}),
};
});
};

return (
<>
{loading && <Progress />}
Expand All @@ -55,7 +79,7 @@ const RadarComponent = (props: TechRadarComponentProps): JSX.Element => {
{...props}
rings={data!.rings}
quadrants={data!.quadrants}
entries={data!.entries}
entries={mapToEntries(data)}
/>
)}
</>
Expand Down
101 changes: 74 additions & 27 deletions plugins/tech-radar/src/sampleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,85 +35,132 @@ quadrants.push({ id: 'process', name: 'Process' });

const entries = new Array<RadarEntry>();
entries.push({
moved: 0,
ring: { id: 'use', name: 'USE', color: '#93c47d' },
timeline: [
{
moved: 0,
ringId: 'use',
date: new Date('2020-08-06'),
description:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
},
],
url: '#',
key: 'javascript',
id: 'javascript',
title: 'JavaScript',
quadrant: { id: 'languages', name: 'Languages' },
quadrant: 'languages',
});
entries.push({
moved: 0,
ring: { id: 'use', name: 'USE', color: '#93c47d' },
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',
},
],
url: '#',
key: 'typescript',
id: 'typescript',
title: 'TypeScript',
quadrant: { id: 'languages', name: 'Languages' },
quadrant: 'languages',
});
entries.push({
moved: 0,
ring: { id: 'use', name: 'USE', color: '#93c47d' },
timeline: [
{
moved: 0,
ringId: 'use',
date: new Date('2020-08-06'),
},
],
url: '#',
key: 'webpack',
id: 'webpack',
title: 'Webpack',
quadrant: { id: 'frameworks', name: 'Frameworks' },
quadrant: 'frameworks',
});
entries.push({
moved: 0,
ring: { id: 'use', name: 'USE', color: '#93c47d' },
timeline: [
{
moved: 0,
ringId: 'use',
date: new Date('2020-08-06'),
},
],
url: '#',
key: 'react',
id: 'react',
title: 'React',
quadrant: { id: 'frameworks', name: 'Frameworks' },
quadrant: 'frameworks',
});
entries.push({
moved: 0,
ring: { id: 'use', name: 'USE', color: '#93c47d' },
timeline: [
{
moved: 0,
ringId: 'use',
date: new Date('2020-08-06'),
},
],
url: '#',
key: 'code-reviews',
id: 'code-reviews',
title: 'Code Reviews',
quadrant: { id: 'process', name: 'Process' },
quadrant: 'process',
});
entries.push({
moved: 0,
timeline: [
{
moved: 0,
ringId: 'assess',
date: new Date('2020-08-06'),
},
],
url: '#',
key: 'mob-programming',
id: 'mob-programming',
title: 'Mob Programming',
quadrant: { id: 'process', name: 'Process' },
ring: { id: 'assess', name: 'ASSESS', color: '#fbdb84' },
quadrant: 'process',
});
entries.push({
moved: 0,
timeline: [
{
moved: 0,
ringId: 'use',
date: new Date('2020-08-06'),
},
],
url: '#',
key: 'docs-like-code',
id: 'docs-like-code',
title: 'Docs-like-code',
quadrant: { id: 'process', name: 'Process' },
ring: { id: 'use', name: 'USE', color: '#93c47d' },
quadrant: 'process',
});
entries.push({
moved: 0,
timeline: [
{
ringId: 'hold',
date: new Date('2020-08-06'),
},
],
url: '#',
key: 'force-push',
id: 'force-push',
title: 'Force push to master',
quadrant: { id: 'process', name: 'Process' },
ring: { id: 'hold', name: 'HOLD', color: '#93c47d' },
quadrant: 'process',
});
entries.push({
moved: 0,
ring: { id: 'use', name: 'USE', color: '#93c47d' },
timeline: [
{
ringId: 'use',
date: new Date('2020-08-06'),
},
],
url: '#',
key: 'github-actions',
id: 'github-actions',
title: 'GitHub Actions',
quadrant: { id: 'infrastructure', name: 'Infrastructure' },
quadrant: 'infrastructure',
});

export default function getSampleData(): Promise<TechRadarLoaderResponse> {
Expand Down
8 changes: 8 additions & 0 deletions plugins/tech-radar/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ export type Entry = {
// How this entry has recently moved; -1 for "down", +1 for "up", 0 for not moved
moved?: MovedState;
active?: boolean;
timeline?: Array<EntrySnapshot>;
};

export type EntrySnapshot = {
date: Date;
ring: Ring;
description?: string;
moved?: MovedState;
};

// The same as Entry except quadrant/ring are declared by their string ID instead of being the actual objects
Expand Down

0 comments on commit a906f20

Please sign in to comment.