add defaultTarget to ExternalRouteRef

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-01-23 09:26:38 +01:00
parent 16d0520055
commit 46b63dea67
8 changed files with 117 additions and 30 deletions
@@ -573,6 +573,7 @@ export function createExternalRouteRef<
? (keyof TParams)[]
: TParamKeys[];
optional?: TOptional;
defaultTarget?: string;
}): ExternalRouteRef<
keyof TParams extends never
? undefined
@@ -44,6 +44,7 @@ export interface InternalExternalRouteRef<
readonly version: 'v1';
getParams(): string[];
getDescription(): string;
getDefaultTarget(): string | undefined;
setId(id: string): void;
}
@@ -80,10 +81,15 @@ class ExternalRouteRefImpl
constructor(
readonly optional: boolean,
readonly params: string[] = [],
readonly defaultTarget: string | undefined,
creationSite: string,
) {
super(params, creationSite);
}
getDefaultTarget() {
return this.defaultTarget;
}
}
/**
@@ -115,6 +121,14 @@ export function createExternalRouteRef<
* if they aren't, `useExternalRouteRef` will return `undefined`.
*/
optional?: TOptional;
/**
* The route (typically in another plugin) that this should map to by default.
*
* The string is expected to be on the standard `<plugin id>.<route id>` form,
* for example `techdocs.docRoot`.
*/
defaultTarget?: string;
}): ExternalRouteRef<
keyof TParams extends never
? undefined
@@ -126,6 +140,7 @@ export function createExternalRouteRef<
return new ExternalRouteRefImpl(
Boolean(options?.optional),
options?.params as string[] | undefined,
options?.defaultTarget,
describeParentCallSite(),
) as ExternalRouteRef<any, any>;
}