plugin-api: move is*RouteRef to app-api
Co-authored-by: Juan Lulkin <jmaiz@spotify.com> Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -21,15 +21,11 @@ import {
|
||||
AnyParams,
|
||||
RouteFunc,
|
||||
routeRefType,
|
||||
} from './types';
|
||||
import {
|
||||
RouteRef,
|
||||
ExternalRouteRef,
|
||||
SubRouteRef,
|
||||
isRouteRef,
|
||||
isSubRouteRef,
|
||||
isExternalRouteRef,
|
||||
} from '@backstage/plugin-api';
|
||||
} from './types';
|
||||
import { RouteRef, ExternalRouteRef, SubRouteRef } from '@backstage/plugin-api';
|
||||
|
||||
// Joins a list of paths together, avoiding trailing and duplicate slashes
|
||||
function joinPaths(...paths: string[]): string {
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
import { RouteRef, SubRouteRef, ExternalRouteRef } from '@backstage/plugin-api';
|
||||
import { getOrCreateGlobalSingleton } from '../lib/globalObject';
|
||||
|
||||
export const routeRefType: unique symbol = getOrCreateGlobalSingleton<any>(
|
||||
type RouteRefType = Exclude<keyof RouteRef, 'params'>;
|
||||
export const routeRefType: RouteRefType = getOrCreateGlobalSingleton<any>(
|
||||
'route-ref-type',
|
||||
() => Symbol('route-ref-type'),
|
||||
);
|
||||
@@ -46,3 +47,33 @@ export interface BackstageRouteObject {
|
||||
path: string;
|
||||
routeRefs: Set<RouteRef>;
|
||||
}
|
||||
|
||||
export function isRouteRef<Params extends AnyParams>(
|
||||
routeRef:
|
||||
| RouteRef<Params>
|
||||
| SubRouteRef<Params>
|
||||
| ExternalRouteRef<Params, any>,
|
||||
): routeRef is RouteRef<Params> {
|
||||
return routeRef[routeRefType] === 'absolute';
|
||||
}
|
||||
|
||||
export function isSubRouteRef<Params extends AnyParams>(
|
||||
routeRef:
|
||||
| RouteRef<Params>
|
||||
| SubRouteRef<Params>
|
||||
| ExternalRouteRef<Params, any>,
|
||||
): routeRef is SubRouteRef<Params> {
|
||||
return routeRef[routeRefType] === 'sub';
|
||||
}
|
||||
|
||||
export function isExternalRouteRef<
|
||||
Params extends AnyParams,
|
||||
Optional extends boolean
|
||||
>(
|
||||
routeRef:
|
||||
| RouteRef<Params>
|
||||
| SubRouteRef<Params>
|
||||
| ExternalRouteRef<Params, Optional>,
|
||||
): routeRef is ExternalRouteRef<Params, Optional> {
|
||||
return routeRef[routeRefType] === 'external';
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
|
||||
import { AnyParams, ExternalRouteRef } from './types';
|
||||
import { createExternalRouteRef, isExternalRouteRef } from './ExternalRouteRef';
|
||||
import { isSubRouteRef } from './SubRouteRef';
|
||||
import { isRouteRef } from './RouteRef';
|
||||
import { createExternalRouteRef } from './ExternalRouteRef';
|
||||
|
||||
describe('ExternalRouteRef', () => {
|
||||
it('should be created', () => {
|
||||
@@ -27,11 +25,6 @@ describe('ExternalRouteRef', () => {
|
||||
expect(routeRef.params).toEqual([]);
|
||||
expect(routeRef.optional).toBe(false);
|
||||
expect(String(routeRef)).toBe('routeRef{type=external,id=my-route-ref}');
|
||||
expect(isRouteRef(routeRef)).toBe(false);
|
||||
expect(isSubRouteRef(routeRef)).toBe(false);
|
||||
expect(isExternalRouteRef(routeRef)).toBe(true);
|
||||
|
||||
expect(isRouteRef({} as ExternalRouteRef)).toBe(false);
|
||||
});
|
||||
|
||||
it('should be created as optional', () => {
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
RouteRef,
|
||||
SubRouteRef,
|
||||
ExternalRouteRef,
|
||||
routeRefType,
|
||||
AnyParams,
|
||||
@@ -70,15 +68,3 @@ export function createExternalRouteRef<
|
||||
Boolean(options.optional) as Optional,
|
||||
);
|
||||
}
|
||||
|
||||
export function isExternalRouteRef<
|
||||
Params extends AnyParams,
|
||||
Optional extends boolean
|
||||
>(
|
||||
routeRef:
|
||||
| RouteRef<Params>
|
||||
| SubRouteRef<Params>
|
||||
| ExternalRouteRef<Params, Optional>,
|
||||
): routeRef is ExternalRouteRef<Params, Optional> {
|
||||
return routeRef[routeRefType] === 'external';
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
|
||||
import { AnyParams, RouteRef } from './types';
|
||||
import { createRouteRef, isRouteRef } from './RouteRef';
|
||||
import { isSubRouteRef } from './SubRouteRef';
|
||||
import { isExternalRouteRef } from './ExternalRouteRef';
|
||||
import { createRouteRef } from './RouteRef';
|
||||
|
||||
describe('RouteRef', () => {
|
||||
it('should be created', () => {
|
||||
@@ -26,11 +24,6 @@ describe('RouteRef', () => {
|
||||
});
|
||||
expect(routeRef.params).toEqual([]);
|
||||
expect(String(routeRef)).toBe('routeRef{type=absolute,id=my-route-ref}');
|
||||
expect(isRouteRef(routeRef)).toBe(true);
|
||||
expect(isSubRouteRef(routeRef)).toBe(false);
|
||||
expect(isExternalRouteRef(routeRef)).toBe(false);
|
||||
|
||||
expect(isRouteRef({} as RouteRef)).toBe(false);
|
||||
});
|
||||
|
||||
it('should be created with params', () => {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
import {
|
||||
RouteRef,
|
||||
SubRouteRef,
|
||||
ExternalRouteRef,
|
||||
routeRefType,
|
||||
AnyParams,
|
||||
ParamKeys,
|
||||
@@ -60,12 +58,3 @@ export function createRouteRef<
|
||||
(config.params ?? []) as ParamKeys<OptionalParams<Params>>,
|
||||
);
|
||||
}
|
||||
|
||||
export function isRouteRef<Params extends AnyParams>(
|
||||
routeRef:
|
||||
| RouteRef<Params>
|
||||
| SubRouteRef<Params>
|
||||
| ExternalRouteRef<Params, any>,
|
||||
): routeRef is RouteRef<Params> {
|
||||
return routeRef[routeRefType] === 'absolute';
|
||||
}
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
|
||||
import { AnyParams, SubRouteRef } from './types';
|
||||
import { createSubRouteRef, isSubRouteRef } from './SubRouteRef';
|
||||
import { createRouteRef, isRouteRef } from './RouteRef';
|
||||
import { isExternalRouteRef } from './ExternalRouteRef';
|
||||
import { createSubRouteRef } from './SubRouteRef';
|
||||
import { createRouteRef } from './RouteRef';
|
||||
|
||||
const parent = createRouteRef({ id: 'parent' });
|
||||
const parentX = createRouteRef({ id: 'parent-x', params: ['x'] });
|
||||
@@ -33,11 +32,6 @@ describe('SubRouteRef', () => {
|
||||
expect(routeRef.parent).toBe(parent);
|
||||
expect(routeRef.params).toEqual([]);
|
||||
expect(String(routeRef)).toBe('routeRef{type=sub,id=my-route-ref}');
|
||||
expect(isRouteRef(routeRef)).toBe(false);
|
||||
expect(isSubRouteRef(routeRef)).toBe(true);
|
||||
expect(isExternalRouteRef(routeRef)).toBe(false);
|
||||
|
||||
expect(isRouteRef({} as SubRouteRef)).toBe(false);
|
||||
});
|
||||
|
||||
it('should be created with params', () => {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
import {
|
||||
AnyParams,
|
||||
ExternalRouteRef,
|
||||
OptionalParams,
|
||||
ParamKeys,
|
||||
RouteRef,
|
||||
@@ -117,12 +116,3 @@ export function createSubRouteRef<
|
||||
// type checking of the parent parameter overlap is tricky to express.
|
||||
return subRouteRef as any;
|
||||
}
|
||||
|
||||
export function isSubRouteRef<Params extends AnyParams>(
|
||||
routeRef:
|
||||
| RouteRef<Params>
|
||||
| SubRouteRef<Params>
|
||||
| ExternalRouteRef<Params, any>,
|
||||
): routeRef is SubRouteRef<Params> {
|
||||
return routeRef[routeRefType] === 'sub';
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
export type { RouteRef, SubRouteRef, ExternalRouteRef } from './types';
|
||||
export { createRouteRef, isRouteRef } from './RouteRef';
|
||||
export { createSubRouteRef, isSubRouteRef } from './SubRouteRef';
|
||||
export { createExternalRouteRef, isExternalRouteRef } from './ExternalRouteRef';
|
||||
export { createRouteRef } from './RouteRef';
|
||||
export { createSubRouteRef } from './SubRouteRef';
|
||||
export { createExternalRouteRef } from './ExternalRouteRef';
|
||||
export { useRouteRef } from './useRouteRef';
|
||||
|
||||
Reference in New Issue
Block a user