core-compat-api: merge collectLegacyRoutes into convertLegacyApp
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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.
|
||||
@@ -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',
|
||||
|
||||
@@ -15,6 +15,5 @@
|
||||
*/
|
||||
export * from './compatWrapper';
|
||||
|
||||
export { collectLegacyRoutes } from './collectLegacyRoutes';
|
||||
export { convertLegacyApp } from './convertLegacyApp';
|
||||
export { convertLegacyRouteRef } from './convertLegacyRouteRef';
|
||||
|
||||
Reference in New Issue
Block a user