fix(frontend-app-api): create plugin subroutes type

Signed-off-by: Camila Belo <camilaibs@gmail.com>
Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Camila Belo
2024-01-11 15:04:22 +01:00
parent 20a37d2fd8
commit 13f87f34fc
2 changed files with 16 additions and 6 deletions
@@ -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}`;
@@ -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 };