mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[APM] Revert kbn/typed-react-router-config changes (#120581)
This commit is contained in:
parent
48d18464c8
commit
7f0a6cf8ca
4 changed files with 17 additions and 21 deletions
|
@ -41,10 +41,10 @@ TYPES_DEPS = [
|
|||
"@npm//query-string",
|
||||
"@npm//utility-types",
|
||||
"@npm//@types/jest",
|
||||
"@npm//@types/history",
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/react-router-config",
|
||||
"@npm//@types/react-router-dom",
|
||||
"@npm//@types/history",
|
||||
]
|
||||
|
||||
jsts_transpiler(
|
||||
|
|
|
@ -267,7 +267,6 @@ describe('createRouter', () => {
|
|||
|
||||
const matches = router.matchRoutes('/', history.location);
|
||||
|
||||
// @ts-expect-error 4.3.5 upgrade - router doesn't seem able to merge properly when two routes match
|
||||
expect(matches[1]?.match.params).toEqual({
|
||||
query: {
|
||||
rangeFrom: 'now-30m',
|
||||
|
@ -286,7 +285,6 @@ describe('createRouter', () => {
|
|||
|
||||
expect(matchedRoutes.length).toEqual(4);
|
||||
|
||||
// @ts-expect-error 4.3.5 upgrade - router doesn't seem able to merge properly when two routes match
|
||||
expect(matchedRoutes[matchedRoutes.length - 1].match).toEqual({
|
||||
isExact: true,
|
||||
params: {
|
||||
|
|
|
@ -23,7 +23,7 @@ function toReactRouterPath(path: string) {
|
|||
return path.replace(/(?:{([^\/]+)})/g, ':$1');
|
||||
}
|
||||
|
||||
export function createRouter<TRoute extends Route>(routes: TRoute[]): Router<TRoute[]> {
|
||||
export function createRouter<TRoutes extends Route[]>(routes: TRoutes): Router<TRoutes> {
|
||||
const routesByReactRouterConfig = new Map<ReactRouterConfig, Route>();
|
||||
const reactRouterConfigsByRoute = new Map<Route, ReactRouterConfig>();
|
||||
|
||||
|
@ -181,8 +181,10 @@ export function createRouter<TRoute extends Route>(routes: TRoute[]): Router<TRo
|
|||
);
|
||||
};
|
||||
|
||||
const router = {
|
||||
link,
|
||||
return {
|
||||
link: (path, ...args) => {
|
||||
return link(path, ...args);
|
||||
},
|
||||
getParams: (...args: any[]) => {
|
||||
const matches = matchRoutes(...args);
|
||||
return matches.length
|
||||
|
@ -195,13 +197,11 @@ export function createRouter<TRoute extends Route>(routes: TRoute[]): Router<TRo
|
|||
matchRoutes: (...args: any[]) => {
|
||||
return matchRoutes(...args) as any;
|
||||
},
|
||||
getRoutePath: (route: Route) => {
|
||||
getRoutePath: (route) => {
|
||||
return reactRouterConfigsByRoute.get(route)!.path as string;
|
||||
},
|
||||
getRoutesToMatch: (path: string) => {
|
||||
return getRoutesToMatch(path) as unknown as FlattenRoutesOf<typeof routes>;
|
||||
return getRoutesToMatch(path) as unknown as FlattenRoutesOf<TRoutes>;
|
||||
},
|
||||
};
|
||||
|
||||
return router;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ export interface RouteMatch<TRoute extends Route = Route> {
|
|||
params: t.Type<any>;
|
||||
}
|
||||
? t.TypeOf<TRoute['params']>
|
||||
: AnyObj;
|
||||
: {};
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -160,11 +160,10 @@ interface ReadonlyPlainRoute {
|
|||
}
|
||||
|
||||
export type Route = PlainRoute | ReadonlyPlainRoute;
|
||||
type AnyObj = Record<string, any>;
|
||||
|
||||
interface DefaultOutput {
|
||||
path: AnyObj;
|
||||
query: AnyObj;
|
||||
path: {};
|
||||
query: {};
|
||||
}
|
||||
|
||||
type OutputOfRouteMatch<TRouteMatch extends RouteMatch> = TRouteMatch extends {
|
||||
|
@ -191,21 +190,20 @@ type TypeOfRouteMatch<TRouteMatch extends RouteMatch> = TRouteMatch extends {
|
|||
route: { params: t.Type<any> };
|
||||
}
|
||||
? t.TypeOf<TRouteMatch['route']['params']>
|
||||
: AnyObj;
|
||||
: {};
|
||||
|
||||
type TypeOfMatches<TRouteMatches extends RouteMatch[]> = TRouteMatches extends [RouteMatch]
|
||||
? TypeOfRouteMatch<TRouteMatches[0]>
|
||||
: TRouteMatches extends [RouteMatch, ...infer TNextRouteMatches]
|
||||
? TypeOfRouteMatch<TRouteMatches[0]> &
|
||||
(TNextRouteMatches extends RouteMatch[] ? TypeOfMatches<TNextRouteMatches> : AnyObj)
|
||||
: AnyObj;
|
||||
(TNextRouteMatches extends RouteMatch[] ? TypeOfMatches<TNextRouteMatches> : {})
|
||||
: {};
|
||||
|
||||
export type TypeOf<
|
||||
TRoutes extends Route[],
|
||||
TPath extends PathsOf<TRoutes>,
|
||||
TWithDefaultOutput extends boolean = true
|
||||
> = TypeOfMatches<Match<TRoutes, TPath>> &
|
||||
(TWithDefaultOutput extends true ? DefaultOutput : AnyObj);
|
||||
> = TypeOfMatches<Match<TRoutes, TPath>> & (TWithDefaultOutput extends true ? DefaultOutput : {});
|
||||
|
||||
export type TypeAsArgs<TObject> = keyof TObject extends never
|
||||
? []
|
||||
|
@ -278,7 +276,7 @@ type MapRoute<TRoute extends Route, TParents extends Route[] = []> = MaybeUnion<
|
|||
>;
|
||||
}
|
||||
>
|
||||
: AnyObj
|
||||
: {}
|
||||
>;
|
||||
|
||||
type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]
|
||||
|
@ -343,7 +341,7 @@ type MapRoutes<TRoutes, TParents extends Route[] = []> = TRoutes extends [Route]
|
|||
MapRoute<TRoutes[8], TParents> &
|
||||
MapRoute<TRoutes[7], TParents> &
|
||||
MapRoute<TRoutes[9], TParents>
|
||||
: AnyObj;
|
||||
: {};
|
||||
|
||||
// const element = null as any;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue