diff --git a/plugins/tech-radar/README.md b/plugins/tech-radar/README.md index d48cd969a8..ea3faf8e19 100644 --- a/plugins/tech-radar/README.md +++ b/plugins/tech-radar/README.md @@ -1,89 +1,120 @@ # @backstage/plugin-tech-radar -Screenshot of Tech Radar plugin +Screenshot of Tech Radar plugin The Backstage integration for the Tech Radar based on [Zalando's Tech Radar](https://opensource.zalando.com/tech-radar/) open sourced on [GitHub](https://github.com/zalando/tech-radar). This is used at [Spotify](https://spotify.github.io) for visualizing the official guidelines of different areas of software development such as languages, frameworks, infrastructure and processes. ## Purpose -Zalando explains it very well on their website: +Zalando has a fantastic description [on their website](https://opensource.zalando.com/tech-radar/): > The Tech Radar is a tool to inspire and support engineering teams at Zalando to pick the best technologies for new projects; it provides a platform to share knowledge and experience in technologies, to reflect on technology decisions and continuously evolve our technology landscape. Based on the pioneering work of ThoughtWorks, our Tech Radar sets out the changes in technologies that are interesting in software development — changes that we think our engineering teams should pay attention to and consider using in their projects. -It serves well for teams and companies of all sizes that want to have alignment and wish to visualize it. It scales well for companies who have dozens of different technologies in place. +It serves and scales well for teams and companies of all sizes that want to have alignment across dozens of technologies and visualize it in a simple way. ## Getting Started -In your installation, add the dependency to your Backstage installation: +The Tech Radar can be used in two ways: + +- **Simple (Recommended)** - This gives you an out-of-the-box Tech Radar experience. It lives on the `/tech-radar` URL of your Backstage installation, and you can set a variety of configuration directly in your `apis.ts`. +- **Advanced** - This gives you the React UI component directly. It enables you to insert the Radar on your own layout or page for a more customized feel. + +### Install + +For either simple or advanced installations, you'll need to add the dependency using Yarn: ```sh yarn add @backstage/plugin-tech-radar ``` -In your `apis.ts` set up the "out of the box" implementation for Tech Radar: +### Simple Configuration + +In your `apis.ts` set up the simple "out of the box" implementation for Tech Radar: ```ts import { ApiHolder, ApiRegistry } from '@backstage/core'; import { techRadarApiRef, TechRadar, - loadSampleData, } from '@backstage/plugin-tech-radar'; const builder = ApiRegistry.builder(); -builder.add(techRadarApiRef, new TechRadar(1400, 800, loadSampleData)); +builder.add(techRadarApiRef, new TechRadar({ + width: 1400, + height: 800 +)); export default builder.build() as ApiHolder; ``` -It will then be available on your Backstage installation over at +Congrats, you're done! We'll just load it with [example data](src/sampleData.ts) to get you started. Just go to to see it live in action. -## Configuration - -The implementation for the TechRadar class is: +And if you'd like to configure it more, such as providing it with your own data, see the `TechRadarApi` TypeScript interface below for the options: ```ts -export interface TechRadarAdditionalOptions { - title?: string; - subtitle?: string; +export interface TechRadarComponentProps { + width: number; + height: number; + getData?: () => Promise; svgProps?: object; } -export interface TechRadarLoaderResponse { - quadrants: RadarQuadrant[]; - rings: RadarRing[]; - entries: RadarEntry[]; +export interface TechRadarApi extends TechRadarComponentProps { + title?: string; + subtitle?: string; } - -export interface TechRadarApi { - width: number; - height: number; - load: () => Promise; - additionalOpts: TechRadarAdditionalOptions; -} - -// Constructor signature for the `TechRadar` class -// constructor( -// public width: number, -// public height: number, -// public load: () => Promise, -// public additionalOpts: TechRadarAdditionalOptions = {}, -// ) ``` -The source code is available in [api.ts](src/api.ts). +You can see the API directly over at . -## Code Samples +### Advanced Configuration -### Set up Tech Radar with sample data +This way won't expose an `/tech-radar` path. Instead, you'll need to create your own Backstage plugin and use the Tech Radar as any other React UI component. -See example above. +In your Backstage app, run the following command: -### Set up Tech Radar with hard-coded values +```sh +yarn create-plugin +``` + +In your plugin, in any React component you'd like to import the Tech Radar, do the following: + +```tsx +import { TechRadarComponent } from '@backstage/plugin-tech-radar'; + +function MyCustomRadar() { + return ; +} +``` + +If you'd like to configure it more, see the `TechRadarComponentProps` TypeScript interface for options: ```ts -const hardCodedData = () => +export interface TechRadarComponentProps { + width: number; + height: number; + getData?: () => Promise; + svgProps?: object; +} +``` + +You can see the API directly over at . + +## Frequently Asked Questions + +### Who created the Tech Radar? + +[ThoughtWorks](https://thoughtworks.com/radar) created the Tech Radar concept, and [Zalando created the visualization](https://opensource.zalando.com/tech-radar/) that we use at Spotify and in this plugin. + +### How do I load in my own data? + +It's simple. In both the Simple (Backstage plugin) and Advanced (React component) configurations, you can pass through a `getData` prop which expects a `Promise` signature. See more in . + +Here's an example: + +```tsx +const getHardCodedData = () => Promise.resolve({ quadrants: [{ id: 'infrastructure', name: 'Infrastructure' }], rings: [{ id: 'use', name: 'USE', color: '#93c47d' }], @@ -100,48 +131,43 @@ const hardCodedData = () => ], }); -builder.add(techRadarApiRef, new TechRadar(1400, 800, hardCodedData)); +// Simple +builder.add(techRadarApiRef, new TechRadar({ + width: 1400, + height: 800 + getData: getHardCodedData +)); + +// Advanced + ``` -### Set up Tech Radar with an API call - -```ts -const apiRetrievedData = async () => { - const response = await fetch('http://example.com/tech-radar-values.json'); - const json = await response.json(); - return json as TechRadarLoaderResponse; -}; - -builder.add(techRadarApiRef, new TechRadar(1400, 800, apiRetrievedData)); -``` - -### Use a custom title and subtitle +### How do I write tests? + +You can use the `svgProps` option to pass custom React props to the `` element we create for the Tech Radar. This complements well with the `data-testid` attribute and the `@testing-library/react` library we use in Backstage. ```ts +// Simple builder.add( techRadarApiRef, - new TechRadar(1400, 800, loadSampleData, { - title: 'My Company Tech Radar', - subtitle: 'Learn about what technologies we use at My Company.', - }), -); -``` - -### Use custom props - -Great for testing through adding a `data-testid` for being able to test with `@testing-library/react` - -```ts -builder.add( - techRadarApiRef, - new TechRadar(1400, 800, loadSampleData, { + new TechRadar({ + width: 1400, + height: 800, svgProps: { - // for the main tag of the visualization 'data-testid': 'tech-radar-svg', }, }), ); +// Advanced +; + // Then, in your tests... // const { getByTestId } = render(...); // expect(getByTestId('tech-radar-svg')).toBeInTheDocument();