Skip to content

Commit

Permalink
core-api: export SubRouteRef and make them assignable to plugin.routes
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Oldsberg <[email protected]>
  • Loading branch information
Rugvip committed Mar 16, 2021
1 parent ad19c23 commit a51dc00
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-mugs-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/core-api': patch
---

Export `SubRouteRef` type, and allow `SubRouteRef`s to be assigned to `plugin.routes`.
6 changes: 6 additions & 0 deletions packages/core-api/src/app/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions packages/core-api/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -75,10 +75,8 @@ import {
SignInResult,
} from './types';

export function generateBoundRoutes(
bindRoutes: AppOptions['bindRoutes'],
): Map<ExternalRouteRef, RouteRef> {
const result = new Map<ExternalRouteRef, RouteRef>();
export function generateBoundRoutes(bindRoutes: AppOptions['bindRoutes']) {
const result = new Map<ExternalRouteRef, RouteRef | SubRouteRef>();

if (bindRoutes) {
const bind: AppRouteBinder = (externalRoutes, targetRoutes: AnyRoutes) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core-api/src/plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -70,7 +70,7 @@ export type Extension<T> = {
expose(plugin: BackstagePlugin<any, any>): T;
};

export type AnyRoutes = { [name: string]: RouteRef<any> };
export type AnyRoutes = { [name: string]: RouteRef | SubRouteRef };

export type AnyExternalRoutes = { [name: string]: ExternalRouteRef };

Expand Down
1 change: 1 addition & 0 deletions packages/core-api/src/routing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

export type {
RouteRef,
SubRouteRef,
AbsoluteRouteRef,
ConcreteRoute,
MutableRouteRef,
Expand Down

0 comments on commit a51dc00

Please sign in to comment.