From f63dd72e02ec0c81477b91ce12f89c76b891aae5 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 13 Dec 2023 15:25:29 +0100 Subject: [PATCH 1/2] core-compat-api: merge collectLegacyRoutes into convertLegacyApp Signed-off-by: Patrik Oldsberg --- .changeset/stupid-deers-wonder.md | 5 +++ packages/core-compat-api/api-report.md | 7 ---- .../src/collectLegacyRoutes.tsx | 2 +- .../src/convertLegacyApp.test.tsx | 33 +++++++++++++++++++ .../core-compat-api/src/convertLegacyApp.ts | 4 +++ packages/core-compat-api/src/index.ts | 1 - 6 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 .changeset/stupid-deers-wonder.md diff --git a/.changeset/stupid-deers-wonder.md b/.changeset/stupid-deers-wonder.md new file mode 100644 index 0000000000..e65e01dd5e --- /dev/null +++ b/.changeset/stupid-deers-wonder.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-compat-api': minor +--- + +The `collectLegacyRoutes` has been removed and is replaced by `convertLegacyApp` now being able to convert a `FlatRoutes` element directly. diff --git a/packages/core-compat-api/api-report.md b/packages/core-compat-api/api-report.md index 58d5a2f094..a764d8c091 100644 --- a/packages/core-compat-api/api-report.md +++ b/packages/core-compat-api/api-report.md @@ -3,8 +3,6 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts -/// - import { AnyRouteRefParams } from '@backstage/core-plugin-api'; import { BackstagePlugin } from '@backstage/frontend-plugin-api'; import { ExtensionOverrides } from '@backstage/frontend-plugin-api'; @@ -17,11 +15,6 @@ import { RouteRef as RouteRef_2 } from '@backstage/frontend-plugin-api'; import { SubRouteRef } from '@backstage/core-plugin-api'; import { SubRouteRef as SubRouteRef_2 } from '@backstage/frontend-plugin-api'; -// @public (undocumented) -export function collectLegacyRoutes( - flatRoutesElement: JSX.Element, -): BackstagePlugin[]; - // @public export function compatWrapper(element: ReactNode): React_2.JSX.Element; diff --git a/packages/core-compat-api/src/collectLegacyRoutes.tsx b/packages/core-compat-api/src/collectLegacyRoutes.tsx index 729ead2786..b4af6ac01a 100644 --- a/packages/core-compat-api/src/collectLegacyRoutes.tsx +++ b/packages/core-compat-api/src/collectLegacyRoutes.tsx @@ -144,7 +144,7 @@ function visitRouteChildren(options: { }); } -/** @public */ +/** @internal */ export function collectLegacyRoutes( flatRoutesElement: JSX.Element, ): BackstagePlugin[] { diff --git a/packages/core-compat-api/src/convertLegacyApp.test.tsx b/packages/core-compat-api/src/convertLegacyApp.test.tsx index 9fae0128b0..a8d6cb2dbc 100644 --- a/packages/core-compat-api/src/convertLegacyApp.test.tsx +++ b/packages/core-compat-api/src/convertLegacyApp.test.tsx @@ -126,4 +126,37 @@ describe('convertLegacyApp', () => { }, ]); }); + + it('should find and extract just routes', () => { + const collected = convertLegacyApp( + + } /> + } /> + } /> + } /> + , + ); + + expect( + collected.map((p: any /* TODO */) => ({ + id: p.id, + extensions: p.extensions.map((e: any) => ({ + id: e.id, + attachTo: e.attachTo, + disabled: e.disabled, + defaultConfig: e.configSchema?.parse({}), + })), + })), + ).toEqual([ + expect.objectContaining({ + id: 'score-card', + }), + expect.objectContaining({ + id: 'stackstorm', + }), + expect.objectContaining({ + id: 'puppetDb', + }), + ]); + }); }); diff --git a/packages/core-compat-api/src/convertLegacyApp.ts b/packages/core-compat-api/src/convertLegacyApp.ts index 9fe07cc783..8055a7b72e 100644 --- a/packages/core-compat-api/src/convertLegacyApp.ts +++ b/packages/core-compat-api/src/convertLegacyApp.ts @@ -62,6 +62,10 @@ function selectChildren( export function convertLegacyApp( rootElement: React.JSX.Element, ): (ExtensionOverrides | BackstagePlugin)[] { + if (getComponentData(rootElement, 'core.type') === 'FlatRoutes') { + return collectLegacyRoutes(rootElement); + } + const appRouterEls = selectChildren( rootElement, el => getComponentData(el, 'core.type') === 'AppRouter', diff --git a/packages/core-compat-api/src/index.ts b/packages/core-compat-api/src/index.ts index cb62654684..68e5d9cf19 100644 --- a/packages/core-compat-api/src/index.ts +++ b/packages/core-compat-api/src/index.ts @@ -15,6 +15,5 @@ */ export * from './compatWrapper'; -export { collectLegacyRoutes } from './collectLegacyRoutes'; export { convertLegacyApp } from './convertLegacyApp'; export { convertLegacyRouteRef } from './convertLegacyRouteRef'; From fa1009aaddce8ce7193bc8953bf5eb461fc4bb22 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 13 Dec 2023 16:32:00 +0100 Subject: [PATCH 2/2] app-next: replace usage of collectLegacyRoutes Signed-off-by: Patrik Oldsberg --- packages/app-next/src/App.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app-next/src/App.tsx b/packages/app-next/src/App.tsx index d7ec30bf95..0eca65fdda 100644 --- a/packages/app-next/src/App.tsx +++ b/packages/app-next/src/App.tsx @@ -33,7 +33,7 @@ import { } from '@backstage/frontend-plugin-api'; import techdocsPlugin from '@backstage/plugin-techdocs/alpha'; import { homePage } from './HomePage'; -import { collectLegacyRoutes } from '@backstage/core-compat-api'; +import { convertLegacyApp } from '@backstage/core-compat-api'; import { FlatRoutes } from '@backstage/core-app-api'; import { Route } from 'react-router'; import { CatalogImportPage } from '@backstage/plugin-catalog-import'; @@ -109,7 +109,7 @@ const scmIntegrationApi = createApiExtension({ }), }); -const collectedLegacyPlugins = collectLegacyRoutes( +const collectedLegacyPlugins = convertLegacyApp( } /> ,