From 13f87f34fc1871ad6f03abf2a7453340ad79c036 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Thu, 11 Jan 2024 15:04:22 +0100 Subject: [PATCH 1/3] fix(frontend-app-api): create plugin subroutes type Signed-off-by: Camila Belo Co-authored-by: Patrik Oldsberg --- .../src/routing/collectRouteIds.ts | 18 ++++++++++++++---- .../frontend-plugin-api/src/wiring/types.ts | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/frontend-app-api/src/routing/collectRouteIds.ts b/packages/frontend-app-api/src/routing/collectRouteIds.ts index 1d6aa14e5d..2fbb8b6791 100644 --- a/packages/frontend-app-api/src/routing/collectRouteIds.ts +++ b/packages/frontend-app-api/src/routing/collectRouteIds.ts @@ -21,9 +21,14 @@ import { FrontendFeature, } from '@backstage/frontend-plugin-api'; // eslint-disable-next-line @backstage/no-relative-monorepo-imports -import { toInternalRouteRef } from '../../../frontend-plugin-api/src/routing/RouteRef'; +import { + isRouteRef, + toInternalRouteRef, +} from '../../../frontend-plugin-api/src/routing/RouteRef'; // eslint-disable-next-line @backstage/no-relative-monorepo-imports import { toInternalExternalRouteRef } from '../../../frontend-plugin-api/src/routing/ExternalRouteRef'; +// eslint-disable-next-line @backstage/no-relative-monorepo-imports +import { toInternalSubRouteRef } from '../../../frontend-plugin-api/src/routing/SubRouteRef'; /** @internal */ export interface RouteRefsById { @@ -47,9 +52,14 @@ export function collectRouteIds(features: FrontendFeature[]): RouteRefsById { throw new Error(`Unexpected duplicate route '${refId}'`); } - const internalRef = toInternalRouteRef(ref); - internalRef.setId(refId); - routesById.set(refId, ref); + if (isRouteRef(ref)) { + const internalRef = toInternalRouteRef(ref); + internalRef.setId(refId); + routesById.set(refId, ref); + } else { + const internalRef = toInternalSubRouteRef(ref); + routesById.set(refId, internalRef); + } } for (const [name, ref] of Object.entries(feature.externalRoutes)) { const refId = `plugin.${feature.id}.externalRoutes.${name}`; diff --git a/packages/frontend-plugin-api/src/wiring/types.ts b/packages/frontend-plugin-api/src/wiring/types.ts index c2a6b09ba7..7e0650e06c 100644 --- a/packages/frontend-plugin-api/src/wiring/types.ts +++ b/packages/frontend-plugin-api/src/wiring/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ExternalRouteRef, RouteRef } from '../routing'; +import { ExternalRouteRef, RouteRef, SubRouteRef } from '../routing'; /** * Feature flag configuration. @@ -27,7 +27,7 @@ export type FeatureFlagConfig = { }; /** @public */ -export type AnyRoutes = { [name in string]: RouteRef }; +export type AnyRoutes = { [name in string]: RouteRef | SubRouteRef }; /** @public */ export type AnyExternalRoutes = { [name in string]: ExternalRouteRef }; From 7d63b32d65c6eb189d082f2c250716febfe8e3b2 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Thu, 11 Jan 2024 17:25:15 +0100 Subject: [PATCH 2/3] docs: add changeset file Signed-off-by: Camila Belo --- .changeset/large-pens-cough.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/large-pens-cough.md diff --git a/.changeset/large-pens-cough.md b/.changeset/large-pens-cough.md new file mode 100644 index 0000000000..631a20aee2 --- /dev/null +++ b/.changeset/large-pens-cough.md @@ -0,0 +1,6 @@ +--- +'@backstage/frontend-plugin-api': patch +'@backstage/frontend-app-api': patch +--- + +Accepts sub route refs on the new `createPlugin` routes map. From 54d991a71b0ae7fb6e3e0025eb56566c62d1c035 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Fri, 12 Jan 2024 10:22:36 +0100 Subject: [PATCH 3/3] docs(frontend-plugin-api): update api reports Signed-off-by: Camila Belo --- packages/frontend-plugin-api/api-report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-plugin-api/api-report.md b/packages/frontend-plugin-api/api-report.md index a292634d9a..2260db334f 100644 --- a/packages/frontend-plugin-api/api-report.md +++ b/packages/frontend-plugin-api/api-report.md @@ -180,7 +180,7 @@ export type AnyRouteRefParams = // @public (undocumented) export type AnyRoutes = { - [name in string]: RouteRef; + [name in string]: RouteRef | SubRouteRef; }; export { ApiFactory };