From a51dc0006ee69fea156a9c5d8a2f91fe90145d73 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 16 Mar 2021 17:49:39 +0100 Subject: [PATCH] core-api: export SubRouteRef and make them assignable to plugin.routes Signed-off-by: Patrik Oldsberg --- .changeset/chilled-mugs-learn.md | 5 +++++ packages/core-api/src/app/App.test.tsx | 6 ++++++ packages/core-api/src/app/App.tsx | 8 +++----- packages/core-api/src/plugin/types.ts | 4 ++-- packages/core-api/src/routing/index.ts | 1 + 5 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 .changeset/chilled-mugs-learn.md diff --git a/.changeset/chilled-mugs-learn.md b/.changeset/chilled-mugs-learn.md new file mode 100644 index 0000000000000..b239134cf8528 --- /dev/null +++ b/.changeset/chilled-mugs-learn.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-api': patch +--- + +Export `SubRouteRef` type, and allow `SubRouteRef`s to be assigned to `plugin.routes`. diff --git a/packages/core-api/src/app/App.test.tsx b/packages/core-api/src/app/App.test.tsx index 4e7bf8062410e..c91eef1fb0bc8 100644 --- a/packages/core-api/src/app/App.test.tsx +++ b/packages/core-api/src/app/App.test.tsx @@ -98,6 +98,12 @@ describe('Integration Test', () => { const plugin1 = createPlugin({ id: 'blob', + // Both absolute and sub route refs should be assignable to the plugin routes + routes: { + ref1: plugin1RouteRef, + ref2: plugin2RouteRef, + ref3: subRouteRef1, + }, externalRoutes: { extRouteRef1, extRouteRef2, diff --git a/packages/core-api/src/app/App.tsx b/packages/core-api/src/app/App.tsx index c20eb0824e55f..d2346e478c6ff 100644 --- a/packages/core-api/src/app/App.tsx +++ b/packages/core-api/src/app/App.tsx @@ -53,7 +53,7 @@ import { import { IconComponent, IconComponentMap, IconKey } from '../icons'; import { BackstagePlugin } from '../plugin'; import { AnyRoutes } from '../plugin/types'; -import { RouteRef, ExternalRouteRef } from '../routing'; +import { RouteRef, ExternalRouteRef, SubRouteRef } from '../routing'; import { routeObjectCollector, routeParentCollector, @@ -75,10 +75,8 @@ import { SignInResult, } from './types'; -export function generateBoundRoutes( - bindRoutes: AppOptions['bindRoutes'], -): Map { - const result = new Map(); +export function generateBoundRoutes(bindRoutes: AppOptions['bindRoutes']) { + const result = new Map(); if (bindRoutes) { const bind: AppRouteBinder = (externalRoutes, targetRoutes: AnyRoutes) => { diff --git a/packages/core-api/src/plugin/types.ts b/packages/core-api/src/plugin/types.ts index c3b64d8cb6ad7..2ad02b243d4d7 100644 --- a/packages/core-api/src/plugin/types.ts +++ b/packages/core-api/src/plugin/types.ts @@ -15,7 +15,7 @@ */ import { ComponentType } from 'react'; -import { RouteRef, ExternalRouteRef } from '../routing'; +import { RouteRef, SubRouteRef, ExternalRouteRef } from '../routing'; import { AnyApiFactory } from '../apis/system'; export type RouteOptions = { @@ -70,7 +70,7 @@ export type Extension = { expose(plugin: BackstagePlugin): T; }; -export type AnyRoutes = { [name: string]: RouteRef }; +export type AnyRoutes = { [name: string]: RouteRef | SubRouteRef }; export type AnyExternalRoutes = { [name: string]: ExternalRouteRef }; diff --git a/packages/core-api/src/routing/index.ts b/packages/core-api/src/routing/index.ts index c6134cfe4fcf3..c5441d5b23a7c 100644 --- a/packages/core-api/src/routing/index.ts +++ b/packages/core-api/src/routing/index.ts @@ -16,6 +16,7 @@ export type { RouteRef, + SubRouteRef, AbsoluteRouteRef, ConcreteRoute, MutableRouteRef,