core-compat-api: move over convertLegacyRouteRef

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-11-13 23:44:58 +01:00
parent 80d023a175
commit 80442558f6
5 changed files with 17 additions and 34 deletions
+1 -1
View File
@@ -25,7 +25,6 @@
},
"devDependencies": {
"@backstage/cli": "workspace:^",
"@backstage/core-app-api": "workspace:^",
"@backstage/plugin-puppetdb": "workspace:^",
"@backstage/plugin-stackstorm": "workspace:^",
"@oriflame/backstage-plugin-score-card": "^0.7.0",
@@ -39,6 +38,7 @@
"react-router-dom": "6.0.0-beta.0 || ^6.3.0"
},
"dependencies": {
"@backstage/core-app-api": "workspace:^",
"@backstage/core-plugin-api": "workspace:^",
"@backstage/frontend-plugin-api": "workspace:^"
}
@@ -28,7 +28,7 @@ import {
RouteRef,
getComponentData,
} from '@backstage/core-plugin-api';
import { convertLegacyRouteRef } from '@backstage/core-plugin-api/alpha';
import { convertLegacyRouteRef } from './convertLegacyRouteRef';
/*
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { routeRefType } from './types';
import {
RouteRef as LegacyRouteRef,
SubRouteRef as LegacySubRouteRef,
@@ -22,9 +21,9 @@ import {
AnyRouteRefParams,
} from '@backstage/core-plugin-api';
// Relative imports to avoid dependency, at least for now
// eslint-disable-next-line @backstage/no-forbidden-package-imports
import { routeRefType } from '@backstage/core-plugin-api/src/routing/types';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import {
RouteRef,
SubRouteRef,
@@ -32,29 +31,13 @@ import {
createRouteRef,
createSubRouteRef,
createExternalRouteRef,
} from '../../../frontend-plugin-api/src/routing';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import { toInternalRouteRef } from '../../../frontend-plugin-api/src/routing/RouteRef';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import { toInternalSubRouteRef } from '../../../frontend-plugin-api/src/routing/SubRouteRef';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import { toInternalExternalRouteRef } from '../../../frontend-plugin-api/src/routing/ExternalRouteRef';
// TODO(Rugvip): Once this is moved to a compat package these aliases can be removed and imported from frontend- instead
/** @ignore */
type NewRouteRef<TParams extends AnyRouteRefParams = AnyRouteRefParams> =
RouteRef<TParams>;
/** @ignore */
type NewSubRouteRef<TParams extends AnyRouteRefParams = AnyRouteRefParams> =
SubRouteRef<TParams>;
/** @ignore */
type NewExternalRouteRef<
TParams extends AnyRouteRefParams = AnyRouteRefParams,
TOptional extends boolean = boolean,
> = ExternalRouteRef<TParams, TOptional>;
} from '@backstage/frontend-plugin-api';
// eslint-disable-next-line @backstage/no-forbidden-package-imports
import { toInternalRouteRef } from '@backstage/frontend-plugin-api/src/routing/RouteRef';
// eslint-disable-next-line @backstage/no-forbidden-package-imports
import { toInternalSubRouteRef } from '@backstage/frontend-plugin-api/src/routing/SubRouteRef';
// eslint-disable-next-line @backstage/no-forbidden-package-imports
import { toInternalExternalRouteRef } from '@backstage/frontend-plugin-api/src/routing/ExternalRouteRef';
/**
* A temporary helper to convert a legacy route ref to the new system.
@@ -66,7 +49,7 @@ type NewExternalRouteRef<
*/
export function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(
ref: LegacyRouteRef<TParams>,
): NewRouteRef<TParams>;
): RouteRef<TParams>;
/**
* A temporary helper to convert a legacy sub route ref to the new system.
@@ -78,7 +61,7 @@ export function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(
*/
export function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(
ref: LegacySubRouteRef<TParams>,
): NewSubRouteRef<TParams>;
): SubRouteRef<TParams>;
/**
* A temporary helper to convert a legacy external route ref to the new system.
@@ -93,14 +76,14 @@ export function convertLegacyRouteRef<
TOptional extends boolean,
>(
ref: LegacyExternalRouteRef<TParams, TOptional>,
): NewExternalRouteRef<TParams, TOptional>;
): ExternalRouteRef<TParams, TOptional>;
export function convertLegacyRouteRef(
ref: LegacyRouteRef | LegacySubRouteRef | LegacyExternalRouteRef,
): NewRouteRef | NewSubRouteRef | NewExternalRouteRef {
): RouteRef | SubRouteRef | ExternalRouteRef {
// Ref has already been converted
if ('$$type' in ref) {
return ref as unknown as NewRouteRef | NewSubRouteRef | NewExternalRouteRef;
return ref as unknown as RouteRef | SubRouteRef | ExternalRouteRef;
}
const type = (ref as unknown as { [routeRefType]: unknown })[routeRefType];
+1
View File
@@ -15,3 +15,4 @@
*/
export { collectLegacyRoutes } from './collectLegacyRoutes';
export { convertLegacyApp } from './convertLegacyApp';
export { convertLegacyRouteRef } from './convertLegacyRouteRef';
-1
View File
@@ -16,4 +16,3 @@
export * from './translation';
export * from './apis/alpha';
export { convertLegacyRouteRef } from './routing/convertLegacyRouteRef';