1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/core/src/renderer/routes/navigate-to-route.injectable.ts
Sebastian Malton 45b630553a Fixup type errors
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2023-03-02 13:30:57 -05:00

40 lines
1.3 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { navigateToUrlInjectionToken } from "../../common/front-end-routing/navigate-to-url-injection-token";
import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token";
import currentlyInClusterFrameInjectable from "./currently-in-cluster-frame.injectable";
import { buildURL } from "@k8slens/utilities";
const navigateToRouteInjectable = getInjectable({
id: "navigate-to-route",
instantiate: (di) => {
const navigateToUrl = di.inject(navigateToUrlInjectionToken);
const currentlyInClusterFrame = di.inject(
currentlyInClusterFrameInjectable,
);
return (route, options) => {
const url = buildURL(route.path, {
// TODO: enhance typing
params: options?.parameters as any,
query: options?.query,
fragment: options?.fragment,
});
navigateToUrl(url, {
...options,
forceRootFrame: currentlyInClusterFrame && route.clusterFrame === false,
});
};
},
injectionToken: navigateToRouteInjectionToken,
});
export default navigateToRouteInjectable;