Merge pull request #21835 from backstage/rugvip/nocollect

core-compat-api: merge collectLegacyRoutes into convertLegacyApp
This commit is contained in:
Patrik Oldsberg
2023-12-13 17:05:13 +01:00
committed by GitHub
7 changed files with 45 additions and 11 deletions
+5
View File
@@ -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.
+2 -2
View File
@@ -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(
<FlatRoutes>
<Route path="/catalog-import" element={<CatalogImportPage />} />
</FlatRoutes>,
-7
View File
@@ -3,8 +3,6 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
/// <reference types="react" />
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;
@@ -144,7 +144,7 @@ function visitRouteChildren(options: {
});
}
/** @public */
/** @internal */
export function collectLegacyRoutes(
flatRoutesElement: JSX.Element,
): BackstagePlugin[] {
@@ -126,4 +126,37 @@ describe('convertLegacyApp', () => {
},
]);
});
it('should find and extract just routes', () => {
const collected = convertLegacyApp(
<FlatRoutes>
<Route path="/score-board" element={<ScoreBoardPage />} />
<Route path="/stackstorm" element={<StackstormPage />} />
<Route path="/puppetdb" element={<PuppetDbPage />} />
<Route path="/puppetdb" element={<PuppetDbPage />} />
</FlatRoutes>,
);
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',
}),
]);
});
});
@@ -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',
-1
View File
@@ -15,6 +15,5 @@
*/
export * from './compatWrapper';
export { collectLegacyRoutes } from './collectLegacyRoutes';
export { convertLegacyApp } from './convertLegacyApp';
export { convertLegacyRouteRef } from './convertLegacyRouteRef';