export const RouterParams = { /** * @deprecated * Existing usages are permitted for backward compatibility; * however, please avoid adding new references * * use [useNamespace](../shared/providers/Namespace) */ workspaceName: 'workspaceName', ns: 'ns', applicationName: 'applicationName', integrationTestName: 'integrationTestName', releaseName: 'releaseName', activityTab: 'activityTab', pipelineRunName: 'pipelineRunName', taskRunName: 'taskRunName', componentName: 'componentName', commitName: 'commitName', releasePlanName: 'releasePlanName', snapshotName: 'snapshotName', bindingName: 'bindingName', versionRevision: 'versionRevision', groupName: 'groupName', } as const; export type RouterParams = typeof RouterParams; export enum GithubRedirectRouteParams { ns = 'ns', pipelineRunName = 'pipelineRunName', taskName = 'taskName', } /* eslint-disable @typescript-eslint/no-unused-vars */ type ParamsFromPath = Path extends `${infer _}/:${infer Param}/${infer Rest}` ? Param | ParamsFromPath<`/${Rest}`> : Path extends `${infer _}/:${infer Param}` ? Param : never; type ParamObject = T extends never ? object : { [K in T]: string }; type CreatePathOptions = { leadingSlash: boolean; }; export type RouteDefinition = { path: Path; createPath: (params: ParamObject>, options?: CreatePathOptions) => string; extend: (subpath: SubPath) => RouteDefinition<`${Path}/${SubPath}`>; }; export function buildRoute(path: Path): RouteDefinition { return { path, createPath: ( params: ParamObject>, options: CreatePathOptions = { leadingSlash: true }, ): string => { const leadingSlash = options?.leadingSlash; const generatedPath = Object.entries(params).reduce( (acc, [key, value]) => acc.replace(`:${key}`, value), path, ); return leadingSlash ? `/${generatedPath}` : generatedPath; }, extend: (subpath) => { return buildRoute(`${path}/${subpath}`); }, }; }