diff --git a/packages/frontend-app-api/src/routing/RouteResolver.ts b/packages/frontend-app-api/src/routing/RouteResolver.ts index 9da5836be4..77336988e2 100644 --- a/packages/frontend-app-api/src/routing/RouteResolver.ts +++ b/packages/frontend-app-api/src/routing/RouteResolver.ts @@ -19,7 +19,7 @@ import { RouteRef, ExternalRouteRef, SubRouteRef, - AnyRouteParams, + AnyRouteRefParams, RouteFunc, } from '@backstage/frontend-plugin-api'; import mapValues from 'lodash/mapValues'; @@ -189,7 +189,7 @@ export class RouteResolver { private readonly appBasePath: string, // base path without a trailing slash ) {} - resolve( + resolve( anyRouteRef: | RouteRef | SubRouteRef diff --git a/packages/frontend-app-api/src/routing/extractRouteInfoFromInstanceTree.test.ts b/packages/frontend-app-api/src/routing/extractRouteInfoFromInstanceTree.test.ts index 86a071df79..0de33b50f2 100644 --- a/packages/frontend-app-api/src/routing/extractRouteInfoFromInstanceTree.test.ts +++ b/packages/frontend-app-api/src/routing/extractRouteInfoFromInstanceTree.test.ts @@ -18,7 +18,7 @@ import React from 'react'; import { BackstagePlugin } from '@backstage/core-plugin-api'; import { extractRouteInfoFromInstanceTree } from './extractRouteInfoFromInstanceTree'; import { - AnyRouteParams, + AnyRouteRefParams, Extension, RouteRef, coreExtensionData, @@ -35,7 +35,7 @@ const ref2 = createRouteRef(); const ref3 = createRouteRef(); const ref4 = createRouteRef(); const ref5 = createRouteRef(); -const refOrder: RouteRef[] = [ref1, ref2, ref3, ref4, ref5]; +const refOrder: RouteRef[] = [ref1, ref2, ref3, ref4, ref5]; function createTestExtension(options: { id: string; diff --git a/packages/frontend-plugin-api/api-report.md b/packages/frontend-plugin-api/api-report.md index 7753b1744e..9169d9c9e8 100644 --- a/packages/frontend-plugin-api/api-report.md +++ b/packages/frontend-plugin-api/api-report.md @@ -44,7 +44,7 @@ export type AnyExternalRoutes = { }; // @public -export type AnyRouteParams = +export type AnyRouteRefParams = | { [param in string]: string; } @@ -93,7 +93,7 @@ export const coreExtensionData: { reactElement: ConfigurableExtensionDataRef; routePath: ConfigurableExtensionDataRef; apiFactory: ConfigurableExtensionDataRef; - routeRef: ConfigurableExtensionDataRef, {}>; + routeRef: ConfigurableExtensionDataRef, {}>; navTarget: ConfigurableExtensionDataRef; theme: ConfigurableExtensionDataRef; }; @@ -288,7 +288,7 @@ export function createSchemaFromZod( // @public export function createSubRouteRef< Path extends string, - ParentParams extends AnyRouteParams = never, + ParentParams extends AnyRouteRefParams = never, >(config: { path: Path; parent: RouteRef; @@ -414,7 +414,7 @@ export interface ExtensionOverridesOptions { // @public export interface ExternalRouteRef< - TParams extends AnyRouteParams = AnyRouteParams, + TParams extends AnyRouteRefParams = AnyRouteRefParams, TOptional extends boolean = boolean, > { // (undocumented) @@ -454,14 +454,16 @@ export type PortableSchema = { }; // @public -export type RouteFunc = ( +export type RouteFunc = ( ...[params]: TParams extends undefined ? readonly [] : readonly [params: TParams] ) => string; // @public -export interface RouteRef { +export interface RouteRef< + TParams extends AnyRouteRefParams = AnyRouteRefParams, +> { // (undocumented) readonly $$type: '@backstage/RouteRef'; // (undocumented) @@ -469,7 +471,9 @@ export interface RouteRef { } // @public -export interface SubRouteRef { +export interface SubRouteRef< + TParams extends AnyRouteRefParams = AnyRouteRefParams, +> { // (undocumented) readonly $$type: '@backstage/SubRouteRef'; // (undocumented) @@ -481,18 +485,18 @@ export interface SubRouteRef { // @public export function useRouteRef< TOptional extends boolean, - TParams extends AnyRouteParams, + TParams extends AnyRouteRefParams, >( routeRef: ExternalRouteRef, ): TParams extends true ? RouteFunc | undefined : RouteFunc; // @public -export function useRouteRef( +export function useRouteRef( routeRef: RouteRef | SubRouteRef, ): RouteFunc; // @public -export function useRouteRefParams( +export function useRouteRefParams( _routeRef: RouteRef | SubRouteRef, ): Params; ``` diff --git a/packages/frontend-plugin-api/src/routing/ExternalRouteRef.test.ts b/packages/frontend-plugin-api/src/routing/ExternalRouteRef.test.ts index ad47941833..727dc1f53e 100644 --- a/packages/frontend-plugin-api/src/routing/ExternalRouteRef.test.ts +++ b/packages/frontend-plugin-api/src/routing/ExternalRouteRef.test.ts @@ -19,7 +19,7 @@ import { createExternalRouteRef, toInternalExternalRouteRef, } from './ExternalRouteRef'; -import { AnyRouteParams } from './types'; +import { AnyRouteRefParams } from './types'; describe('ExternalRouteRef', () => { it('should be created', () => { @@ -67,7 +67,7 @@ describe('ExternalRouteRef', () => { it('should properly infer and validate parameter types and assignments', () => { function checkRouteRef< - T extends AnyRouteParams, + T extends AnyRouteRefParams, TOptional extends boolean, TCheck extends TOptional, >( diff --git a/packages/frontend-plugin-api/src/routing/ExternalRouteRef.ts b/packages/frontend-plugin-api/src/routing/ExternalRouteRef.ts index ad5ad05f05..c9aabdef27 100644 --- a/packages/frontend-plugin-api/src/routing/ExternalRouteRef.ts +++ b/packages/frontend-plugin-api/src/routing/ExternalRouteRef.ts @@ -16,7 +16,7 @@ import { RouteRefImpl } from './RouteRef'; import { describeParentCallSite } from './describeParentCallSite'; -import { AnyRouteParams } from './types'; +import { AnyRouteRefParams } from './types'; /** * Route descriptor, to be later bound to a concrete route by the app. Used to implement cross-plugin route references. @@ -28,7 +28,7 @@ import { AnyRouteParams } from './types'; * @public */ export interface ExternalRouteRef< - TParams extends AnyRouteParams = AnyRouteParams, + TParams extends AnyRouteRefParams = AnyRouteRefParams, TOptional extends boolean = boolean, > { readonly $$type: '@backstage/ExternalRouteRef'; @@ -38,7 +38,7 @@ export interface ExternalRouteRef< /** @internal */ export interface InternalExternalRouteRef< - TParams extends AnyRouteParams = AnyRouteParams, + TParams extends AnyRouteRefParams = AnyRouteRefParams, TOptional extends boolean = boolean, > extends ExternalRouteRef { readonly version: 'v1'; @@ -50,7 +50,7 @@ export interface InternalExternalRouteRef< /** @internal */ export function toInternalExternalRouteRef< - TParams extends AnyRouteParams = AnyRouteParams, + TParams extends AnyRouteRefParams = AnyRouteRefParams, TOptional extends boolean = boolean, >( resource: ExternalRouteRef, diff --git a/packages/frontend-plugin-api/src/routing/RouteRef.test.ts b/packages/frontend-plugin-api/src/routing/RouteRef.test.ts index c8d7c22e35..de7a3de887 100644 --- a/packages/frontend-plugin-api/src/routing/RouteRef.test.ts +++ b/packages/frontend-plugin-api/src/routing/RouteRef.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { AnyRouteParams } from './types'; +import { AnyRouteRefParams } from './types'; import { RouteRef, createRouteRef, toInternalRouteRef } from './RouteRef'; describe('RouteRef', () => { @@ -54,7 +54,7 @@ describe('RouteRef', () => { }); it('should properly infer and validate parameter types and assignments', () => { - function checkRouteRef( + function checkRouteRef( _ref: RouteRef, _params: T extends undefined ? undefined : T, ) {} diff --git a/packages/frontend-plugin-api/src/routing/RouteRef.ts b/packages/frontend-plugin-api/src/routing/RouteRef.ts index 1085644993..da562e5273 100644 --- a/packages/frontend-plugin-api/src/routing/RouteRef.ts +++ b/packages/frontend-plugin-api/src/routing/RouteRef.ts @@ -15,7 +15,7 @@ */ import { describeParentCallSite } from './describeParentCallSite'; -import { AnyRouteParams } from './types'; +import { AnyRouteRefParams } from './types'; /** * Absolute route reference. @@ -26,14 +26,16 @@ import { AnyRouteParams } from './types'; * * @public */ -export interface RouteRef { +export interface RouteRef< + TParams extends AnyRouteRefParams = AnyRouteRefParams, +> { readonly $$type: '@backstage/RouteRef'; readonly T: TParams; } /** @internal */ export interface InternalRouteRef< - TParams extends AnyRouteParams = AnyRouteParams, + TParams extends AnyRouteRefParams = AnyRouteRefParams, > extends RouteRef { readonly version: 'v1'; getParams(): string[]; @@ -44,7 +46,7 @@ export interface InternalRouteRef< /** @internal */ export function toInternalRouteRef< - TParams extends AnyRouteParams = AnyRouteParams, + TParams extends AnyRouteRefParams = AnyRouteRefParams, >(resource: RouteRef): InternalRouteRef { const r = resource as InternalRouteRef; if (r.$$type !== '@backstage/RouteRef') { diff --git a/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts b/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts index 5b1ef6d836..b04728c49b 100644 --- a/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts +++ b/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { AnyRouteParams } from './types'; +import { AnyRouteRefParams } from './types'; import { SubRouteRef, createSubRouteRef, @@ -96,7 +96,7 @@ describe('SubRouteRef', () => { }); it('should properly infer and parse path parameters', () => { - function checkSubRouteRef( + function checkSubRouteRef( _ref: SubRouteRef, _params: T extends undefined ? undefined : T, ) {} diff --git a/packages/frontend-plugin-api/src/routing/SubRouteRef.ts b/packages/frontend-plugin-api/src/routing/SubRouteRef.ts index 5c093afa7a..74996ab4e7 100644 --- a/packages/frontend-plugin-api/src/routing/SubRouteRef.ts +++ b/packages/frontend-plugin-api/src/routing/SubRouteRef.ts @@ -15,7 +15,7 @@ */ import { RouteRef, toInternalRouteRef } from './RouteRef'; -import { AnyRouteParams } from './types'; +import { AnyRouteRefParams } from './types'; // Should match the pattern in react-router const PARAM_PATTERN = /^\w+$/; @@ -29,7 +29,9 @@ const PARAM_PATTERN = /^\w+$/; * * @public */ -export interface SubRouteRef { +export interface SubRouteRef< + TParams extends AnyRouteRefParams = AnyRouteRefParams, +> { readonly $$type: '@backstage/SubRouteRef'; readonly T: TParams; @@ -39,7 +41,7 @@ export interface SubRouteRef { /** @internal */ export interface InternalSubRouteRef< - TParams extends AnyRouteParams = AnyRouteParams, + TParams extends AnyRouteRefParams = AnyRouteRefParams, > extends SubRouteRef { readonly version: 'v1'; @@ -50,7 +52,7 @@ export interface InternalSubRouteRef< /** @internal */ export function toInternalSubRouteRef< - TParams extends AnyRouteParams = AnyRouteParams, + TParams extends AnyRouteRefParams = AnyRouteRefParams, >(resource: SubRouteRef): InternalSubRouteRef { const r = resource as InternalSubRouteRef; if (r.$$type !== '@backstage/SubRouteRef') { @@ -68,7 +70,7 @@ export function isSubRouteRef(opaque: { } /** @internal */ -export class SubRouteRefImpl +export class SubRouteRefImpl implements SubRouteRef { readonly $$type = '@backstage/SubRouteRef'; @@ -127,7 +129,7 @@ type PathParams = { [name in ParamNames]: string }; */ type MergeParams< P1 extends { [param in string]: string }, - P2 extends AnyRouteParams, + P2 extends AnyRouteRefParams, > = (P1[keyof P1] extends never ? {} : P1) & (P2 extends undefined ? {} : P2); /** @@ -145,7 +147,7 @@ type TrimEmptyParams = */ type MakeSubRouteRef< Params extends { [param in string]: string }, - ParentParams extends AnyRouteParams, + ParentParams extends AnyRouteRefParams, > = keyof Params & keyof ParentParams extends never ? SubRouteRef>> : never; @@ -158,7 +160,7 @@ type MakeSubRouteRef< */ export function createSubRouteRef< Path extends string, - ParentParams extends AnyRouteParams = never, + ParentParams extends AnyRouteRefParams = never, >(config: { path: Path; parent: RouteRef; diff --git a/packages/frontend-plugin-api/src/routing/index.ts b/packages/frontend-plugin-api/src/routing/index.ts index d262bbed58..6c25f725b5 100644 --- a/packages/frontend-plugin-api/src/routing/index.ts +++ b/packages/frontend-plugin-api/src/routing/index.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -export type { AnyRouteParams } from './types'; +export type { AnyRouteRefParams } from './types'; export { createRouteRef, type RouteRef } from './RouteRef'; export { createSubRouteRef, type SubRouteRef } from './SubRouteRef'; export { diff --git a/packages/frontend-plugin-api/src/routing/types.ts b/packages/frontend-plugin-api/src/routing/types.ts index 8fe0d7e8a4..3bf1323210 100644 --- a/packages/frontend-plugin-api/src/routing/types.ts +++ b/packages/frontend-plugin-api/src/routing/types.ts @@ -19,4 +19,4 @@ * * @public */ -export type AnyRouteParams = { [param in string]: string } | undefined; +export type AnyRouteRefParams = { [param in string]: string } | undefined; diff --git a/packages/frontend-plugin-api/src/routing/useRouteRef.tsx b/packages/frontend-plugin-api/src/routing/useRouteRef.tsx index 3754d2e6d5..dfcb110930 100644 --- a/packages/frontend-plugin-api/src/routing/useRouteRef.tsx +++ b/packages/frontend-plugin-api/src/routing/useRouteRef.tsx @@ -17,7 +17,7 @@ import { useMemo } from 'react'; import { matchRoutes, useLocation } from 'react-router-dom'; import { useVersionedContext } from '@backstage/version-bridge'; -import { AnyRouteParams } from './types'; +import { AnyRouteRefParams } from './types'; import { RouteRef } from './RouteRef'; import { SubRouteRef } from './SubRouteRef'; import { ExternalRouteRef } from './ExternalRouteRef'; @@ -35,7 +35,7 @@ import { ExternalRouteRef } from './ExternalRouteRef'; * * @public */ -export type RouteFunc = ( +export type RouteFunc = ( ...[params]: TParams extends undefined ? readonly [] : readonly [params: TParams] @@ -45,7 +45,7 @@ export type RouteFunc = ( * @internal */ export interface RouteResolver { - resolve( + resolve( anyRouteRef: | RouteRef | SubRouteRef @@ -67,7 +67,7 @@ export interface RouteResolver { */ export function useRouteRef< TOptional extends boolean, - TParams extends AnyRouteParams, + TParams extends AnyRouteRefParams, >( routeRef: ExternalRouteRef, ): TParams extends true ? RouteFunc | undefined : RouteFunc; @@ -83,7 +83,7 @@ export function useRouteRef< * @returns A function that will in turn return the concrete URL of the `routeRef`. * @public */ -export function useRouteRef( +export function useRouteRef( routeRef: RouteRef | SubRouteRef, ): RouteFunc; @@ -98,7 +98,7 @@ export function useRouteRef( * @returns A function that will in turn return the concrete URL of the `routeRef`. * @public */ -export function useRouteRef( +export function useRouteRef( routeRef: | RouteRef | SubRouteRef diff --git a/packages/frontend-plugin-api/src/routing/useRouteRefParams.ts b/packages/frontend-plugin-api/src/routing/useRouteRefParams.ts index dbe34a4d01..1bbd8ec6b8 100644 --- a/packages/frontend-plugin-api/src/routing/useRouteRefParams.ts +++ b/packages/frontend-plugin-api/src/routing/useRouteRefParams.ts @@ -15,7 +15,7 @@ */ import { useParams } from 'react-router-dom'; -import { AnyRouteParams } from './types'; +import { AnyRouteRefParams } from './types'; import { RouteRef } from './RouteRef'; import { SubRouteRef } from './SubRouteRef'; @@ -24,7 +24,7 @@ import { SubRouteRef } from './SubRouteRef'; * @param _routeRef - Ref of the current route. * @public */ -export function useRouteRefParams( +export function useRouteRefParams( _routeRef: RouteRef | SubRouteRef, ): Params { return useParams() as Params;