simplify route bindings in config

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-01-20 11:16:25 +01:00
parent 475fd94380
commit 86346c2c11
5 changed files with 36 additions and 13 deletions
+25
View File
@@ -0,0 +1,25 @@
---
'@backstage/frontend-app-api': minor
---
**BREAKING**: The `app.routes.bindings` app-config mapping has been simplified. You now only need to specify the plugin ID and route ID on both sides of the mapping.
Old form:
```yaml
app:
routes:
bindings:
plugin.catalog.externalRoutes.viewTechDoc: plugin.techdocs.routes.docRoot
plugin.catalog.externalRoutes.createComponent: plugin.catalog-import.routes.importPage
```
New form:
```yaml
app:
routes:
bindings:
catalog.viewTechDoc: techdocs.docRoot
catalog.createComponent: catalog-import.importPage
```
@@ -241,10 +241,10 @@ app:
bindings:
# point to the Scaffolder create component page when the Catalog create component ref is used
# highlight-next-line
plugin.catalog.externalRoutes.createComponent: plugin.scaffolder.routes.index
catalog.createComponent: scaffolder.index
# point to the Catalog details page when the Scaffolder component details ref is used
# highlight-next-line
plugin.scaffolder.externalRoutes.componentDetails: plugin.catalog.routes.details
scaffolder.componentDetails: catalog.details
```
We also have the ability to express this in code as an option to `createApp`, but you of course only need to use one of these two methods:
+3 -3
View File
@@ -3,9 +3,9 @@ app:
packages: 'all' # ✨
routes:
bindings:
plugin.pages.externalRoutes.pageX: plugin.pages.routes.pageX
plugin.catalog.externalRoutes.viewTechDoc: plugin.techdocs.routes.docRoot
plugin.catalog.externalRoutes.createComponent: plugin.catalog-import.routes.importPage
pages.pageX: pages.pageX
catalog.viewTechDoc: techdocs.docRoot
catalog.createComponent: catalog-import.importPage
extensions:
# - apis.plugin.graphiql.browse.gitlab: true
@@ -37,15 +37,13 @@ describe('collectRouteIds', () => {
createPlugin({ id: 'test', routes: { ref }, externalRoutes: { extRef } }),
]);
expect(Object.fromEntries(collected.routes)).toEqual({
'plugin.test.routes.ref': ref,
'test.ref': ref,
});
expect(Object.fromEntries(collected.externalRoutes)).toEqual({
'plugin.test.externalRoutes.extRef': extRef,
'test.extRef': extRef,
});
expect(String(ref)).toBe('RouteRef{plugin.test.routes.ref}');
expect(String(extRef)).toBe(
'ExternalRouteRef{plugin.test.externalRoutes.extRef}',
);
expect(String(ref)).toBe('RouteRef{test.ref}');
expect(String(extRef)).toBe('ExternalRouteRef{test.extRef}');
});
});
@@ -47,7 +47,7 @@ export function collectRouteIds(features: FrontendFeature[]): RouteRefsById {
}
for (const [name, ref] of Object.entries(feature.routes)) {
const refId = `plugin.${feature.id}.routes.${name}`;
const refId = `${feature.id}.${name}`;
if (routesById.has(refId)) {
throw new Error(`Unexpected duplicate route '${refId}'`);
}
@@ -62,7 +62,7 @@ export function collectRouteIds(features: FrontendFeature[]): RouteRefsById {
}
}
for (const [name, ref] of Object.entries(feature.externalRoutes)) {
const refId = `plugin.${feature.id}.externalRoutes.${name}`;
const refId = `${feature.id}.${name}`;
if (externalRoutesById.has(refId)) {
throw new Error(`Unexpected duplicate external route '${refId}'`);
}