diff --git a/README.md b/README.md index 7f41745..80469f1 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,77 @@ const routes = ( /> ``` +#### How to Use This Component in Backstage with a Config-Based URL + +##### Configure the URL in app-config.yaml + +In your Backstage `app-config.yaml`, add a config key for the editor’s JSON URL. For example: + +```yaml +techRadar: + url: "https://example.org/path/to/tech-radar.json" +``` + +Adjust the key and value to suit your environment. + +##### Set up the type for the config value + +In your `package.json`, add: + +```json +{ + // ... + "files": [ + // ... + "config.d.ts" + ], + "configSchema": "config.d.ts" +} +``` + +You'll need to create a type definition for the config value in your Backstage app. In your `config.d.ts` file, add: + +````ts +export interface Config { + techRadar: { + /** + * Frontend URL + * @visibility frontend + */ + url: string; + }; +} +``` + +##### Create a small React wrapper in your Backstage app + +Somewhere in your Backstage app (for example, in `App.tsx` or in a separate `TechRadarEditorWrapper.tsx` file), create a tiny wrapper component to read the config and pass that URL to the `` web component as an attribute: + +```tsx +import React from "react"; +import { useApi, configApiRef } from "@backstage/core-plugin-api"; + +// Import the custom element so that React recognizes +import "tech-radar-editor"; + +export const TechRadarEditorWrapper = () => { + const configApi = useApi(configApiRef); + const dataUrl = configApi.getOptionalString("techRadar.url") ?? ""; + + return ; +}; +```` + +##### Add a route for your Tech Radar Editor + +In your Backstage `App.tsx` (or wherever you define your routes), import that wrapper and point a route to it: + +```tsx +} /> +``` + +Now when you visit `/tech-radar-editor`, the `` component will automatically fetch the JSON from your configured URL. + ## Consume the Component in Plain JavaScript Include the component in an HTML file: diff --git a/package.json b/package.json index 701b02d..4917b9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tech-radar-editor", - "version": "1.0.1", + "version": "1.1.0", "type": "module", "repository": { "type": "git", diff --git a/src/TechRadarEditor.svelte b/src/TechRadarEditor.svelte index 3858038..b26a2ad 100644 --- a/src/TechRadarEditor.svelte +++ b/src/TechRadarEditor.svelte @@ -7,6 +7,11 @@