From e5c25f94a38243a164b9962d66daff50ddbe2efd Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 3 May 2023 13:22:19 -0400 Subject: [PATCH] chore: Improve typing of front end routes to fix type errors Signed-off-by: Sebastian Malton --- .../front-end-route-injection-token.ts | 78 +++++++++++++++++-- .../navigate-to-route-injection-token.ts | 30 ++++--- .../add-cluster-route.injectable.ts | 16 +--- .../catalog/catalog-route.injectable.ts | 23 ++---- .../catalog/navigate-to-catalog.injectable.ts | 4 +- .../cluster-view-route.injectable.ts | 16 +--- .../navigate-to-cluster-view.injectable.ts | 3 +- .../config-maps-route.injectable.ts | 18 ++--- ...zontal-pod-autoscalers-route.injectable.ts | 20 ++--- .../config/leases/leases-route.injectable.ts | 20 ++--- .../limit-ranges-route.injectable.ts | 20 ++--- ...webhook-configurations-route.injectable.ts | 24 ++---- ...pod-disruption-budgets-route.injectable.ts | 20 ++--- .../priority-classes-route.injectable.ts | 20 ++--- .../resource-quotas-route.injectable.ts | 20 ++--- .../runtime-classes-route.injectable.ts | 20 ++--- .../secrets/secrets-route.injectable.ts | 20 ++--- ...webhook-configurations-route.injectable.ts | 20 ++--- ...rtical-pod-autoscalers-route.injectable.ts | 20 ++--- .../custom-resources-route.injectable.ts | 22 +----- ...navigate-to-custom-resources.injectable.ts | 3 +- .../cluster/events/events-route.injectable.ts | 20 ++--- .../charts/helm-charts-route.injectable.ts | 22 +----- .../navigate-to-helm-charts.injectable.ts | 9 +-- .../helm-releases-route.injectable.ts | 17 +--- .../namespaces/namespaces-route.injectable.ts | 20 ++--- .../endpoints/endpoints-route.injectable.ts | 20 ++--- .../ingress-classes-route.injectable.ts | 20 ++--- .../ingresses/ingresses-route.injectable.ts | 34 ++++---- .../network-policies-route.injectable.ts | 20 ++--- .../navigate-to-port-forwards.injectable.ts | 7 +- .../port-forwards-route.injectable.ts | 21 +---- .../services/services-route.injectable.ts | 20 ++--- .../cluster/nodes/nodes-route.injectable.ts | 20 ++--- .../cluster-overview-route.injectable.ts | 20 ++--- ...rsistent-volume-claims-route.injectable.ts | 20 ++--- .../persistent-volumes-route.injectable.ts | 20 ++--- .../storage-classes-route.injectable.ts | 20 ++--- .../cluster-role-bindings-route.injectable.ts | 20 ++--- .../cluster-roles-route.injectable.ts | 20 ++--- .../pod-security-policies-route.injectable.ts | 24 ++---- .../role-bindings-route.injectable.ts | 24 ++---- .../roles/roles-route.injectable.ts | 20 ++--- .../service-accounts-route.injectable.ts | 20 ++--- .../cron-jobs/cron-jobs-route.injectable.ts | 20 ++--- .../daemonsets/daemonsets-route.injectable.ts | 20 ++--- .../deployments-route.injectable.ts | 20 ++--- .../workloads/jobs/jobs-route.injectable.ts | 20 ++--- .../workloads-overview-route.injectable.ts | 16 +--- .../workloads/pods/pods-route.injectable.ts | 20 ++--- .../replicasets-route.injectable.ts | 20 ++--- .../route.injectable.ts | 20 ++--- .../statefulsets-route.injectable.ts | 20 ++--- .../entity-settings-route.injectable.ts | 17 +--- .../extensions/extensions-route.injectable.ts | 16 +--- .../default-welcome-route.injectable.ts | 18 ++--- .../welcome/welcome-route.injectable.ts | 20 +---- .../src/extensions/lens-renderer-extension.ts | 2 +- ...tems-when-cluster-is-not-relevant.test.tsx | 16 ++-- ...tively-hide-kube-object-menu-item.test.tsx | 14 +--- ...uses-when-cluster-is-not-relevant.test.tsx | 16 ++-- ...eactively-hide-kube-object-status.test.tsx | 14 +--- .../show-status-for-a-kube-object.test.tsx | 14 +--- ...debar-and-tab-navigation-for-core.test.tsx | 14 +--- .../visibility-of-sidebar-items.test.tsx | 19 ++--- .../navigating-between-routes.test.tsx | 48 ++++-------- .../preferences/closing-preferences.test.tsx | 28 ++----- ...-route-for-legacy-extensions.injectable.ts | 16 +--- .../common/preferences-route.injectable.ts | 16 +--- .../current-preference-tab-id.injectable.ts | 16 ++-- .../welcome/setting-welcome-page.test.tsx | 2 +- .../navigate-to-route.injectable.ts | 7 +- .../catalog-route-parameters.injectable.ts | 24 ------ .../renderer/components/catalog/catalog.tsx | 51 +++++------- ...luster-view-route-parameters.injectable.ts | 23 ------ .../cluster-manager/cluster-view.tsx | 43 +++++----- .../components/config-leases/leases.tsx | 8 +- .../pod-disruption-budgets.tsx | 8 +- .../priority-classes.tsx | 14 +--- .../runtime-classes.tsx | 14 +--- .../route-parameters.injectable.ts | 24 ------ .../components/custom-resources/view.tsx | 40 +++++----- .../current-entity.injectable.ts | 16 +++- .../route-parameters.injectable.ts | 23 ------ .../src/renderer/components/events/events.tsx | 3 + ...helm-charts-route-parameters.injectable.ts | 24 ------ .../components/helm-charts/helm-charts.tsx | 19 ++--- .../selected-helm-chart.injectable.ts | 20 ++--- ...lm-releases-route-parameters.injectable.ts | 24 ------ .../target-helm-release.injectable.ts | 23 ++++-- .../components/helm-releases/releases.tsx | 20 +++-- ...rt-forwards-route-parameters.injectable.ts | 23 ------ .../network-port-forwards/port-forwards.tsx | 43 +++++----- .../test-utils/get-application-builder.tsx | 16 ++-- ...rame-layout-child-component.injectable.tsx | 18 +++-- .../matched-cluster-id.injectable.ts | 9 ++- .../src/renderer/navigation/page-param.ts | 4 +- .../routes/current-route.injectable.ts | 2 +- ...extension-route-registrator.injectable.tsx | 17 ++-- .../routes/matching-route.injectable.ts | 26 ++++--- .../routes/navigate-to-route.injectable.ts | 5 +- .../src/renderer/routes/page-registration.ts | 3 +- .../routes/route-is-active.injectable.ts | 4 +- .../route-path-parameters.injectable.ts | 15 ++-- ...oute-specific-component-injection-token.ts | 16 ++-- .../utilities/src/type-narrowing.ts | 2 +- 106 files changed, 722 insertions(+), 1286 deletions(-) delete mode 100644 packages/core/src/renderer/components/catalog/catalog-route-parameters.injectable.ts delete mode 100644 packages/core/src/renderer/components/cluster-manager/cluster-view-route-parameters.injectable.ts delete mode 100644 packages/core/src/renderer/components/custom-resources/route-parameters.injectable.ts delete mode 100644 packages/core/src/renderer/components/entity-settings/route-parameters.injectable.ts delete mode 100644 packages/core/src/renderer/components/helm-charts/helm-charts-route-parameters.injectable.ts delete mode 100644 packages/core/src/renderer/components/helm-releases/helm-releases-route-parameters.injectable.ts delete mode 100644 packages/core/src/renderer/components/network-port-forwards/port-forwards-route-parameters.injectable.ts diff --git a/packages/core/src/common/front-end-routing/front-end-route-injection-token.ts b/packages/core/src/common/front-end-routing/front-end-route-injection-token.ts index cf1f9ed87e..9bbe818776 100644 --- a/packages/core/src/common/front-end-routing/front-end-route-injection-token.ts +++ b/packages/core/src/common/front-end-routing/front-end-route-injection-token.ts @@ -2,19 +2,85 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getInjectionToken } from "@ogre-tools/injectable"; +import { isFunction, isString } from "@k8slens/utilities"; +import type { DiContainerForInjection, Injectable } from "@ogre-tools/injectable"; +import { getInjectable, getInjectionToken } from "@ogre-tools/injectable"; import type { IComputedValue } from "mobx"; +import { computed } from "mobx"; +import type { Simplify } from "type-fest"; import type { LensRendererExtension } from "../../extensions/lens-renderer-extension"; -export const frontEndRouteInjectionToken = getInjectionToken>({ +declare const emptyObjectSymbol: unique symbol; + +export interface EmptyObject {[emptyObjectSymbol]?: never} + +export const frontEndRouteInjectionToken = getInjectionToken>({ id: "front-end-route-injection-token", }); -export interface Route { - path: string; +type InferParamFromPart = + Part extends `:${infer Name}?` + ? { [key in Name]?: string } + : Part extends `:${infer Name}` + ? { [key in Name]: string } + : EmptyObject; + +export type HelperInferParamFromPath = + Path extends `/${infer First}/${infer Tail}` + ? InferParamFromPart & HelperInferParamFromPath<`/${Tail}`> + : Path extends `/${infer First}` + ? InferParamFromPart + : EmptyObject; + +export type InferParamFromPath = keyof Simplify, typeof emptyObjectSymbol>> extends never + ? EmptyObject + : Simplify, typeof emptyObjectSymbol>>; + +export type ParametersFromRouteInjectable = + RouteInjectable extends Injectable, Route, void> + ? InferParamFromPath + : never; + +export type RouteFromInjectable = + RouteInjectable extends Injectable, Route, void> + ? Route + : never; + +export interface Route { + id: string; + path: Path; clusterFrame: boolean; isEnabled: IComputedValue; extension?: LensRendererExtension; - - readonly parameterSignature?: TParameter; } + +export interface RouteOptions { + id: string; + path: Path | ((di: DiContainerForInjection) => Path); + clusterFrame: boolean; + /** + * defaults to `true` + */ + isEnabled?: IComputedValue | ((di: DiContainerForInjection) => IComputedValue); + extension?: LensRendererExtension; +} + +export const getFrontEndRouteInjectable = ({ + id, + path, + isEnabled, + ...rest +}: RouteOptions) => getInjectable({ + id, + instantiate: (di) => ({ + ...rest, + id, + path: isString(path) + ? path + : path(di), + isEnabled: isFunction(isEnabled) + ? isEnabled(di) + : isEnabled ?? computed(() => true), + }), + injectionToken: frontEndRouteInjectionToken, + }); diff --git a/packages/core/src/common/front-end-routing/navigate-to-route-injection-token.ts b/packages/core/src/common/front-end-routing/navigate-to-route-injection-token.ts index 365c089400..966f99d658 100644 --- a/packages/core/src/common/front-end-routing/navigate-to-route-injection-token.ts +++ b/packages/core/src/common/front-end-routing/navigate-to-route-injection-token.ts @@ -2,9 +2,10 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ +import type { Injectable } from "@ogre-tools/injectable"; import { getInjectionToken } from "@ogre-tools/injectable"; import type { HasRequiredKeys } from "type-fest"; -import type { Route } from "./front-end-route-injection-token"; +import type { InferParamFromPath, Route } from "./front-end-route-injection-token"; export type NavigateWithParameterOptions = ( HasRequiredKeys extends true @@ -12,32 +13,29 @@ export type NavigateWithParameterOptions = ( : { parameters?: TParameters } ); -export type NavigateWithParameterOptionsForRoute = ( - TRoute extends Route - ? NavigateWithParameterOptions - : { parameters?: undefined } -); - export interface BaseNavigateToRouteOptions { query?: Record; fragment?: string; withoutAffectingBackButton?: boolean; } -export type NavigateToRouteOptions = ( - TRoute extends Route - ? ([] | [options: BaseNavigateToRouteOptions]) - : TRoute extends Route - ? HasRequiredKeys extends true - ? [options: BaseNavigateToRouteOptions & { parameters: Params }] - : ([] | [options: BaseNavigateToRouteOptions & { parameters?: Params }]) - : ([] | [options: BaseNavigateToRouteOptions]) +export type NavigateToRouteOptions = ( + HasRequiredKeys> extends true + ? ([options: BaseNavigateToRouteOptions & { parameters: InferParamFromPath }]) + : ([] | [options: BaseNavigateToRouteOptions & { parameters?: InferParamFromPath }]) ); export interface NavigateToRoute { - (route: Route, ...options: NavigateToRouteOptions): void; + (route: Route, ...options: NavigateToRouteOptions): void; } +export type NavigateToSpecificRoute = + InjectableRoute extends Injectable, Route, void> + ? HasRequiredKeys> extends true + ? (parameters: InferParamFromPath) => void + : (parameters?: InferParamFromPath) => void + : never; + export const navigateToRouteInjectionToken = getInjectionToken( { id: "navigate-to-route-injection-token" }, ); diff --git a/packages/core/src/common/front-end-routing/routes/add-cluster/add-cluster-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/add-cluster/add-cluster-route.injectable.ts index 41e165dc59..919ad4325a 100644 --- a/packages/core/src/common/front-end-routing/routes/add-cluster/add-cluster-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/add-cluster/add-cluster-route.injectable.ts @@ -2,20 +2,12 @@ * 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 { computed } from "mobx"; -import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token"; -const addClusterRouteInjectable = getInjectable({ +const addClusterRouteInjectable = getFrontEndRouteInjectable({ id: "add-cluster-route", - - instantiate: () => ({ - path: "/add-cluster", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/add-cluster", + clusterFrame: false, }); export default addClusterRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/catalog/catalog-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/catalog/catalog-route.injectable.ts index bfe0904073..45213786e7 100644 --- a/packages/core/src/common/front-end-routing/routes/catalog/catalog-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/catalog/catalog-route.injectable.ts @@ -2,26 +2,15 @@ * 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 { computed } from "mobx"; -import type { Route } from "../../front-end-route-injection-token"; -import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token"; +import type { ParametersFromRouteInjectable } from "../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token"; -export interface CatalogPathParameters { - group?: string; - kind?: string; -} +export type CatalogPathParameters = ParametersFromRouteInjectable; -const catalogRouteInjectable = getInjectable({ +const catalogRouteInjectable = getFrontEndRouteInjectable({ id: "catalog-route", - - instantiate: (): Route => ({ - path: "/catalog/:group?/:kind?", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/catalog/:group?/:kind?", + clusterFrame: false, }); export default catalogRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/catalog/navigate-to-catalog.injectable.ts b/packages/core/src/common/front-end-routing/routes/catalog/navigate-to-catalog.injectable.ts index bf067910a8..a3951c2db4 100644 --- a/packages/core/src/common/front-end-routing/routes/catalog/navigate-to-catalog.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/catalog/navigate-to-catalog.injectable.ts @@ -16,9 +16,7 @@ const navigateToCatalogInjectable = getInjectable({ const navigateToRoute = di.inject(navigateToRouteInjectionToken); const catalogRoute = di.inject(catalogRouteInjectable); - return (parameters) => navigateToRoute(catalogRoute, { - parameters, - }); + return (parameters) => navigateToRoute(catalogRoute, { parameters }); }, }); diff --git a/packages/core/src/common/front-end-routing/routes/cluster-view/cluster-view-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster-view/cluster-view-route.injectable.ts index e912ff63e0..7801c95e89 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster-view/cluster-view-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster-view/cluster-view-route.injectable.ts @@ -2,20 +2,12 @@ * 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 { computed } from "mobx"; -import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token"; -const clusterViewRouteInjectable = getInjectable({ +const clusterViewRouteInjectable = getFrontEndRouteInjectable({ id: "cluster-view-route", - - instantiate: () => ({ - path: "/cluster/:clusterId", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/cluster/:clusterId", + clusterFrame: false, }); export default clusterViewRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable.ts index 4edc3d3bb5..292bdaaf89 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable.ts @@ -15,8 +15,7 @@ const navigateToClusterViewInjectable = getInjectable({ const navigateToRoute = di.inject(navigateToRouteInjectionToken); const route = di.inject(clusterViewRouteInjectable); - return (clusterId) => - navigateToRoute(route, { parameters: { clusterId }}); + return (clusterId) => navigateToRoute(route, { parameters: { clusterId }}); }, }); diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/config-maps/config-maps-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/config-maps/config-maps-route.injectable.ts index c6a525269c..08f102ba50 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/config-maps/config-maps-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/config-maps/config-maps-route.injectable.ts @@ -2,21 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const configMapsRouteInjectable = getInjectable({ +const configMapsRouteInjectable = getFrontEndRouteInjectable({ id: "config-maps-route", - instantiate: (di) => ({ - path: "/configmaps", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "configmaps", - group: "", - }), + path: "/configmaps", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "configmaps", + group: "", }), - injectionToken: frontEndRouteInjectionToken, }); export default configMapsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/horizontal-pod-autoscalers-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/horizontal-pod-autoscalers-route.injectable.ts index cef3bdcb5a..25ce258eff 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/horizontal-pod-autoscalers-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/horizontal-pod-autoscalers/horizontal-pod-autoscalers-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const horizontalPodAutoscalersRouteInjectable = getInjectable({ +const horizontalPodAutoscalersRouteInjectable = getFrontEndRouteInjectable({ id: "horizontal-pod-autoscalers-route", - - instantiate: (di) => ({ - path: "/hpa", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "horizontalpodautoscalers", - group: "autoscaling", - }), + path: "/hpa", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "horizontalpodautoscalers", + group: "autoscaling", }), - - injectionToken: frontEndRouteInjectionToken, }); export default horizontalPodAutoscalersRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/leases/leases-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/leases/leases-route.injectable.ts index 6da3564c8f..dfca75bd63 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/leases/leases-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/leases/leases-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const leasesRouteInjectable = getInjectable({ +const leasesRouteInjectable = getFrontEndRouteInjectable({ id: "leases", - - instantiate: (di) => ({ - path: "/leases", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "leases", - group: "coordination.k8s.io", - }), + path: "/leases", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "leases", + group: "coordination.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default leasesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/limit-ranges/limit-ranges-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/limit-ranges/limit-ranges-route.injectable.ts index a80a9e8ef4..1ca88a2e6d 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/limit-ranges/limit-ranges-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/limit-ranges/limit-ranges-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const limitRangesRouteInjectable = getInjectable({ +const limitRangesRouteInjectable = getFrontEndRouteInjectable({ id: "limit-ranges-route", - - instantiate: (di) => ({ - path: "/limitranges", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "limitranges", - group: "", - }), + path: "/limitranges", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "limitranges", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default limitRangesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/mutating-webhook-configurations/mutating-webhook-configurations-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/mutating-webhook-configurations/mutating-webhook-configurations-route.injectable.ts index 5812f1258d..c8baa2792b 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/mutating-webhook-configurations/mutating-webhook-configurations-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/mutating-webhook-configurations/mutating-webhook-configurations-route.injectable.ts @@ -2,25 +2,17 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { - shouldShowResourceInjectionToken, -} from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; -import { getInjectable } from "@ogre-tools/injectable"; +import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const mutatingWebhookConfigurationsRouteInjectable = getInjectable({ +const mutatingWebhookConfigurationsRouteInjectable = getFrontEndRouteInjectable({ id: "mutatingwebhookconfigurations", - - instantiate: (di) => ({ - path: "/mutatingwebhookconfigurations", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "mutatingwebhookconfigurations", - group: "admissionregistration.k8s.io", - }), + path: "/mutatingwebhookconfigurations", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "mutatingwebhookconfigurations", + group: "admissionregistration.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default mutatingWebhookConfigurationsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/pod-disruption-budgets/pod-disruption-budgets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/pod-disruption-budgets/pod-disruption-budgets-route.injectable.ts index e297c7396e..0aed502157 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/pod-disruption-budgets/pod-disruption-budgets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/pod-disruption-budgets/pod-disruption-budgets-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const podDisruptionBudgetsRouteInjectable = getInjectable({ +const podDisruptionBudgetsRouteInjectable = getFrontEndRouteInjectable({ id: "pod-disruption-budgets-route", - - instantiate: (di) => ({ - path: "/poddisruptionbudgets", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "poddisruptionbudgets", - group: "policy", - }), + path: "/poddisruptionbudgets", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "poddisruptionbudgets", + group: "policy", }), - - injectionToken: frontEndRouteInjectionToken, }); export default podDisruptionBudgetsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.injectable.ts index ea424ec86d..e92069b8b8 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/priority-classes/priority-classes-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const priorityClassesRouteInjectable = getInjectable({ +const priorityClassesRouteInjectable = getFrontEndRouteInjectable({ id: "priority-classes-route", - - instantiate: (di) => ({ - path: "/priorityclasses", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "priorityclasses", - group: "scheduling.k8s.io", - }), + path: "/priorityclasses", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "priorityclasses", + group: "scheduling.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default priorityClassesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/resource-quotas/resource-quotas-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/resource-quotas/resource-quotas-route.injectable.ts index 96704bbc80..44af8968f1 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/resource-quotas/resource-quotas-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/resource-quotas/resource-quotas-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const resourceQuotasRouteInjectable = getInjectable({ +const resourceQuotasRouteInjectable = getFrontEndRouteInjectable({ id: "resource-quotas-route", - - instantiate: (di) => ({ - path: "/resourcequotas", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "resourcequotas", - group: "", - }), + path: "/resourcequotas", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "resourcequotas", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default resourceQuotasRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/runtime-classes/runtime-classes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/runtime-classes/runtime-classes-route.injectable.ts index a088ee2ba4..eeb2285b30 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/runtime-classes/runtime-classes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/runtime-classes/runtime-classes-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const runtimeClassesRouteInjectable = getInjectable({ +const runtimeClassesRouteInjectable = getFrontEndRouteInjectable({ id: "runtime-classes-route", - - instantiate: (di) => ({ - path: "/runtimeclasses", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "runtimeclasses", - group: "node.k8s.io", - }), + path: "/runtimeclasses", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "runtimeclasses", + group: "node.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default runtimeClassesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/secrets/secrets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/secrets/secrets-route.injectable.ts index 38343e4729..97e1eb0a88 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/secrets/secrets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/secrets/secrets-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const secretsRouteInjectable = getInjectable({ +const secretsRouteInjectable = getFrontEndRouteInjectable({ id: "secrets-route", - - instantiate: (di) => ({ - path: "/secrets", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "secrets", - group: "", - }), + path: "/secrets", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "secrets", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default secretsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/validating-webhook-configurations/validating-webhook-configurations-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/validating-webhook-configurations/validating-webhook-configurations-route.injectable.ts index 6307238350..595c45982b 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/validating-webhook-configurations/validating-webhook-configurations-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/validating-webhook-configurations/validating-webhook-configurations-route.injectable.ts @@ -3,22 +3,16 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; -import { getInjectable } from "@ogre-tools/injectable"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const validatingWebhookConfigurationsRouteInjectable = getInjectable({ +const validatingWebhookConfigurationsRouteInjectable = getFrontEndRouteInjectable({ id: "validatingwebhookconfigurations", - - instantiate: (di) => ({ - path: "/validatingwebhookconfigurations", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "validatingwebhookconfigurations", - group: "admissionregistration.k8s.io", - }), + path: "/validatingwebhookconfigurations", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "validatingwebhookconfigurations", + group: "admissionregistration.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default validatingWebhookConfigurationsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/config/vertical-pod-autoscalers/vertical-pod-autoscalers-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/config/vertical-pod-autoscalers/vertical-pod-autoscalers-route.injectable.ts index 07559a8d2a..0169405f58 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/config/vertical-pod-autoscalers/vertical-pod-autoscalers-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/config/vertical-pod-autoscalers/vertical-pod-autoscalers-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const verticalPodAutoscalersRouteInjectable = getInjectable({ +const verticalPodAutoscalersRouteInjectable = getFrontEndRouteInjectable({ id: "vertical-pod-autoscalers-route", - - instantiate: (di) => ({ - path: "/vpa", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "verticalpodautoscalers", - group: "autoscaling.k8s.io", - }), + path: "/vpa", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "verticalpodautoscalers", + group: "autoscaling.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default verticalPodAutoscalersRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable.ts index ada023cf0b..c0395ffa1d 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable.ts @@ -2,26 +2,12 @@ * 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 { computed } from "mobx"; -import type { Route } from "../../../front-end-route-injection-token"; -import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -export interface CustomResourcesPathParameters { - group: string; - name: string; -} - -const customResourcesRouteInjectable = getInjectable({ +const customResourcesRouteInjectable = getFrontEndRouteInjectable({ id: "custom-resources-route", - - instantiate: (): Route => ({ - path: "/crd/:group/:name", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/crd/:group?/:name?", + clusterFrame: true, }); export default customResourcesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resources.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resources.injectable.ts index dcf671ee2e..825bd3caaf 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resources.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/custom-resources/navigate-to-custom-resources.injectable.ts @@ -4,10 +4,9 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { navigateToRouteInjectionToken } from "../../../navigate-to-route-injection-token"; -import type { CustomResourcesPathParameters } from "./custom-resources-route.injectable"; import customResourcesRouteInjectable from "./custom-resources-route.injectable"; -export type NavigateToCustomResources = (parameters: CustomResourcesPathParameters) => void; +export type NavigateToCustomResources = NavigateToSpecificRoute; const navigateToCustomResourcesInjectable = getInjectable({ id: "navigate-to-custom-resources", diff --git a/packages/core/src/common/front-end-routing/routes/cluster/events/events-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/events/events-route.injectable.ts index fd4dfef75d..145371dadb 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/events/events-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/events/events-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../front-end-route-injection-token"; -const eventsRouteInjectable = getInjectable({ +const eventsRouteInjectable = getFrontEndRouteInjectable({ id: "events-route", - - instantiate: (di) => ({ - path: "/events", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "events", - group: "", - }), + path: "/events", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "events", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default eventsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/helm/charts/helm-charts-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/helm/charts/helm-charts-route.injectable.ts index 02161b082a..b00f274eec 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/helm/charts/helm-charts-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/helm/charts/helm-charts-route.injectable.ts @@ -2,26 +2,12 @@ * 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 { computed } from "mobx"; -import type { Route } from "../../../../front-end-route-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -export interface HelmChartsPathParameters { - repo?: string; - chartName?: string; -} - -const helmChartsRouteInjectable = getInjectable({ +const helmChartsRouteInjectable = getFrontEndRouteInjectable({ id: "helm-charts-route", - - instantiate: (): Route => ({ - path: "/helm/charts/:repo?/:chartName?", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/helm/charts/:repo?/:chartName?", + clusterFrame: true, }); export default helmChartsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable.ts index 37ab96cc2c..2e34303070 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable.ts @@ -3,11 +3,11 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { HelmChartsPathParameters } from "./helm-charts-route.injectable"; import helmChartsRouteInjectable from "./helm-charts-route.injectable"; +import type { NavigateToSpecificRoute } from "../../../../navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token"; -export type NavigateToHelmCharts = (parameters?: HelmChartsPathParameters) => void; +export type NavigateToHelmCharts = NavigateToSpecificRoute; const navigateToHelmChartsInjectable = getInjectable({ id: "navigate-to-helm-charts", @@ -16,10 +16,7 @@ const navigateToHelmChartsInjectable = getInjectable({ const navigateToRoute = di.inject(navigateToRouteInjectionToken); const route = di.inject(helmChartsRouteInjectable); - return (parameters) => - navigateToRoute(route, { - parameters, - }); + return (parameters) => navigateToRoute(route, { parameters }); }, }); diff --git a/packages/core/src/common/front-end-routing/routes/cluster/helm/releases/helm-releases-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/helm/releases/helm-releases-route.injectable.ts index fb66416c63..fac062fea4 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/helm/releases/helm-releases-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/helm/releases/helm-releases-route.injectable.ts @@ -2,26 +2,17 @@ * 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 { computed } from "mobx"; -import type { Route } from "../../../../front-end-route-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; export interface HelmReleasesPathParameters { namespace?: string; name?: string; } -const helmReleasesRouteInjectable = getInjectable({ +const helmReleasesRouteInjectable = getFrontEndRouteInjectable({ id: "helm-releases-route", - - instantiate: (): Route => ({ - path: "/helm/releases/:namespace?/:name?", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/helm/releases/:namespace?/:name?", + clusterFrame: true, }); export default helmReleasesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/namespaces/namespaces-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/namespaces/namespaces-route.injectable.ts index 6fb569fc11..b34554f9c6 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/namespaces/namespaces-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/namespaces/namespaces-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../front-end-route-injection-token"; -const namespacesRouteInjectable = getInjectable({ +const namespacesRouteInjectable = getFrontEndRouteInjectable({ id: "namespaces-route", - - instantiate: (di) => ({ - path: "/namespaces", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "namespaces", - group: "", - }), + path: "/namespaces", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "namespaces", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default namespacesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/endpoints/endpoints-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/endpoints/endpoints-route.injectable.ts index d8dcf8aa8f..5638f65a50 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/endpoints/endpoints-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/endpoints/endpoints-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const endpointsRouteInjectable = getInjectable({ +const endpointsRouteInjectable = getFrontEndRouteInjectable({ id: "endpoints-route", - - instantiate: (di) => ({ - path: "/endpoints", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "endpoints", - group: "", - }), + path: "/endpoints", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "endpoints", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default endpointsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classes-route.injectable.ts index 6ea8ffd736..7889f3b163 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/ingress-class/ingress-classes-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -const ingressClassesRouteInjectable = getInjectable({ +const ingressClassesRouteInjectable = getFrontEndRouteInjectable({ id: "ingress-classes-route", - - instantiate: (di) => ({ - path: "/ingress-classes", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "ingressclasses", - group: "networking.k8s.io", - }), + path: "/ingress-classes", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "ingressclasses", + group: "networking.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default ingressClassesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/ingresses/ingresses-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/ingresses/ingresses-route.injectable.ts index c2a6fe33cc..a752535f92 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/ingresses/ingresses-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/ingresses/ingresses-route.injectable.ts @@ -2,30 +2,24 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; import { computedOr } from "@k8slens/utilities"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const ingressesRouteInjectable = getInjectable({ +const ingressesRouteInjectable = getFrontEndRouteInjectable({ id: "ingresses-route", - - instantiate: (di) => ({ - path: "/ingresses", - clusterFrame: true, - isEnabled: computedOr( - di.inject(shouldShowResourceInjectionToken, { - apiName: "ingresses", - group: "networking.k8s.io", - }), - di.inject(shouldShowResourceInjectionToken, { - apiName: "ingresses", - group: "extensions", - }), - ), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/ingresses", + clusterFrame: true, + isEnabled: (di) => computedOr( + di.inject(shouldShowResourceInjectionToken, { + apiName: "ingresses", + group: "networking.k8s.io", + }), + di.inject(shouldShowResourceInjectionToken, { + apiName: "ingresses", + group: "extensions", + }), + ), }); export default ingressesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable.ts index 664eefa9f1..867e2f96e8 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/network-policies/network-policies-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const networkPoliciesRouteInjectable = getInjectable({ +const networkPoliciesRouteInjectable = getFrontEndRouteInjectable({ id: "network-policies-route", - - instantiate: (di) => ({ - path: "/network-policies", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "networkpolicies", - group: "networking.k8s.io", - }), + path: "/network-policies", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "networkpolicies", + group: "networking.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default networkPoliciesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable.ts index 9a03eeda47..351836bb2c 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable.ts @@ -3,11 +3,11 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import type { PortForwardsPathParameters } from "./port-forwards-route.injectable"; import portForwardsRouteInjectable from "./port-forwards-route.injectable"; +import type { NavigateToSpecificRoute } from "../../../../navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token"; -export type NavigateToPortForwards = (parameters?: PortForwardsPathParameters) => void; +export type NavigateToPortForwards = NavigateToSpecificRoute; const navigateToPortForwardsInjectable = getInjectable({ id: "navigate-to-port-forwards", @@ -16,8 +16,7 @@ const navigateToPortForwardsInjectable = getInjectable({ const navigateToRoute = di.inject(navigateToRouteInjectionToken); const route = di.inject(portForwardsRouteInjectable); - return (parameters) => - navigateToRoute(route, { parameters }); + return (parameters) => navigateToRoute(route, { parameters }); }, }); diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/port-forwards/port-forwards-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/port-forwards/port-forwards-route.injectable.ts index 7788e78559..e10839db55 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/port-forwards/port-forwards-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/port-forwards/port-forwards-route.injectable.ts @@ -2,25 +2,12 @@ * 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 { computed } from "mobx"; -import type { Route } from "../../../../front-end-route-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -export interface PortForwardsPathParameters { - forwardPort?: string; -} - -const portForwardsRouteInjectable = getInjectable({ +const portForwardsRouteInjectable = getFrontEndRouteInjectable({ id: "port-forwards-route", - - instantiate: (): Route => ({ - path: "/port-forwards/:forwardPort?", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/port-forwards/:forwardPort?", + clusterFrame: true, }); export default portForwardsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/network/services/services-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/network/services/services-route.injectable.ts index e9b130b318..8a0e2a4255 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/network/services/services-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/network/services/services-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const servicesRouteInjectable = getInjectable({ +const servicesRouteInjectable = getFrontEndRouteInjectable({ id: "services-route", - - instantiate: (di) => ({ - path: "/services", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "services", - group: "", - }), + path: "/services", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "services", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default servicesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/nodes/nodes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/nodes/nodes-route.injectable.ts index 1fe80a799b..ec94afbf85 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/nodes/nodes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/nodes/nodes-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../front-end-route-injection-token"; -const nodesRouteInjectable = getInjectable({ +const nodesRouteInjectable = getFrontEndRouteInjectable({ id: "nodes-route", - - instantiate: (di) => ({ - path: "/nodes", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "nodes", - group: "", - }), + path: "/nodes", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "nodes", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default nodesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/overview/cluster-overview-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/overview/cluster-overview-route.injectable.ts index bf9c3961ed..fb43e9d359 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/overview/cluster-overview-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/overview/cluster-overview-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../front-end-route-injection-token"; -const clusterOverviewRouteInjectable = getInjectable({ +const clusterOverviewRouteInjectable = getFrontEndRouteInjectable({ id: "cluster-overview-route", - - instantiate: (di) => ({ - path: "/overview", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "nodes", - group: "", - }), + path: "/overview", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "nodes", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default clusterOverviewRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volume-claims/persistent-volume-claims-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volume-claims/persistent-volume-claims-route.injectable.ts index c8d7b64f8d..214f4af445 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volume-claims/persistent-volume-claims-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volume-claims/persistent-volume-claims-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const persistentVolumeClaimsRouteInjectable = getInjectable({ +const persistentVolumeClaimsRouteInjectable = getFrontEndRouteInjectable({ id: "persistent-volume-claims-route", - - instantiate: (di) => ({ - path: "/persistent-volume-claims", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "persistentvolumeclaims", - group: "", - }), + path: "/persistent-volume-claims", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "persistentvolumeclaims", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default persistentVolumeClaimsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volumes/persistent-volumes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volumes/persistent-volumes-route.injectable.ts index a93ac0a3c8..df2f8a8acd 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volumes/persistent-volumes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/storage/persistent-volumes/persistent-volumes-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const persistentVolumesRouteInjectable = getInjectable({ +const persistentVolumesRouteInjectable = getFrontEndRouteInjectable({ id: "persistent-volumes-route", - - instantiate: (di) => ({ - path: "/persistent-volumes", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "persistentvolumes", - group: "", - }), + path: "/persistent-volumes", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "persistentvolumes", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default persistentVolumesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/storage/storage-classes/storage-classes-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/storage/storage-classes/storage-classes-route.injectable.ts index 0645c0f4eb..c2ac257170 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/storage/storage-classes/storage-classes-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/storage/storage-classes/storage-classes-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const storageClassesRouteInjectable = getInjectable({ +const storageClassesRouteInjectable = getFrontEndRouteInjectable({ id: "storage-classes-route", - - instantiate: (di) => ({ - path: "/storage-classes", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "storageclasses", - group: "storage.k8s.io", - }), + path: "/storage-classes", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "storageclasses", + group: "storage.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default storageClassesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-role-bindings/cluster-role-bindings-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-role-bindings/cluster-role-bindings-route.injectable.ts index 158563f8d5..60e57661ee 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-role-bindings/cluster-role-bindings-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-role-bindings/cluster-role-bindings-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const clusterRoleBindingsRouteInjectable = getInjectable({ +const clusterRoleBindingsRouteInjectable = getFrontEndRouteInjectable({ id: "cluster-role-bindings-route", - - instantiate: (di) => ({ - path: "/cluster-role-bindings", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "clusterrolebindings", - group: "rbac.authorization.k8s.io", - }), + path: "/cluster-role-bindings", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "clusterrolebindings", + group: "rbac.authorization.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default clusterRoleBindingsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-roles/cluster-roles-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-roles/cluster-roles-route.injectable.ts index db28d8dfff..d1488ebdcd 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-roles/cluster-roles-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/cluster-roles/cluster-roles-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const clusterRolesRouteInjectable = getInjectable({ +const clusterRolesRouteInjectable = getFrontEndRouteInjectable({ id: "cluster-roles-route", - - instantiate: (di) => ({ - path: "/cluster-roles", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "clusterroles", - group: "rbac.authorization.k8s.io", - }), + path: "/cluster-roles", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "clusterroles", + group: "rbac.authorization.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default clusterRolesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/pod-security-policies/pod-security-policies-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/pod-security-policies/pod-security-policies-route.injectable.ts index 27f9165be8..b6d868540d 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/pod-security-policies/pod-security-policies-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/pod-security-policies/pod-security-policies-route.injectable.ts @@ -2,25 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const podSecurityPoliciesRouteInjectable = getInjectable({ +const podSecurityPoliciesRouteInjectable = getFrontEndRouteInjectable({ id: "pod-security-policies-route", - - instantiate: (di) => { - return { - path: "/pod-security-policies", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "podsecuritypolicies", - group: "policy", - }), - }; - }, - - injectionToken: frontEndRouteInjectionToken, + path: "/pod-security-policies", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "podsecuritypolicies", + group: "policy", + }), }); export default podSecurityPoliciesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/role-bindings/role-bindings-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/role-bindings/role-bindings-route.injectable.ts index 195210df23..417a5b163d 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/role-bindings/role-bindings-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/role-bindings/role-bindings-route.injectable.ts @@ -2,25 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const roleBindingsRouteInjectable = getInjectable({ +const roleBindingsRouteInjectable = getFrontEndRouteInjectable({ id: "role-bindings-route", - - instantiate: (di) => { - return { - path: "/role-bindings", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "rolebindings", - group: "rbac.authorization.k8s.io", - }), - }; - }, - - injectionToken: frontEndRouteInjectionToken, + path: "/role-bindings", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "rolebindings", + group: "rbac.authorization.k8s.io", + }), }); export default roleBindingsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/roles/roles-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/roles/roles-route.injectable.ts index 807a12177c..7f57b5793c 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/roles/roles-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/roles/roles-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const rolesRouteInjectable = getInjectable({ +const rolesRouteInjectable = getFrontEndRouteInjectable({ id: "roles-route", - - instantiate: (di) => ({ - path: "/roles", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "roles", - group: "rbac.authorization.k8s.io", - }), + path: "/roles", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "roles", + group: "rbac.authorization.k8s.io", }), - - injectionToken: frontEndRouteInjectionToken, }); export default rolesRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/user-management/service-accounts/service-accounts-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/user-management/service-accounts/service-accounts-route.injectable.ts index aecc5a3640..8bac48c736 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/user-management/service-accounts/service-accounts-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/user-management/service-accounts/service-accounts-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const serviceAccountsRouteInjectable = getInjectable({ +const serviceAccountsRouteInjectable = getFrontEndRouteInjectable({ id: "service-accounts-route", - - instantiate: (di) => ({ - path: "/service-accounts", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "serviceaccounts", - group: "", - }), + path: "/service-accounts", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "serviceaccounts", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default serviceAccountsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/cron-jobs/cron-jobs-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/cron-jobs/cron-jobs-route.injectable.ts index 0899486298..5ce80315ae 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/cron-jobs/cron-jobs-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/cron-jobs/cron-jobs-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const cronJobsRouteInjectable = getInjectable({ +const cronJobsRouteInjectable = getFrontEndRouteInjectable({ id: "cron-jobs-route", - - instantiate: (di) => ({ - path: "/cronjobs", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "cronjobs", - group: "batch", - }), + path: "/cronjobs", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "cronjobs", + group: "batch", }), - - injectionToken: frontEndRouteInjectionToken, }); export default cronJobsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/daemonsets/daemonsets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/daemonsets/daemonsets-route.injectable.ts index 42f1329551..a80efcd4a0 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/daemonsets/daemonsets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/daemonsets/daemonsets-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const daemonsetsRouteInjectable = getInjectable({ +const daemonsetsRouteInjectable = getFrontEndRouteInjectable({ id: "daemonsets-route", - - instantiate: (di) => ({ - path: "/daemonsets", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "daemonsets", - group: "apps", - }), + path: "/daemonsets", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "daemonsets", + group: "apps", }), - - injectionToken: frontEndRouteInjectionToken, }); export default daemonsetsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/deployments/deployments-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/deployments/deployments-route.injectable.ts index 222f842981..2c16f8d041 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/deployments/deployments-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/deployments/deployments-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const deploymentsRouteInjectable = getInjectable({ +const deploymentsRouteInjectable = getFrontEndRouteInjectable({ id: "deployments-route", - - instantiate: (di) => ({ - path: "/deployments", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "deployments", - group: "apps", - }), + path: "/deployments", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "deployments", + group: "apps", }), - - injectionToken: frontEndRouteInjectionToken, }); export default deploymentsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/jobs/jobs-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/jobs/jobs-route.injectable.ts index 4933c69531..8a97b691ba 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/jobs/jobs-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/jobs/jobs-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const jobsRouteInjectable = getInjectable({ +const jobsRouteInjectable = getFrontEndRouteInjectable({ id: "jobs-route", - - instantiate: (di) => ({ - path: "/jobs", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "jobs", - group: "batch", - }), + path: "/jobs", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "jobs", + group: "batch", }), - - injectionToken: frontEndRouteInjectionToken, }); export default jobsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/overview/workloads-overview-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/overview/workloads-overview-route.injectable.ts index 188bd9f1de..08d992dec9 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/overview/workloads-overview-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/overview/workloads-overview-route.injectable.ts @@ -2,20 +2,12 @@ * 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 { computed } from "mobx"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const workloadsOverviewRouteInjectable = getInjectable({ +const workloadsOverviewRouteInjectable = getFrontEndRouteInjectable({ id: "workloads-overview-route", - - instantiate: () => ({ - path: "/workloads", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/workloads", + clusterFrame: true, }); export default workloadsOverviewRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/pods/pods-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/pods/pods-route.injectable.ts index 6563896893..d89e58cd31 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/pods/pods-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/pods/pods-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const podsRouteInjectable = getInjectable({ +const podsRouteInjectable = getFrontEndRouteInjectable({ id: "pods-route", - - instantiate: (di) => ({ - path: "/pods", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "pods", - group: "", - }), + path: "/pods", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "pods", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); export default podsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicasets/replicasets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicasets/replicasets-route.injectable.ts index bff60b2b8d..c843fe3621 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicasets/replicasets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/replicasets/replicasets-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const replicasetsRouteInjectable = getInjectable({ +const replicasetsRouteInjectable = getFrontEndRouteInjectable({ id: "replicasets-route", - - instantiate: (di) => ({ - path: "/replicasets", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "replicasets", - group: "apps", - }), + path: "/replicasets", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "replicasets", + group: "apps", }), - - injectionToken: frontEndRouteInjectionToken, }); export default replicasetsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/replication-controllers/route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/replication-controllers/route.injectable.ts index e43712632f..73225d6ecb 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/replication-controllers/route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/replication-controllers/route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const replicationControllersRouteInjectable = getInjectable({ +const replicationControllersRouteInjectable = getFrontEndRouteInjectable({ id: "replication-controllers-route", - - instantiate: (di) => ({ - path: "/replication-controllers", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "replicationcontrollers", - group: "", // core - }), + path: "/replication-controllers", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "replicationcontrollers", + group: "", // core }), - - injectionToken: frontEndRouteInjectionToken, }); export default replicationControllersRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable.ts index 0a0160ccd9..43655478a6 100644 --- a/packages/core/src/common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/cluster/workloads/statefulsets/statefulsets-route.injectable.ts @@ -2,23 +2,17 @@ * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token"; -import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token"; -const statefulsetsRouteInjectable = getInjectable({ +const statefulsetsRouteInjectable = getFrontEndRouteInjectable({ id: "statefulsets-route", - - instantiate: (di) => ({ - path: "/statefulsets", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "statefulsets", - group: "apps", - }), + path: "/statefulsets", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "statefulsets", + group: "apps", }), - - injectionToken: frontEndRouteInjectionToken, }); export default statefulsetsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/entity-settings/entity-settings-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/entity-settings/entity-settings-route.injectable.ts index e7d3ac5f46..6829ee2e5f 100644 --- a/packages/core/src/common/front-end-routing/routes/entity-settings/entity-settings-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/entity-settings/entity-settings-route.injectable.ts @@ -2,25 +2,16 @@ * 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 { computed } from "mobx"; -import type { Route } from "../../front-end-route-injection-token"; -import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token"; export interface EntitySettingsPathParameters { entityId: string; } -const entitySettingsRouteInjectable = getInjectable({ +const entitySettingsRouteInjectable = getFrontEndRouteInjectable({ id: "entity-settings-route", - - instantiate: (): Route => ({ - path: "/entity/:entityId/settings", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/entity/:entityId/settings", + clusterFrame: false, }); export default entitySettingsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/extensions/extensions-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/extensions/extensions-route.injectable.ts index 5992355022..78a9895048 100644 --- a/packages/core/src/common/front-end-routing/routes/extensions/extensions-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/extensions/extensions-route.injectable.ts @@ -2,20 +2,12 @@ * 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 { computed } from "mobx"; -import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token"; -const extensionsRouteInjectable = getInjectable({ +const extensionsRouteInjectable = getFrontEndRouteInjectable({ id: "extensions-route", - - instantiate: () => ({ - path: "/extensions", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/extensions", + clusterFrame: false, }); export default extensionsRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/welcome/default-welcome-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/welcome/default-welcome-route.injectable.ts index d8db889033..9232b975d4 100644 --- a/packages/core/src/common/front-end-routing/routes/welcome/default-welcome-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/welcome/default-welcome-route.injectable.ts @@ -2,25 +2,19 @@ * 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 { computed } from "mobx"; import welcomeRouteConfigInjectable from "./welcome-route-config.injectable"; -import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token"; -const defaultWelcomeRouteInjectable = getInjectable({ +const defaultWelcomeRouteInjectable = getFrontEndRouteInjectable({ id: "default-welcome-route", - - instantiate: (di) => { + path: "/welcome", + clusterFrame: false, + isEnabled: (di) => { const welcomeRoute = di.inject(welcomeRouteConfigInjectable); - return { - path: "/welcome", - clusterFrame: false, - isEnabled: computed(() => welcomeRoute === "/welcome"), - }; + return computed(() => welcomeRoute === "/welcome"); }, - - injectionToken: frontEndRouteInjectionToken, }); export default defaultWelcomeRouteInjectable; diff --git a/packages/core/src/common/front-end-routing/routes/welcome/welcome-route.injectable.ts b/packages/core/src/common/front-end-routing/routes/welcome/welcome-route.injectable.ts index 839a7446c1..870e58e0f8 100644 --- a/packages/core/src/common/front-end-routing/routes/welcome/welcome-route.injectable.ts +++ b/packages/core/src/common/front-end-routing/routes/welcome/welcome-route.injectable.ts @@ -2,25 +2,13 @@ * 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 { computed } from "mobx"; import welcomeRouteConfigInjectable from "./welcome-route-config.injectable"; -import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token"; -const welcomeRouteInjectable = getInjectable({ +const welcomeRouteInjectable = getFrontEndRouteInjectable({ id: "welcome-route", - - instantiate: (di) => { - const welcomeRoute = di.inject(welcomeRouteConfigInjectable); - - return { - path: welcomeRoute, - clusterFrame: false, - isEnabled: computed(() => true), - }; - }, - - injectionToken: frontEndRouteInjectionToken, + path: (di) => di.inject(welcomeRouteConfigInjectable), + clusterFrame: false, }); export default welcomeRouteInjectable; diff --git a/packages/core/src/extensions/lens-renderer-extension.ts b/packages/core/src/extensions/lens-renderer-extension.ts index 555fa1e3cf..56aad1d3b2 100644 --- a/packages/core/src/extensions/lens-renderer-extension.ts +++ b/packages/core/src/extensions/lens-renderer-extension.ts @@ -50,7 +50,7 @@ import type { PageParamInit } from "./renderer-api/navigation"; interface LensRendererExtensionDependencies extends LensExtensionDependencies { navigateToRoute: NavigateToRoute; getExtensionPageParameters: GetExtensionPageParameters; - readonly routes: IComputedValue[]>; + readonly routes: IComputedValue[]>; readonly entityRegistry: CatalogEntityRegistry; readonly categoryRegistry: CatalogCategoryRegistry; } diff --git a/packages/core/src/features/cluster/kube-object-menu/extension-api/disable-kube-object-menu-items-when-cluster-is-not-relevant.test.tsx b/packages/core/src/features/cluster/kube-object-menu/extension-api/disable-kube-object-menu-items-when-cluster-is-not-relevant.test.tsx index c5e4de7e35..1f28485f5b 100644 --- a/packages/core/src/features/cluster/kube-object-menu/extension-api/disable-kube-object-menu-items-when-cluster-is-not-relevant.test.tsx +++ b/packages/core/src/features/cluster/kube-object-menu/extension-api/disable-kube-object-menu-items-when-cluster-is-not-relevant.test.tsx @@ -9,8 +9,8 @@ import type { ApplicationBuilder } from "../../../../renderer/components/test-ut import type { KubernetesCluster } from "../../../../common/catalog-entities"; import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getInjectable } from "@ogre-tools/injectable"; -import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token"; -import { computed, runInAction } from "mobx"; +import { getFrontEndRouteInjectable } from "../../../../common/front-end-routing/front-end-route-injection-token"; +import { runInAction } from "mobx"; import React from "react"; import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token"; import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-injection-token"; @@ -115,16 +115,10 @@ describe("disable kube object menu items when cluster is not relevant", () => { }); }); -const testRouteInjectable = getInjectable({ +const testRouteInjectable = getFrontEndRouteInjectable({ id: "test-route", - - instantiate: () => ({ - path: "/test-route", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/test-route", + clusterFrame: true, }); const testRouteComponentInjectable = getInjectable({ diff --git a/packages/core/src/features/cluster/kube-object-menu/extension-api/reactively-hide-kube-object-menu-item.test.tsx b/packages/core/src/features/cluster/kube-object-menu/extension-api/reactively-hide-kube-object-menu-item.test.tsx index f88ca0e249..dc8828d29f 100644 --- a/packages/core/src/features/cluster/kube-object-menu/extension-api/reactively-hide-kube-object-menu-item.test.tsx +++ b/packages/core/src/features/cluster/kube-object-menu/extension-api/reactively-hide-kube-object-menu-item.test.tsx @@ -6,7 +6,7 @@ import type { RenderResult } from "@testing-library/react"; import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getInjectable } from "@ogre-tools/injectable"; -import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../common/front-end-routing/front-end-route-injection-token"; import type { IObservableValue } from "mobx"; import { observable, runInAction, computed } from "mobx"; import React from "react"; @@ -83,16 +83,10 @@ describe("reactively hide kube object menu item", () => { }); }); -const testRouteInjectable = getInjectable({ +const testRouteInjectable = getFrontEndRouteInjectable({ id: "test-route", - - instantiate: () => ({ - path: "/test-route", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/test-route", + clusterFrame: true, }); const testRouteComponentInjectable = getInjectable({ diff --git a/packages/core/src/features/cluster/kube-object-status-icon/extension-api/disable-kube-object-statuses-when-cluster-is-not-relevant.test.tsx b/packages/core/src/features/cluster/kube-object-status-icon/extension-api/disable-kube-object-statuses-when-cluster-is-not-relevant.test.tsx index 6d1ee34235..6a27311c56 100644 --- a/packages/core/src/features/cluster/kube-object-status-icon/extension-api/disable-kube-object-statuses-when-cluster-is-not-relevant.test.tsx +++ b/packages/core/src/features/cluster/kube-object-status-icon/extension-api/disable-kube-object-statuses-when-cluster-is-not-relevant.test.tsx @@ -9,8 +9,8 @@ import type { ApplicationBuilder } from "../../../../renderer/components/test-ut import type { KubernetesCluster } from "../../../../common/catalog-entities"; import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getInjectable } from "@ogre-tools/injectable"; -import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token"; -import { computed, runInAction } from "mobx"; +import { getFrontEndRouteInjectable } from "../../../../common/front-end-routing/front-end-route-injection-token"; +import { runInAction } from "mobx"; import React from "react"; import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token"; import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-injection-token"; @@ -116,16 +116,10 @@ describe("disable kube object statuses when cluster is not relevant", () => { }); }); -const testRouteInjectable = getInjectable({ +const testRouteInjectable = getFrontEndRouteInjectable({ id: "test-route", - - instantiate: () => ({ - path: "/test-route", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/test-route", + clusterFrame: true, }); const testRouteComponentInjectable = getInjectable({ diff --git a/packages/core/src/features/cluster/kube-object-status-icon/extension-api/reactively-hide-kube-object-status.test.tsx b/packages/core/src/features/cluster/kube-object-status-icon/extension-api/reactively-hide-kube-object-status.test.tsx index 82ee3d4407..534d65dddc 100644 --- a/packages/core/src/features/cluster/kube-object-status-icon/extension-api/reactively-hide-kube-object-status.test.tsx +++ b/packages/core/src/features/cluster/kube-object-status-icon/extension-api/reactively-hide-kube-object-status.test.tsx @@ -6,7 +6,7 @@ import type { RenderResult } from "@testing-library/react"; import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import { getInjectable } from "@ogre-tools/injectable"; -import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../../common/front-end-routing/front-end-route-injection-token"; import type { IObservableValue } from "mobx"; import { observable, runInAction, computed } from "mobx"; import React from "react"; @@ -88,16 +88,10 @@ describe("reactively hide kube object status", () => { }); }); -const testRouteInjectable = getInjectable({ +const testRouteInjectable = getFrontEndRouteInjectable({ id: "test-route", - - instantiate: () => ({ - path: "/test-route", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/test-route", + clusterFrame: true, }); const testRouteComponentInjectable = getInjectable({ diff --git a/packages/core/src/features/cluster/kube-object-status-icon/show-status-for-a-kube-object.test.tsx b/packages/core/src/features/cluster/kube-object-status-icon/show-status-for-a-kube-object.test.tsx index 9d9d9b51eb..950c3acb6e 100644 --- a/packages/core/src/features/cluster/kube-object-status-icon/show-status-for-a-kube-object.test.tsx +++ b/packages/core/src/features/cluster/kube-object-status-icon/show-status-for-a-kube-object.test.tsx @@ -8,7 +8,7 @@ import type { DiContainer } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable"; import type { IAtom } from "mobx"; import { runInAction, createAtom, computed } from "mobx"; -import { frontEndRouteInjectionToken } from "../../../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; import { routeSpecificComponentInjectionToken } from "../../../renderer/routes/route-specific-component-injection-token"; import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder"; @@ -262,16 +262,10 @@ describe("show status for a kube object", () => { }); }); -const testRouteInjectable = getInjectable({ +const testRouteInjectable = getFrontEndRouteInjectable({ id: "test-route", - - instantiate: () => ({ - path: "/test-route", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/test-route", + clusterFrame: true, }); const rerenderParentFor = (atom: IAtom) => () => { diff --git a/packages/core/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx b/packages/core/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx index 0207d28e3f..d05e0aee52 100644 --- a/packages/core/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx +++ b/packages/core/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx @@ -12,7 +12,7 @@ import { sidebarItemInjectionToken } from "@k8slens/cluster-sidebar"; import { computed, runInAction } from "mobx"; import { noop } from "lodash/fp"; import routeIsActiveInjectable from "../../renderer/routes/route-is-active.injectable"; -import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../common/front-end-routing/front-end-route-injection-token"; import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import writeJsonFileInjectable from "../../common/fs/write-json-file.injectable"; @@ -324,16 +324,10 @@ const someChildSidebarItemInjectable = getInjectable({ injectionToken: sidebarItemInjectionToken, }); -const testRouteInjectable = getInjectable({ +const testRouteInjectable = getFrontEndRouteInjectable({ id: "some-route-injectable-id", - - instantiate: () => ({ - path: "/some-child-page", - clusterFrame: true, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/some-child-page", + clusterFrame: true, }); const testRouteComponentInjectable = getInjectable({ diff --git a/packages/core/src/features/cluster/visibility-of-sidebar-items.test.tsx b/packages/core/src/features/cluster/visibility-of-sidebar-items.test.tsx index 8f3b37fa45..61bfcf615d 100644 --- a/packages/core/src/features/cluster/visibility-of-sidebar-items.test.tsx +++ b/packages/core/src/features/cluster/visibility-of-sidebar-items.test.tsx @@ -8,7 +8,7 @@ import { sidebarItemInjectionToken } from "@k8slens/cluster-sidebar"; import { runInAction } from "mobx"; import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token"; import React from "react"; -import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../common/front-end-routing/front-end-route-injection-token"; import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token"; @@ -68,19 +68,14 @@ describe("cluster - visibility of sidebar items", () => { }); }); -const testRouteInjectable = getInjectable({ +const testRouteInjectable = getFrontEndRouteInjectable({ id: "some-route-injectable-id", - - instantiate: (di) => ({ - path: "/some-child-page", - clusterFrame: true, - isEnabled: di.inject(shouldShowResourceInjectionToken, { - apiName: "namespaces", - group: "", - }), + path: "/some-child-page", + clusterFrame: true, + isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, { + apiName: "namespaces", + group: "", }), - - injectionToken: frontEndRouteInjectionToken, }); const testRouteComponentInjectable = getInjectable({ diff --git a/packages/core/src/features/navigating-between-routes.test.tsx b/packages/core/src/features/navigating-between-routes.test.tsx index 2d23de46b4..a1a6fcda24 100644 --- a/packages/core/src/features/navigating-between-routes.test.tsx +++ b/packages/core/src/features/navigating-between-routes.test.tsx @@ -5,12 +5,12 @@ import type { DiContainer } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable"; import React from "react"; -import { computed, runInAction } from "mobx"; +import { runInAction } from "mobx"; import type { RenderResult } from "@testing-library/react"; import { routeSpecificComponentInjectionToken } from "../renderer/routes/route-specific-component-injection-token"; import { observer } from "mobx-react"; -import type { Route } from "../common/front-end-routing/front-end-route-injection-token"; -import { frontEndRouteInjectionToken } from "../common/front-end-routing/front-end-route-injection-token"; +import type { RouteFromInjectable } from "../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../common/front-end-routing/front-end-route-injection-token"; import type { ApplicationBuilder } from "../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../renderer/components/test-utils/get-application-builder"; import currentRouteInjectable from "../renderer/routes/current-route.injectable"; @@ -44,7 +44,7 @@ describe("navigating between routes", () => { }); describe("when navigating to route", () => { - let route: Route; + let route: RouteFromInjectable; beforeEach(() => { const navigateToRoute = windowDi.inject(navigateToRouteInjectionToken); @@ -77,7 +77,7 @@ describe("navigating between routes", () => { }); it("does not have path parameters", () => { - const pathParameters = windowDi.inject(routePathParametersInjectable, route); + const pathParameters = windowDi.inject(routePathParametersInjectable)(route); expect(pathParameters.get()).toEqual({}); }); @@ -120,10 +120,7 @@ describe("navigating between routes", () => { }); describe("when navigating to route with path parameters", () => { - let route: Route<{ - someParameter?: string | undefined; - someOtherParameter?: string | undefined; - }>; + let route: RouteFromInjectable; beforeEach(() => { route = windowDi.inject(routeWithOptionalPathParametersInjectable); @@ -157,7 +154,7 @@ describe("navigating between routes", () => { }); it("knows path parameters", () => { - const pathParameters = windowDi.inject(routePathParametersInjectable, route); + const pathParameters = windowDi.inject(routePathParametersInjectable)(route); expect(pathParameters.get()).toEqual({ someParameter: "some-value", @@ -167,10 +164,7 @@ describe("navigating between routes", () => { }); describe("when navigating to route without path parameters", () => { - let route: Route<{ - someParameter?: string | undefined; - someOtherParameter?: string | undefined; - }>; + let route: RouteFromInjectable; beforeEach(() => { route = windowDi.inject(routeWithOptionalPathParametersInjectable); @@ -193,7 +187,7 @@ describe("navigating between routes", () => { }); it("knows path parameters", () => { - const pathParameters = windowDi.inject(routePathParametersInjectable, route); + const pathParameters = windowDi.inject(routePathParametersInjectable)(route); expect(pathParameters.get()).toEqual({ someParameter: undefined, @@ -204,15 +198,10 @@ describe("navigating between routes", () => { }); }); -const testRouteWithoutPathParametersInjectable = getInjectable({ +const testRouteWithoutPathParametersInjectable = getFrontEndRouteInjectable({ id: "some-route", - injectionToken: frontEndRouteInjectionToken, - - instantiate: (): Route => ({ - path: "/some-path", - clusterFrame: false, - isEnabled: computed(() => true), - }), + path: "/some-path", + clusterFrame: false, }); const testRouteWithoutPathParametersComponentInjectable = getInjectable({ @@ -226,15 +215,10 @@ const testRouteWithoutPathParametersComponentInjectable = getInjectable({ injectionToken: routeSpecificComponentInjectionToken, }); -const routeWithOptionalPathParametersInjectable = getInjectable({ +const routeWithOptionalPathParametersInjectable = getFrontEndRouteInjectable({ id: "some-route", - injectionToken: frontEndRouteInjectionToken, - - instantiate: (): Route<{ someParameter?: string; someOtherParameter?: string }> => ({ - path: "/some-path/:someParameter?/:someOtherParameter?", - clusterFrame: false, - isEnabled: computed(() => true), - }), + path: "/some-path/:someParameter?/:someOtherParameter?", + clusterFrame: false, }); const routeWithOptionalPathParametersComponentInjectable = getInjectable({ @@ -242,7 +226,7 @@ const routeWithOptionalPathParametersComponentInjectable = getInjectable({ instantiate: (di) => { const route = di.inject(routeWithOptionalPathParametersInjectable); - const pathParameters = di.inject(routePathParametersInjectable, route); + const pathParameters = di.inject(routePathParametersInjectable)(route); return { route, diff --git a/packages/core/src/features/preferences/closing-preferences.test.tsx b/packages/core/src/features/preferences/closing-preferences.test.tsx index 83f8f215b9..d2e243bff4 100644 --- a/packages/core/src/features/preferences/closing-preferences.test.tsx +++ b/packages/core/src/features/preferences/closing-preferences.test.tsx @@ -8,8 +8,8 @@ import type { RenderResult } from "@testing-library/react"; import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import currentPathInjectable from "../../renderer/routes/current-path.injectable"; -import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token"; -import { computed, runInAction } from "mobx"; +import { getFrontEndRouteInjectable } from "../../common/front-end-routing/front-end-route-injection-token"; +import { runInAction } from "mobx"; import React from "react"; import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token"; import { observableHistoryInjectionToken, searchParamsOptions } from "@k8slens/routing"; @@ -210,16 +210,10 @@ describe("preferences - closing-preferences", () => { }); }); -const testFrontPageRouteInjectable = getInjectable({ +const testFrontPageRouteInjectable = getFrontEndRouteInjectable({ id: "some-front-page", - - instantiate: () => ({ - path: "/some-front-page", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/some-front-page", + clusterFrame: false, }); const testFrontPageRouteComponentInjectable = getInjectable({ @@ -233,16 +227,10 @@ const testFrontPageRouteComponentInjectable = getInjectable({ injectionToken: routeSpecificComponentInjectionToken, }); -const testRouteInjectable = getInjectable({ +const testRouteInjectable = getFrontEndRouteInjectable({ id: "some-page", - - instantiate: () => ({ - path: "/some-page", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/some-page", + clusterFrame: false, }); const testRouteComponentInjectable = getInjectable({ diff --git a/packages/core/src/features/preferences/common/preferences-route-for-legacy-extensions.injectable.ts b/packages/core/src/features/preferences/common/preferences-route-for-legacy-extensions.injectable.ts index c1f81953a0..94cbda9f27 100644 --- a/packages/core/src/features/preferences/common/preferences-route-for-legacy-extensions.injectable.ts +++ b/packages/core/src/features/preferences/common/preferences-route-for-legacy-extensions.injectable.ts @@ -2,20 +2,12 @@ * 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 { computed } from "mobx"; -import { frontEndRouteInjectionToken } from "../../../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; -const preferencesRouteForLegacyExtensionsInjectable = getInjectable({ +const preferencesRouteForLegacyExtensionsInjectable = getFrontEndRouteInjectable({ id: "preferences-route-for-legacy-extensions", - - instantiate: () => ({ - path: "/preferences/extension/:extensionId/:preferenceTabId?", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/preferences/extension/:extensionId/:preferenceTabId?", + clusterFrame: false, }); export default preferencesRouteForLegacyExtensionsInjectable; diff --git a/packages/core/src/features/preferences/common/preferences-route.injectable.ts b/packages/core/src/features/preferences/common/preferences-route.injectable.ts index 7d7283ed1f..8b4149c608 100644 --- a/packages/core/src/features/preferences/common/preferences-route.injectable.ts +++ b/packages/core/src/features/preferences/common/preferences-route.injectable.ts @@ -2,20 +2,12 @@ * 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 { computed } from "mobx"; -import { frontEndRouteInjectionToken } from "../../../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; -const preferencesRouteInjectable = getInjectable({ +const preferencesRouteInjectable = getFrontEndRouteInjectable({ id: "preferences-route", - - instantiate: () => ({ - path: "/preferences/:preferenceTabId?", - clusterFrame: false, - isEnabled: computed(() => true), - }), - - injectionToken: frontEndRouteInjectionToken, + path: "/preferences/:preferenceTabId?", + clusterFrame: false, }); export default preferencesRouteInjectable; diff --git a/packages/core/src/features/preferences/renderer/preference-items/current-preference-tab-id.injectable.ts b/packages/core/src/features/preferences/renderer/preference-items/current-preference-tab-id.injectable.ts index cdac5905a4..e8b1bbe3a6 100644 --- a/packages/core/src/features/preferences/renderer/preference-items/current-preference-tab-id.injectable.ts +++ b/packages/core/src/features/preferences/renderer/preference-items/current-preference-tab-id.injectable.ts @@ -14,19 +14,13 @@ const currentPreferenceTabIdInjectable = getInjectable({ instantiate: (di) => { const preferencesRoute = di.inject(preferencesRouteInjectable); const preferencesRouteForLegacyExtensions = di.inject(preferencesRouteForLegacyExtensionsInjectable); + const routePathParameters = di.inject(routePathParametersInjectable); - const nonLegacyRoutePathParameters = di.inject( - routePathParametersInjectable, - preferencesRoute, - ); - - const legacyRoutePathParameters = di.inject( - routePathParametersInjectable, - preferencesRouteForLegacyExtensions, - ); + const nonLegacyRoutePathParameters = routePathParameters(preferencesRoute); + const legacyRoutePathParameters = routePathParameters(preferencesRouteForLegacyExtensions); return computed(() => { - const nonLegacyPreferenceTabId = nonLegacyRoutePathParameters.get().preferenceTabId; + const nonLegacyPreferenceTabId = nonLegacyRoutePathParameters.get()?.preferenceTabId; if (nonLegacyPreferenceTabId) { return nonLegacyPreferenceTabId; @@ -34,7 +28,7 @@ const currentPreferenceTabIdInjectable = getInjectable({ const legacyParameters = legacyRoutePathParameters.get(); - if (legacyParameters.extensionId) { + if (legacyParameters?.extensionId) { if (legacyParameters.preferenceTabId) { return `extension-${legacyParameters.extensionId}-${legacyParameters.preferenceTabId}`; } diff --git a/packages/core/src/features/welcome/setting-welcome-page.test.tsx b/packages/core/src/features/welcome/setting-welcome-page.test.tsx index bae9ef7630..b0054209c5 100644 --- a/packages/core/src/features/welcome/setting-welcome-page.test.tsx +++ b/packages/core/src/features/welcome/setting-welcome-page.test.tsx @@ -15,7 +15,7 @@ import type { Route } from "../../common/front-end-routing/front-end-route-injec describe("setting-welcome-page", () => { let builder: ApplicationBuilder; let rendered : RenderResult; - let welcomeRoute: Route; + let welcomeRoute: Route; beforeEach(() => { builder = getApplicationBuilder(); diff --git a/packages/core/src/main/navigate-to-route/navigate-to-route.injectable.ts b/packages/core/src/main/navigate-to-route/navigate-to-route.injectable.ts index a8810414c4..77f35d893d 100644 --- a/packages/core/src/main/navigate-to-route/navigate-to-route.injectable.ts +++ b/packages/core/src/main/navigate-to-route/navigate-to-route.injectable.ts @@ -4,6 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { navigateToUrlInjectionToken } from "../../common/front-end-routing/navigate-to-url-injection-token"; +import type { NavigateToRoute } from "../../common/front-end-routing/navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token"; import { buildURL } from "@k8slens/utilities"; @@ -13,15 +14,15 @@ const navigateToRouteInjectable = getInjectable({ instantiate: (di) => { const navigateToUrl = di.inject(navigateToUrlInjectionToken); - return async (route, options) => { + return ((route, options) => { const url = buildURL(route.path, { params: options?.parameters as object, query: options?.query, fragment: options?.fragment, }); - await navigateToUrl(url, options); - }; + void navigateToUrl(url, options); + }) as NavigateToRoute; }, injectionToken: navigateToRouteInjectionToken, diff --git a/packages/core/src/renderer/components/catalog/catalog-route-parameters.injectable.ts b/packages/core/src/renderer/components/catalog/catalog-route-parameters.injectable.ts deleted file mode 100644 index 0d9bd1fc4e..0000000000 --- a/packages/core/src/renderer/components/catalog/catalog-route-parameters.injectable.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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 { computed } from "mobx"; -import routePathParametersInjectable from "../../routes/route-path-parameters.injectable"; -import catalogRouteInjectable from "../../../common/front-end-routing/routes/catalog/catalog-route.injectable"; - -const catalogRouteParametersInjectable = getInjectable({ - id: "catalog-route-parameters", - - instantiate: (di) => { - const route = di.inject(catalogRouteInjectable); - const pathParameters = di.inject(routePathParametersInjectable, route); - - return { - group: computed(() => pathParameters.get().group), - kind: computed(() => pathParameters.get().kind), - }; - }, -}); - -export default catalogRouteParametersInjectable; diff --git a/packages/core/src/renderer/components/catalog/catalog.tsx b/packages/core/src/renderer/components/catalog/catalog.tsx index 785d17d38b..fd14f22be5 100644 --- a/packages/core/src/renderer/components/catalog/catalog.tsx +++ b/packages/core/src/renderer/components/catalog/catalog.tsx @@ -6,7 +6,7 @@ import styles from "./catalog.module.scss"; import type { IComputedValue } from "mobx"; -import { action, computed, makeObservable, observable, reaction, runInAction, when } from "mobx"; +import { action, computed, observable, reaction, runInAction, when } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import React from "react"; import type { CatalogCategory, CatalogCategoryRegistry, CatalogEntity } from "../../../common/catalog"; @@ -39,7 +39,6 @@ import showErrorNotificationInjectable from "../notifications/show-error-notific import { browseCatalogTab } from "./catalog-browse-tab"; import catalogEntityStoreInjectable from "./catalog-entity-store.injectable"; import catalogPreviousActiveTabStorageInjectable from "./catalog-previous-active-tab-storage/catalog-previous-active-tab-storage.injectable"; -import catalogRouteParametersInjectable from "./catalog-route-parameters.injectable"; import type { CategoryColumns, GetCategoryColumnsParams } from "./columns/get.injectable"; import getCategoryColumnsInjectable from "./columns/get.injectable"; import type { CustomCategoryViewComponents } from "./custom-views"; @@ -51,6 +50,12 @@ import type { ShowEntityDetails } from "./entity-details/show.injectable"; import showEntityDetailsInjectable from "./entity-details/show.injectable"; import type { Hotbar } from "../../../features/hotbar/storage/common/hotbar"; import activeHotbarInjectable from "../../../features/hotbar/storage/common/active.injectable"; +import type { ParametersFromRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; +import type catalogRouteInjectable from "../../../common/front-end-routing/routes/catalog/catalog-route.injectable"; + +export interface CatalogProps { + params: ParametersFromRouteInjectable; +} interface Dependencies { catalogPreviousActiveTabStorage: StorageLayer; @@ -60,10 +65,6 @@ interface Dependencies { emitEvent: EmitAppEvent; showEntityDetails: ShowEntityDetails; onCatalogEntityListClick: OnCatalogEntityListClick; - routeParameters: { - group: IComputedValue; - kind: IComputedValue; - }; navigateToCatalog: NavigateToCatalog; catalogCategoryRegistry: CatalogCategoryRegistry; visitEntityContextMenu: VisitEntityContextMenu; @@ -75,28 +76,19 @@ interface Dependencies { } @observer -class NonInjectedCatalog extends React.Component { +class NonInjectedCatalog extends React.Component { private readonly menuItems = observable.array(); - @observable activeTab: string | undefined = undefined; + readonly activeTab = observable.box(); - constructor(props: Dependencies) { - super(props); - makeObservable(this); - } + readonly routeActiveTab = computed(() => { + const { params: { group, kind }, catalogPreviousActiveTabStorage } = this.props; - @computed - get routeActiveTab(): string { - const { routeParameters: { group, kind }, catalogPreviousActiveTabStorage } = this.props; - - const dereferencedGroup = group.get(); - const dereferencedKind = kind.get(); - - if (dereferencedGroup && dereferencedKind) { - return `${dereferencedGroup}/${dereferencedKind}`; + if (group && kind) { + return `${group}/${kind}`; } return catalogPreviousActiveTabStorage.get() || browseCatalogTab; - } + }); componentDidMount() { const { @@ -109,8 +101,8 @@ class NonInjectedCatalog extends React.Component { disposeOnUnmount(this, [ catalogEntityStore.watch(), - reaction(() => this.routeActiveTab, (routeTab) => { - catalogPreviousActiveTabStorage.set(this.routeActiveTab); + reaction(() => this.routeActiveTab.get(), (routeTab) => { + catalogPreviousActiveTabStorage.set(routeTab); void (async () => { try { @@ -122,7 +114,7 @@ class NonInjectedCatalog extends React.Component { const item = catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab); runInAction(() => { - this.activeTab = routeTab; + this.activeTab.set(routeTab); catalogEntityStore.activeCategory.set(item); }); } catch (error) { @@ -141,14 +133,14 @@ class NonInjectedCatalog extends React.Component { const currentCategory = catalogEntityStore.activeCategory.get(); const someCategory = categories[0]; - if (this.routeActiveTab === browseCatalogTab || !someCategory) { + if (this.routeActiveTab.get() === browseCatalogTab || !someCategory) { return; } const currentCategoryShouldBeShown = Boolean(categories.find(item => item.getId() === someCategory.getId())); if (!currentCategory || !currentCategoryShouldBeShown) { - this.activeTab = someCategory.getId(); + this.activeTab.set(someCategory.getId()); this.props.catalogEntityStore.activeCategory.set(someCategory); } }), @@ -296,7 +288,7 @@ class NonInjectedCatalog extends React.Component { )} @@ -318,14 +310,13 @@ class NonInjectedCatalog extends React.Component { } } -export const Catalog = withInjectables(NonInjectedCatalog, { +export const Catalog = withInjectables(NonInjectedCatalog, { getProps: (di, props) => ({ ...props, catalogEntityStore: di.inject(catalogEntityStoreInjectable), catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable), getCategoryColumns: di.inject(getCategoryColumnsInjectable), customCategoryViews: di.inject(customCategoryViewsInjectable), - routeParameters: di.inject(catalogRouteParametersInjectable), navigateToCatalog: di.inject(navigateToCatalogInjectable), emitEvent: di.inject(emitAppEventInjectable), activeHotbar: di.inject(activeHotbarInjectable), diff --git a/packages/core/src/renderer/components/cluster-manager/cluster-view-route-parameters.injectable.ts b/packages/core/src/renderer/components/cluster-manager/cluster-view-route-parameters.injectable.ts deleted file mode 100644 index 6343286dff..0000000000 --- a/packages/core/src/renderer/components/cluster-manager/cluster-view-route-parameters.injectable.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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 { computed } from "mobx"; -import routePathParametersInjectable from "../../routes/route-path-parameters.injectable"; -import clusterViewRouteInjectable from "../../../common/front-end-routing/routes/cluster-view/cluster-view-route.injectable"; - -const clusterViewRouteParametersInjectable = getInjectable({ - id: "cluster-view-route-parameters", - - instantiate: (di) => { - const route = di.inject(clusterViewRouteInjectable); - const pathParameters = di.inject(routePathParametersInjectable, route); - - return { - clusterId: computed(() => pathParameters.get().clusterId), - }; - }, -}); - -export default clusterViewRouteParametersInjectable; diff --git a/packages/core/src/renderer/components/cluster-manager/cluster-view.tsx b/packages/core/src/renderer/components/cluster-manager/cluster-view.tsx index d1adbfb547..f3a060582c 100644 --- a/packages/core/src/renderer/components/cluster-manager/cluster-view.tsx +++ b/packages/core/src/renderer/components/cluster-manager/cluster-view.tsx @@ -5,16 +5,13 @@ import "./cluster-view.scss"; import React from "react"; -import type { IComputedValue } from "mobx"; -import { computed, makeObservable, reaction } from "mobx"; +import { computed, reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import { ClusterStatus } from "./cluster-status"; import type { ClusterFrameHandler } from "./cluster-frame-handler"; -import type { Cluster } from "../../../common/cluster/cluster"; import { withInjectables } from "@ogre-tools/injectable-react"; import type { NavigateToCatalog } from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable"; import navigateToCatalogInjectable from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable"; -import clusterViewRouteParametersInjectable from "./cluster-view-route-parameters.injectable"; import clusterFrameHandlerInjectable from "./cluster-frame-handler.injectable"; import type { CatalogEntityRegistry } from "../../api/catalog/entity/registry"; import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable"; @@ -22,10 +19,14 @@ import type { RequestClusterActivation } from "../../../features/cluster/activat import requestClusterActivationInjectable from "../../../features/cluster/activation/renderer/request-activation.injectable"; import type { GetClusterById } from "../../../features/cluster/storage/common/get-by-id.injectable"; import getClusterByIdInjectable from "../../../features/cluster/storage/common/get-by-id.injectable"; -import type { StrictReactNode } from "@k8slens/utilities"; +import type { ParametersFromRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; +import type clusterViewRouteInjectable from "../../../common/front-end-routing/routes/cluster-view/cluster-view-route.injectable"; + +export interface ClusterViewProps { + params: ParametersFromRouteInjectable; +} interface Dependencies { - clusterId: IComputedValue; clusterFrames: ClusterFrameHandler; navigateToCatalog: NavigateToCatalog; entityRegistry: CatalogEntityRegistry; @@ -34,34 +35,27 @@ interface Dependencies { } @observer -class NonInjectedClusterView extends React.Component { - constructor(props: Dependencies) { - super(props); - makeObservable(this); - } - +class NonInjectedClusterView extends React.Component { get clusterId() { - return this.props.clusterId.get(); + return this.props.params.clusterId; } - @computed get cluster(): Cluster | undefined { - return this.props.getClusterById(this.clusterId); - } + readonly cluster = computed(() => this.props.getClusterById(this.clusterId)); private readonly isViewLoaded = computed(() => this.props.clusterFrames.hasLoadedView(this.clusterId), { keepAlive: true, requiresReaction: true, }); - @computed get isReady(): boolean { - const { cluster } = this; + readonly isReady = computed(() => { + const cluster = this.cluster.get(); if (!cluster) { return false; } return cluster.ready.get() && cluster.available.get() && this.isViewLoaded.get(); - } + }); componentDidMount() { this.bindEvents(); @@ -94,8 +88,9 @@ class NonInjectedClusterView extends React.Component { ]); } - renderStatus(): StrictReactNode { - const { cluster, isReady } = this; + renderStatus() { + const cluster = this.cluster.get(); + const isReady = this.isReady.get(); if (cluster && !isReady) { return ; @@ -113,9 +108,9 @@ class NonInjectedClusterView extends React.Component { } } -export const ClusterView = withInjectables(NonInjectedClusterView, { - getProps: (di) => ({ - ...di.inject(clusterViewRouteParametersInjectable), +export const ClusterView = withInjectables(NonInjectedClusterView, { + getProps: (di, props) => ({ + ...props, navigateToCatalog: di.inject(navigateToCatalogInjectable), clusterFrames: di.inject(clusterFrameHandlerInjectable), entityRegistry: di.inject(catalogEntityRegistryInjectable), diff --git a/packages/core/src/renderer/components/config-leases/leases.tsx b/packages/core/src/renderer/components/config-leases/leases.tsx index 81397aab26..b5045cd20f 100644 --- a/packages/core/src/renderer/components/config-leases/leases.tsx +++ b/packages/core/src/renderer/components/config-leases/leases.tsx @@ -7,9 +7,7 @@ import "./leases.scss"; import * as React from "react"; import { observer } from "mobx-react"; -import type { Lease } from "@k8slens/kube-object"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; -import type { KubeObjectDetailsProps } from "../kube-object-details"; import { KubeObjectListLayout } from "../kube-object-list-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { KubeObjectAge } from "../kube-object/age"; @@ -25,14 +23,12 @@ enum columnId { age = "age", } -export type LeaseProps = KubeObjectDetailsProps; - interface Dependencies { leaseStore: LeaseStore; } @observer -class NonInjectedLease extends React.Component { +class NonInjectedLease extends React.Component { render() { const { leaseStore } = this.props; @@ -76,7 +72,7 @@ class NonInjectedLease extends React.Component { } } -export const Leases = withInjectables(NonInjectedLease, { +export const Leases = withInjectables(NonInjectedLease, { getProps: (di, props) => ({ ...props, leaseStore: di.inject(leaseStoreInjectable), diff --git a/packages/core/src/renderer/components/config-pod-disruption-budgets/pod-disruption-budgets.tsx b/packages/core/src/renderer/components/config-pod-disruption-budgets/pod-disruption-budgets.tsx index c281f45f67..f579cd0701 100644 --- a/packages/core/src/renderer/components/config-pod-disruption-budgets/pod-disruption-budgets.tsx +++ b/packages/core/src/renderer/components/config-pod-disruption-budgets/pod-disruption-budgets.tsx @@ -7,9 +7,7 @@ import "./pod-disruption-budgets.scss"; import * as React from "react"; import { observer } from "mobx-react"; -import type { PodDisruptionBudget } from "@k8slens/kube-object"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; -import type { KubeObjectDetailsProps } from "../kube-object-details"; import { KubeObjectListLayout } from "../kube-object-list-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { KubeObjectAge } from "../kube-object/age"; @@ -28,14 +26,12 @@ enum columnId { age = "age", } -export type PodDisruptionBudgetsProps = KubeObjectDetailsProps; - interface Dependencies { podDisruptionBudgetStore: PodDisruptionBudgetStore; } @observer -class NonInjectedPodDisruptionBudgets extends React.Component { +class NonInjectedPodDisruptionBudgets extends React.Component { render() { return ( @@ -86,7 +82,7 @@ class NonInjectedPodDisruptionBudgets extends React.Component(NonInjectedPodDisruptionBudgets, { +export const PodDisruptionBudgets = withInjectables(NonInjectedPodDisruptionBudgets, { getProps: (di, props) => ({ ...props, podDisruptionBudgetStore: di.inject(podDisruptionBudgetStoreInjectable), diff --git a/packages/core/src/renderer/components/config-priority-classes/priority-classes.tsx b/packages/core/src/renderer/components/config-priority-classes/priority-classes.tsx index fbef6fa631..781f9f0aa6 100644 --- a/packages/core/src/renderer/components/config-priority-classes/priority-classes.tsx +++ b/packages/core/src/renderer/components/config-priority-classes/priority-classes.tsx @@ -7,16 +7,13 @@ import "./priority-classes.scss"; import * as React from "react"; import { observer } from "mobx-react"; -import type { PriorityClass } from "@k8slens/kube-object"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; -import type { KubeObjectDetailsProps } from "../kube-object-details"; import { KubeObjectListLayout } from "../kube-object-list-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { KubeObjectAge } from "../kube-object/age"; import { withInjectables } from "@ogre-tools/injectable-react"; import priorityClassStoreInjectable from "./store.injectable"; import type { PriorityClassStore } from "./store"; -import autoBindReact from "auto-bind/react"; enum columnId { name = "name", @@ -25,19 +22,12 @@ enum columnId { age = "age", } -export type PriorityClassesProps = KubeObjectDetailsProps; - interface Dependencies { priorityClassStore: PriorityClassStore; } @observer -class NonInjectedPriorityClasses extends React.Component { - constructor(props: PriorityClassesProps & Dependencies) { - super(props); - autoBindReact(this); - } - +class NonInjectedPriorityClasses extends React.Component { render() { const { priorityClassStore } = this.props; @@ -78,7 +68,7 @@ class NonInjectedPriorityClasses extends React.Component(NonInjectedPriorityClasses, { +export const PriorityClasses = withInjectables(NonInjectedPriorityClasses, { getProps: (di, props) => ({ ...props, priorityClassStore: di.inject(priorityClassStoreInjectable), diff --git a/packages/core/src/renderer/components/config-runtime-classes/runtime-classes.tsx b/packages/core/src/renderer/components/config-runtime-classes/runtime-classes.tsx index ba3ca9b984..9919d09e8c 100644 --- a/packages/core/src/renderer/components/config-runtime-classes/runtime-classes.tsx +++ b/packages/core/src/renderer/components/config-runtime-classes/runtime-classes.tsx @@ -7,16 +7,13 @@ import "./runtime-classes.scss"; import * as React from "react"; import { observer } from "mobx-react"; -import type { RuntimeClass } from "@k8slens/kube-object"; import { KubeObjectStatusIcon } from "../kube-object-status-icon"; -import type { KubeObjectDetailsProps } from "../kube-object-details"; import { KubeObjectListLayout } from "../kube-object-list-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { KubeObjectAge } from "../kube-object/age"; import { withInjectables } from "@ogre-tools/injectable-react"; import runtimeClassStoreInjectable from "./store.injectable"; import type { RuntimeClassStore } from "./store"; -import autoBindReact from "auto-bind/react"; enum columnId { name = "name", @@ -24,19 +21,12 @@ enum columnId { age = "age", } -export type RuntimeClassesProps = KubeObjectDetailsProps; - interface Dependencies { runtimeClassStore: RuntimeClassStore; } @observer -class NonInjectedRuntimeClasses extends React.Component { - constructor(props: RuntimeClassesProps & Dependencies) { - super(props); - autoBindReact(this); - } - +class NonInjectedRuntimeClasses extends React.Component { render() { const { runtimeClassStore } = this.props; @@ -74,7 +64,7 @@ class NonInjectedRuntimeClasses extends React.Component(NonInjectedRuntimeClasses, { +export const RuntimeClasses = withInjectables(NonInjectedRuntimeClasses, { getProps: (di, props) => ({ ...props, runtimeClassStore: di.inject(runtimeClassStoreInjectable), diff --git a/packages/core/src/renderer/components/custom-resources/route-parameters.injectable.ts b/packages/core/src/renderer/components/custom-resources/route-parameters.injectable.ts deleted file mode 100644 index 69368218fd..0000000000 --- a/packages/core/src/renderer/components/custom-resources/route-parameters.injectable.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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 { computed } from "mobx"; -import routePathParametersInjectable from "../../routes/route-path-parameters.injectable"; -import customResourcesRouteInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable"; - -const customResourcesRouteParametersInjectable = getInjectable({ - id: "custom-resources-route-parameters", - - instantiate: (di) => { - const route = di.inject(customResourcesRouteInjectable); - const pathParameters = di.inject(routePathParametersInjectable, route); - - return { - group: computed(() => pathParameters.get().group), - name: computed(() => pathParameters.get().name), - }; - }, -}); - -export default customResourcesRouteParametersInjectable; diff --git a/packages/core/src/renderer/components/custom-resources/view.tsx b/packages/core/src/renderer/components/custom-resources/view.tsx index ffb83f70ee..5ed326cd9b 100644 --- a/packages/core/src/renderer/components/custom-resources/view.tsx +++ b/packages/core/src/renderer/components/custom-resources/view.tsx @@ -8,19 +8,19 @@ import "./view.scss"; import React from "react"; import { observer } from "mobx-react"; import { KubeObjectListLayout } from "../kube-object-list-layout"; -import type { IComputedValue } from "mobx"; -import { computed, makeObservable } from "mobx"; +import { computed } from "mobx"; import type { ApiManager } from "../../../common/k8s-api/api-manager"; import { formatJSONValue, safeJSONPathValue } from "@k8slens/utilities"; import { TabLayout } from "../layout/tab-layout-2"; import { withInjectables } from "@ogre-tools/injectable-react"; -import customResourcesRouteParametersInjectable from "./route-parameters.injectable"; import { KubeObjectAge } from "../kube-object/age"; import type { CustomResourceDefinitionStore } from "../custom-resource-definitions/store"; import apiManagerInjectable from "../../../common/k8s-api/api-manager/manager.injectable"; import customResourceDefinitionStoreInjectable from "../custom-resource-definitions/store.injectable"; import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; import type { TableCellProps } from "@k8slens/list-layout"; +import type { ParametersFromRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; +import type customResourcesRouteInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/custom-resources-route.injectable"; enum columnId { name = "name", @@ -29,29 +29,29 @@ enum columnId { } interface Dependencies { - group: IComputedValue; - name: IComputedValue; apiManager: ApiManager; customResourceDefinitionStore: CustomResourceDefinitionStore; } +export interface CustomResourcesProps { + params: ParametersFromRouteInjectable; +} + @observer -class NonInjectedCustomResources extends React.Component { - constructor(props: Dependencies) { - super(props); - makeObservable(this); - } +class NonInjectedCustomResources extends React.Component { + readonly crd = computed(() => { + if (this.props.params.group && this.props.params.name) { + return this.props.customResourceDefinitionStore.getByGroup(this.props.params.group, this.props.params.name); + } - @computed get crd() { - return this.props.customResourceDefinitionStore.getByGroup(this.props.group.get(), this.props.name.get()); - } + return undefined; + }); - @computed get store() { - return this.props.apiManager.getStore(this.crd?.getResourceApiBase()); - } + readonly store = computed(() => this.props.apiManager.getStore(this.crd.get()?.getResourceApiBase())); render() { - const { crd, store } = this; + const crd = this.crd.get(); + const store = this.store.get(); if (!crd || !store) { return null; @@ -132,9 +132,9 @@ class NonInjectedCustomResources extends React.Component { } } -export const CustomResources = withInjectables(NonInjectedCustomResources, { - getProps: (di) => ({ - ...di.inject(customResourcesRouteParametersInjectable), +export const CustomResources = withInjectables(NonInjectedCustomResources, { + getProps: (di, props) => ({ + ...props, apiManager: di.inject(apiManagerInjectable), customResourceDefinitionStore: di.inject(customResourceDefinitionStoreInjectable), }), diff --git a/packages/core/src/renderer/components/entity-settings/current-entity.injectable.ts b/packages/core/src/renderer/components/entity-settings/current-entity.injectable.ts index fded6d096a..b07450b2d1 100644 --- a/packages/core/src/renderer/components/entity-settings/current-entity.injectable.ts +++ b/packages/core/src/renderer/components/entity-settings/current-entity.injectable.ts @@ -4,16 +4,26 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; +import entitySettingsRouteInjectable from "../../../common/front-end-routing/routes/entity-settings/entity-settings-route.injectable"; import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable"; -import entitySettingsRouteParametersInjectable from "./route-parameters.injectable"; +import routePathParametersInjectable from "../../routes/route-path-parameters.injectable"; const currentCatalogEntityForSettingsInjectable = getInjectable({ id: "current-catalog-entity-for-settings", instantiate: (di) => { - const { entityId } = di.inject(entitySettingsRouteParametersInjectable); + const route = di.inject(entitySettingsRouteInjectable); + const pathParameters = di.inject(routePathParametersInjectable)(route); const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); - return computed(() => catalogEntityRegistry.getById(entityId.get())); + return computed(() => { + const params = pathParameters.get(); + + if (!params) { + return undefined; + } + + return catalogEntityRegistry.getById(params.entityId); + }); }, }); diff --git a/packages/core/src/renderer/components/entity-settings/route-parameters.injectable.ts b/packages/core/src/renderer/components/entity-settings/route-parameters.injectable.ts deleted file mode 100644 index 8a1d5600b8..0000000000 --- a/packages/core/src/renderer/components/entity-settings/route-parameters.injectable.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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 { computed } from "mobx"; -import routePathParametersInjectable from "../../routes/route-path-parameters.injectable"; -import entitySettingsRouteInjectable from "../../../common/front-end-routing/routes/entity-settings/entity-settings-route.injectable"; - -const entitySettingsRouteParametersInjectable = getInjectable({ - id: "entity-settings-route-parameters", - - instantiate: (di) => { - const route = di.inject(entitySettingsRouteInjectable); - const pathParameters = di.inject(routePathParametersInjectable, route); - - return { - entityId: computed(() => pathParameters.get().entityId), - }; - }, -}); - -export default entitySettingsRouteParametersInjectable; diff --git a/packages/core/src/renderer/components/events/events.tsx b/packages/core/src/renderer/components/events/events.tsx index 556078e9ec..9fffc7a76e 100644 --- a/packages/core/src/renderer/components/events/events.tsx +++ b/packages/core/src/renderer/components/events/events.tsx @@ -32,6 +32,8 @@ import type { GetDetailsUrl } from "../kube-detail-params/get-details-url.inject import getDetailsUrlInjectable from "../kube-detail-params/get-details-url.injectable"; import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; import type { KubeEventApi } from "@k8slens/kube-api"; +import type { ParametersFromRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; +import type eventsRouteInjectable from "../../../common/front-end-routing/routes/cluster/events/events-route.injectable"; enum columnId { message = "message", @@ -48,6 +50,7 @@ export interface EventsProps extends Partial; } const defaultProps: Partial = { diff --git a/packages/core/src/renderer/components/helm-charts/helm-charts-route-parameters.injectable.ts b/packages/core/src/renderer/components/helm-charts/helm-charts-route-parameters.injectable.ts deleted file mode 100644 index cc800ff7f3..0000000000 --- a/packages/core/src/renderer/components/helm-charts/helm-charts-route-parameters.injectable.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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 { computed } from "mobx"; -import routePathParametersInjectable from "../../routes/route-path-parameters.injectable"; -import helmChartsRouteInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/helm-charts-route.injectable"; - -const helmChartsRouteParametersInjectable = getInjectable({ - id: "helm-charts-route-parameters", - - instantiate: (di) => { - const route = di.inject(helmChartsRouteInjectable); - const pathParameters = di.inject(routePathParametersInjectable, route); - - return { - chartName: computed(() => pathParameters.get().chartName), - repo: computed(() => pathParameters.get().repo), - }; - }, -}); - -export default helmChartsRouteParametersInjectable; diff --git a/packages/core/src/renderer/components/helm-charts/helm-charts.tsx b/packages/core/src/renderer/components/helm-charts/helm-charts.tsx index dff8025de5..1a0a707079 100644 --- a/packages/core/src/renderer/components/helm-charts/helm-charts.tsx +++ b/packages/core/src/renderer/components/helm-charts/helm-charts.tsx @@ -14,13 +14,14 @@ import type { IComputedValue } from "mobx"; import type { IAsyncComputed } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; -import helmChartsRouteParametersInjectable from "./helm-charts-route-parameters.injectable"; import type { NavigateToHelmCharts } from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable"; import navigateToHelmChartsInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable"; import { HelmChartIcon } from "./icon"; import helmChartsInjectable from "./helm-charts/helm-charts.injectable"; import selectedHelmChartInjectable from "./helm-charts/selected-helm-chart.injectable"; import { noop } from "lodash"; +import type { ParametersFromRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; +import type helmChartsRouteInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/helm-charts-route.injectable"; enum columnId { name = "name", @@ -31,17 +32,17 @@ enum columnId { } interface Dependencies { - routeParameters: { - chartName: IComputedValue; - repo: IComputedValue; - }; navigateToHelmCharts: NavigateToHelmCharts; charts: IAsyncComputed; selectedChart: IComputedValue; } +export interface HelmChartsProps { + params: ParametersFromRouteInjectable; +} + @observer -class NonInjectedHelmCharts extends Component { +class NonInjectedHelmCharts extends Component { onDetails = (chart: HelmChart) => { if (chart === this.props.selectedChart.get()) { this.hideDetails(); @@ -144,9 +145,9 @@ class NonInjectedHelmCharts extends Component { } } -export const HelmCharts = withInjectables(NonInjectedHelmCharts, { - getProps: (di) => ({ - routeParameters: di.inject(helmChartsRouteParametersInjectable), +export const HelmCharts = withInjectables(NonInjectedHelmCharts, { + getProps: (di, props) => ({ + ...props, navigateToHelmCharts: di.inject(navigateToHelmChartsInjectable), charts: di.inject(helmChartsInjectable), selectedChart: di.inject(selectedHelmChartInjectable), diff --git a/packages/core/src/renderer/components/helm-charts/helm-charts/selected-helm-chart.injectable.ts b/packages/core/src/renderer/components/helm-charts/helm-charts/selected-helm-chart.injectable.ts index 47777fb783..2ac8d5ffab 100644 --- a/packages/core/src/renderer/components/helm-charts/helm-charts/selected-helm-chart.injectable.ts +++ b/packages/core/src/renderer/components/helm-charts/helm-charts/selected-helm-chart.injectable.ts @@ -4,31 +4,31 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import helmChartsRouteParametersInjectable from "../helm-charts-route-parameters.injectable"; +import helmChartsRouteInjectable from "../../../../common/front-end-routing/routes/cluster/helm/charts/helm-charts-route.injectable"; +import routePathParametersInjectable from "../../../routes/route-path-parameters.injectable"; import helmChartsInjectable from "./helm-charts.injectable"; const selectedHelmChartInjectable = getInjectable({ id: "selected-helm-chart", instantiate: (di) => { - const { chartName, repo } = di.inject(helmChartsRouteParametersInjectable); + const route = di.inject(helmChartsRouteInjectable); + const pathParameters = di.inject(routePathParametersInjectable)(route); const helmCharts = di.inject(helmChartsInjectable); return computed(() => { - const dereferencedChartName = chartName.get(); - const deferencedRepository = repo.get(); + const { chartName, repo } = pathParameters.get() ?? {}; - if (!dereferencedChartName || !deferencedRepository) { + if (!chartName || !repo) { return undefined; } return helmCharts.value .get() - .find( - (chart) => - chart.getName() === dereferencedChartName && - chart.getRepository() === deferencedRepository, - ); + .find((chart) => ( + chart.getName() === chartName + && chart.getRepository() === repo + )); }); }, }); diff --git a/packages/core/src/renderer/components/helm-releases/helm-releases-route-parameters.injectable.ts b/packages/core/src/renderer/components/helm-releases/helm-releases-route-parameters.injectable.ts deleted file mode 100644 index e8f637621f..0000000000 --- a/packages/core/src/renderer/components/helm-releases/helm-releases-route-parameters.injectable.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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 { computed } from "mobx"; -import helmReleasesRouteInjectable from "../../../common/front-end-routing/routes/cluster/helm/releases/helm-releases-route.injectable"; -import routePathParametersInjectable from "../../routes/route-path-parameters.injectable"; - -const helmReleasesRouteParametersInjectable = getInjectable({ - id: "helm-releases-route-parameters", - - instantiate: (di) => { - const route = di.inject(helmReleasesRouteInjectable); - const pathParameters = di.inject(routePathParametersInjectable, route); - - return { - namespace: computed(() => pathParameters.get().namespace), - name: computed(() => pathParameters.get().name), - }; - }, -}); - -export default helmReleasesRouteParametersInjectable; diff --git a/packages/core/src/renderer/components/helm-releases/release-details/target-helm-release.injectable.ts b/packages/core/src/renderer/components/helm-releases/release-details/target-helm-release.injectable.ts index 809ed1ab5a..06dae36a26 100644 --- a/packages/core/src/renderer/components/helm-releases/release-details/target-helm-release.injectable.ts +++ b/packages/core/src/renderer/components/helm-releases/release-details/target-helm-release.injectable.ts @@ -4,21 +4,32 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; -import helmReleasesRouteParametersInjectable from "../helm-releases-route-parameters.injectable"; +import helmReleasesRouteInjectable from "../../../../common/front-end-routing/routes/cluster/helm/releases/helm-releases-route.injectable"; +import routePathParametersInjectable from "../../../routes/route-path-parameters.injectable"; -export interface TargetHelmRelease { name: string; namespace: string } +export interface TargetHelmRelease { + name: string; + namespace: string; +} const targetHelmReleaseInjectable = getInjectable({ id: "target-helm-release", instantiate: (di) => { - const routeParameters = di.inject(helmReleasesRouteParametersInjectable); + const route = di.inject(helmReleasesRouteInjectable); + const pathParameters = di.inject(routePathParametersInjectable)(route); return computed((): TargetHelmRelease | undefined => { - const name = routeParameters.name.get(); - const namespace = routeParameters.namespace.get(); + const { name, namespace } = pathParameters.get() ?? {}; - return name && namespace ? { name, namespace } : undefined; + if (name && namespace) { + return { + name, + namespace, + }; + } + + return undefined; }); }, }); diff --git a/packages/core/src/renderer/components/helm-releases/releases.tsx b/packages/core/src/renderer/components/helm-releases/releases.tsx index 514e7593e7..d1e71a4091 100644 --- a/packages/core/src/renderer/components/helm-releases/releases.tsx +++ b/packages/core/src/renderer/components/helm-releases/releases.tsx @@ -6,7 +6,7 @@ import "../item-object-list/item-list-layout.scss"; import "./releases.scss"; -import React, { Component } from "react"; +import React from "react"; import type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api"; import { withInjectables } from "@ogre-tools/injectable-react"; import type { ItemListStore } from "../item-object-list"; @@ -20,10 +20,12 @@ import type { RemovableHelmRelease } from "./removable-releases"; import type { IComputedValue } from "mobx"; import releasesInjectable from "./releases.injectable"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; -import helmReleasesRouteParametersInjectable from "./helm-releases-route-parameters.injectable"; import type { NavigateToHelmReleases } from "../../../common/front-end-routing/routes/cluster/helm/releases/navigate-to-helm-releases.injectable"; import navigateToHelmReleasesInjectable from "../../../common/front-end-routing/routes/cluster/helm/releases/navigate-to-helm-releases.injectable"; import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; +import type { ParametersFromRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; +import type helmReleasesRouteInjectable from "../../../common/front-end-routing/routes/cluster/helm/releases/helm-releases-route.injectable"; +import { observer } from "mobx-react"; enum columnId { name = "name", @@ -39,11 +41,15 @@ enum columnId { interface Dependencies { releases: IComputedValue; releasesArePending: IComputedValue; - namespace: IComputedValue; navigateToHelmReleases: NavigateToHelmReleases; } -class NonInjectedHelmReleases extends Component { +export interface HelmReleasesProps { + params: ParametersFromRouteInjectable; +} + +@observer +class NonInjectedHelmReleases extends React.Component { onDetails = (item: HelmRelease) => { this.showDetails(item); }; @@ -206,11 +212,11 @@ class NonInjectedHelmReleases extends Component { } } -export const HelmReleases = withInjectables(NonInjectedHelmReleases, { - getProps: (di) => ({ +export const HelmReleases = withInjectables(NonInjectedHelmReleases, { + getProps: (di, props) => ({ + ...props, releases: di.inject(removableReleasesInjectable), releasesArePending: di.inject(releasesInjectable).pending, navigateToHelmReleases: di.inject(navigateToHelmReleasesInjectable), - ...di.inject(helmReleasesRouteParametersInjectable), }), }); diff --git a/packages/core/src/renderer/components/network-port-forwards/port-forwards-route-parameters.injectable.ts b/packages/core/src/renderer/components/network-port-forwards/port-forwards-route-parameters.injectable.ts deleted file mode 100644 index 65da9fca11..0000000000 --- a/packages/core/src/renderer/components/network-port-forwards/port-forwards-route-parameters.injectable.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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 { computed } from "mobx"; -import routePathParametersInjectable from "../../routes/route-path-parameters.injectable"; -import portForwardsRouteInjectable from "../../../common/front-end-routing/routes/cluster/network/port-forwards/port-forwards-route.injectable"; - -const portForwardsRouteParametersInjectable = getInjectable({ - id: "port-forwards-route-parameters", - - instantiate: (di) => { - const route = di.inject(portForwardsRouteInjectable); - const pathParameters = di.inject(routePathParametersInjectable, route); - - return { - forwardPort: computed(() => pathParameters.get().forwardPort), - }; - }, -}); - -export default portForwardsRouteParametersInjectable; diff --git a/packages/core/src/renderer/components/network-port-forwards/port-forwards.tsx b/packages/core/src/renderer/components/network-port-forwards/port-forwards.tsx index df1aaaa79f..a37a6614a7 100644 --- a/packages/core/src/renderer/components/network-port-forwards/port-forwards.tsx +++ b/packages/core/src/renderer/components/network-port-forwards/port-forwards.tsx @@ -14,12 +14,12 @@ import { PortForwardDetails } from "./port-forward-details"; import { withInjectables } from "@ogre-tools/injectable-react"; import portForwardStoreInjectable from "../../port-forward/port-forward-store/port-forward-store.injectable"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; -import type { IComputedValue } from "mobx"; -import { computed, makeObservable } from "mobx"; -import portForwardsRouteParametersInjectable from "./port-forwards-route-parameters.injectable"; +import { computed } from "mobx"; import type { NavigateToPortForwards } from "../../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable"; import navigateToPortForwardsInjectable from "../../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable"; import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; +import type { ParametersFromRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token"; +import type portForwardsRouteInjectable from "../../../common/front-end-routing/routes/cluster/network/port-forwards/port-forwards-route.injectable"; enum columnId { name = "name", @@ -33,38 +33,33 @@ enum columnId { interface Dependencies { portForwardStore: PortForwardStore; - forwardPort: IComputedValue; navigateToPortForwards: NavigateToPortForwards; } +export interface PortForwardsProps { + params: ParametersFromRouteInjectable; +} + @observer -class NonInjectedPortForwards extends React.Component { - constructor(props: Dependencies) { - super(props); - - makeObservable(this); - } - +class NonInjectedPortForwards extends React.Component { componentDidMount() { - disposeOnUnmount(this, [ this.props.portForwardStore.watch(), ]); } - @computed - get selectedPortForward() { - const forwardPort = this.props.forwardPort.get(); + readonly selectedPortForward = computed(() => { + const forwardPort = this.props.params.forwardPort; if (!forwardPort) { return undefined; } return this.props.portForwardStore.getById(forwardPort); - } + }); onDetails = (item: PortForwardItem) => { - if (item === this.selectedPortForward) { + if (item === this.selectedPortForward.get()) { this.hideDetails(); } else { this.showDetails(item); @@ -97,6 +92,8 @@ class NonInjectedPortForwards extends React.Component { render() { + const selectedPortForward = this.selectedPortForward.get(); + return ( @@ -149,12 +146,12 @@ class NonInjectedPortForwards extends React.Component { customizeRemoveDialog={selectedItems => ({ message: this.renderRemoveDialogMessage(selectedItems), })} - detailsItem={this.selectedPortForward} + detailsItem={selectedPortForward} onDetails={this.onDetails} /> - {this.selectedPortForward && ( + {selectedPortForward && ( )} @@ -163,10 +160,10 @@ class NonInjectedPortForwards extends React.Component { } } -export const PortForwards = withInjectables(NonInjectedPortForwards, { - getProps: (di) => ({ +export const PortForwards = withInjectables(NonInjectedPortForwards, { + getProps: (di, props) => ({ + ...props, portForwardStore: di.inject(portForwardStoreInjectable), - ...di.inject(portForwardsRouteParametersInjectable), navigateToPortForwards: di.inject(navigateToPortForwardsInjectable), }), }); diff --git a/packages/core/src/renderer/components/test-utils/get-application-builder.tsx b/packages/core/src/renderer/components/test-utils/get-application-builder.tsx index bf12dc1247..d5cdf0b57c 100644 --- a/packages/core/src/renderer/components/test-utils/get-application-builder.tsx +++ b/packages/core/src/renderer/components/test-utils/get-application-builder.tsx @@ -32,8 +32,7 @@ import assert from "assert"; import { openMenu } from "react-select-event"; import userEvent from "@testing-library/user-event"; import lensProxyPortInjectable from "../../../main/lens-proxy/lens-proxy-port.injectable"; -import type { Route } from "../../../common/front-end-routing/front-end-route-injection-token"; -import type { NavigateToRouteOptions } from "../../../common/front-end-routing/navigate-to-route-injection-token"; +import type { NavigateToRoute } from "../../../common/front-end-routing/navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token"; import type { LensMainExtension } from "../../../extensions/lens-main-extension"; import type { LensExtension } from "../../../extensions/lens-extension"; @@ -153,7 +152,7 @@ export interface ApplicationBuilder { preferences: { close: () => void; navigate: () => void; - navigateTo: (route: Route, params: NavigateToRouteOptions>) => void; + navigateTo: NavigateToRoute; navigation: { click: (id: string) => void; }; @@ -503,13 +502,12 @@ export const getApplicationBuilder = () => { navigateToPreferences(); }, - navigateTo: (route, params) => { + navigateTo: ((...args) => { const windowDi = builder.applicationWindow.only.di; - const navigateToRoute = windowDi.inject(navigateToRouteInjectionToken); - navigateToRoute(route, params); - }, + navigateToRoute(...args); + }) as NavigateToRoute, navigation: { click: (pathId: string) => { @@ -562,6 +560,7 @@ export const getApplicationBuilder = () => { windowDi.override(activeKubernetesClusterInjectable, () => computed(() => catalogEntityFromCluster(cluster))); // TODO: Figure out a way to remove this stub. + // eslint-disable-next-line @typescript-eslint/no-unsafe-return windowDi.override(namespaceStoreInjectable, () => ({ isLoaded: true, get contextNamespaces() { @@ -580,7 +579,8 @@ export const getApplicationBuilder = () => { isSelectedAll: () => false, getTotalCount: () => namespaceItems.length, isSelected: () => false, - } as Partial as NamespaceStore)); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as Partial as any)); }); await builder.beforeApplicationStart(({ mainDi }) => { diff --git a/packages/core/src/renderer/frames/cluster-frame/cluster-frame-layout-child-component.injectable.tsx b/packages/core/src/renderer/frames/cluster-frame/cluster-frame-layout-child-component.injectable.tsx index ec40ef5f35..3b3e734c17 100644 --- a/packages/core/src/renderer/frames/cluster-frame/cluster-frame-layout-child-component.injectable.tsx +++ b/packages/core/src/renderer/frames/cluster-frame/cluster-frame-layout-child-component.injectable.tsx @@ -14,27 +14,29 @@ import { computed } from "mobx"; import currentRouteComponentInjectable from "../../routes/current-route-component.injectable"; import { Redirect } from "react-router"; import startUrlInjectable from "./start-url.injectable"; -import currentPathInjectable from "../../routes/current-path.injectable"; import { observer } from "mobx-react"; import { withInjectables } from "@ogre-tools/injectable-react"; +import type { InferParamFromPath } from "../../../common/front-end-routing/front-end-route-injection-token"; +import type { MatchedRoute } from "../../routes/matching-route.injectable"; +import matchingRouteInjectable from "../../routes/matching-route.injectable"; interface Dependencies { - currentRouteComponent: IComputedValue | undefined>; + currentRouteComponent: IComputedValue }> | undefined>; startUrl: IComputedValue; - currentPath: IComputedValue; + matchedRoute: IComputedValue; } const NonInjectedClusterFrameLayout = observer((props: Dependencies) => { const Component = props.currentRouteComponent.get(); const starting = props.startUrl.get(); - const current = props.currentPath.get(); + const matchedRoute = props.matchedRoute.get(); return ( } footer={}> - {Component ? ( - + {(Component && matchedRoute) ? ( + ) : // NOTE: this check is to prevent an infinite loop - starting !== current ? ( + starting !== matchedRoute?.route.path ? ( ) : (
@@ -53,7 +55,7 @@ const ClusterFrameLayout = withInjectables(NonInjectedClusterFrame ...props, currentRouteComponent: di.inject(currentRouteComponentInjectable), startUrl: di.inject(startUrlInjectable), - currentPath: di.inject(currentPathInjectable), + matchedRoute: di.inject(matchingRouteInjectable), }), }); diff --git a/packages/core/src/renderer/navigation/matched-cluster-id.injectable.ts b/packages/core/src/renderer/navigation/matched-cluster-id.injectable.ts index 2c2bb01f75..5c3bbc222d 100644 --- a/packages/core/src/renderer/navigation/matched-cluster-id.injectable.ts +++ b/packages/core/src/renderer/navigation/matched-cluster-id.injectable.ts @@ -3,15 +3,18 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; -import clusterViewRouteParametersInjectable from "../components/cluster-manager/cluster-view-route-parameters.injectable"; +import { computed } from "mobx"; +import clusterViewRouteInjectable from "../../common/front-end-routing/routes/cluster-view/cluster-view-route.injectable"; +import routePathParametersInjectable from "../routes/route-path-parameters.injectable"; const matchedClusterIdInjectable = getInjectable({ id: "matched-cluster-id", instantiate: (di) => { - const routeParameters = di.inject(clusterViewRouteParametersInjectable); + const route = di.inject(clusterViewRouteInjectable); + const pathParameters = di.inject(routePathParametersInjectable)(route); - return routeParameters.clusterId; + return computed(() => pathParameters.get()?.clusterId); }, }); diff --git a/packages/core/src/renderer/navigation/page-param.ts b/packages/core/src/renderer/navigation/page-param.ts index e7511045e2..f75a26a1cd 100644 --- a/packages/core/src/renderer/navigation/page-param.ts +++ b/packages/core/src/renderer/navigation/page-param.ts @@ -36,9 +36,7 @@ export type PageParamDeclaration = ( ? StringPageParamDeclaration : Value extends Array ? ArrayPageParamDeclaration - : Value extends unknown - ? FallthroughPageParamDeclaration - : DefaultPageParamDeclaration + : DefaultPageParamDeclaration ); export function getPageParamDeclaration(decl: PageParamDeclaration): PageParamDeclaration { diff --git a/packages/core/src/renderer/routes/current-route.injectable.ts b/packages/core/src/renderer/routes/current-route.injectable.ts index fad42b6c36..6e010f87eb 100644 --- a/packages/core/src/renderer/routes/current-route.injectable.ts +++ b/packages/core/src/renderer/routes/current-route.injectable.ts @@ -15,7 +15,7 @@ const currentRouteInjectable = getInjectable({ return computed(() => { const match = matchingRoute.get(); - if (match && match.route.isEnabled.get()) { + if (match?.route.isEnabled.get()) { return match.route; } diff --git a/packages/core/src/renderer/routes/extension-route-registrator.injectable.tsx b/packages/core/src/renderer/routes/extension-route-registrator.injectable.tsx index e1a34cd242..1295f7edf1 100644 --- a/packages/core/src/renderer/routes/extension-route-registrator.injectable.tsx +++ b/packages/core/src/renderer/routes/extension-route-registrator.injectable.tsx @@ -15,7 +15,7 @@ import extensionPageParametersInjectable from "./extension-page-parameters.injec import { getRouteSpecificComponentInjectable } from "./route-specific-component-injection-token"; import type { IComputedValue } from "mobx"; import { computed } from "mobx"; -import { frontEndRouteInjectionToken } from "../../common/front-end-routing/front-end-route-injection-token"; +import { getFrontEndRouteInjectable } from "../../common/front-end-routing/front-end-route-injection-token"; import { getExtensionRoutePath } from "./for-extension"; import extensionShouldBeEnabledForClusterFrameInjectable from "../extension-loader/extension-should-be-enabled-for-cluster-frame.injectable"; import type { PageRegistration } from "./page-registration"; @@ -65,17 +65,12 @@ export default extensionRouteRegistratorInjectable; const toRouteInjectableFor = (di: DiContainerForInjection, extension: LensRendererExtension) => ( (clusterFrame: boolean, getIsEnabled: (registration: PageRegistration) => IComputedValue) => ( (registration: PageRegistration) => { - const routeInjectable = getInjectable({ + const routeInjectable = getFrontEndRouteInjectable({ id: `route-${registration.id ?? ""}-for-extension-${extension.sanitizedExtensionId}`, - - instantiate: () => ({ - path: getExtensionRoutePath(extension, registration.id), - clusterFrame, - isEnabled: getIsEnabled(registration), - extension, - }), - - injectionToken: frontEndRouteInjectionToken, + path: getExtensionRoutePath(extension, registration.id), + clusterFrame, + isEnabled: getIsEnabled(registration), + extension, }); const normalizedParams = di.inject(extensionPageParametersInjectable, { diff --git a/packages/core/src/renderer/routes/matching-route.injectable.ts b/packages/core/src/renderer/routes/matching-route.injectable.ts index 66cf12af57..852f1d7c9f 100644 --- a/packages/core/src/renderer/routes/matching-route.injectable.ts +++ b/packages/core/src/renderer/routes/matching-route.injectable.ts @@ -4,10 +4,15 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import routesInjectable from "./routes.injectable"; -import { matches } from "lodash/fp"; import { computed } from "mobx"; import { matchPath } from "react-router"; import currentPathInjectable from "./current-path.injectable"; +import type { InferParamFromPath, Route } from "../../common/front-end-routing/front-end-route-injection-token"; + +export interface MatchedRoute { + route: Route; + pathParameters: InferParamFromPath; +} const matchingRouteInjectable = getInjectable({ id: "matching-route", @@ -16,21 +21,22 @@ const matchingRouteInjectable = getInjectable({ const routes = di.inject(routesInjectable); const currentPath = di.inject(currentPathInjectable); - return computed(() => { - const matchedRoutes = routes.get().map((route) => { + return computed((): MatchedRoute | undefined => { + for (const route of routes.get()) { const match = matchPath(currentPath.get(), { path: route.path, exact: true, }); - return { - route, - isMatching: !!match, - pathParameters: match ? match.params : {}, - }; - }); + if (match) { + return { + route, + pathParameters: match.params, + }; + } + } - return matchedRoutes.find(matches({ isMatching: true })); + return undefined; }); }, }); diff --git a/packages/core/src/renderer/routes/navigate-to-route.injectable.ts b/packages/core/src/renderer/routes/navigate-to-route.injectable.ts index 4a8ca31ccd..e656906585 100644 --- a/packages/core/src/renderer/routes/navigate-to-route.injectable.ts +++ b/packages/core/src/renderer/routes/navigate-to-route.injectable.ts @@ -4,6 +4,7 @@ */ import { getInjectable } from "@ogre-tools/injectable"; import { navigateToUrlInjectionToken } from "../../common/front-end-routing/navigate-to-url-injection-token"; +import type { NavigateToRoute } from "../../common/front-end-routing/navigate-to-route-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"; @@ -18,7 +19,7 @@ const navigateToRouteInjectable = getInjectable({ currentlyInClusterFrameInjectable, ); - return (route, options) => { + return ((route, options) => { const url = buildURL(route.path, { params: options?.parameters as object, query: options?.query, @@ -29,7 +30,7 @@ const navigateToRouteInjectable = getInjectable({ ...options, forceRootFrame: currentlyInClusterFrame && route.clusterFrame === false, }); - }; + }) as NavigateToRoute; }, injectionToken: navigateToRouteInjectionToken, diff --git a/packages/core/src/renderer/routes/page-registration.ts b/packages/core/src/renderer/routes/page-registration.ts index 87946722ed..98e8d167ae 100644 --- a/packages/core/src/renderer/routes/page-registration.ts +++ b/packages/core/src/renderer/routes/page-registration.ts @@ -13,7 +13,8 @@ export interface PageRegistration { * When not provided, first registered page without "id" would be used for page-menus without target.pageId for same extension */ id?: string; - params?: Params extends PageParams> ? Params : never; + // eslint-disable-next-line unused-imports/no-unused-vars-ts, @typescript-eslint/no-unused-vars + params?: Params extends PageParams> ? Params : never; components: PageComponents; enabled?: IComputedValue; } diff --git a/packages/core/src/renderer/routes/route-is-active.injectable.ts b/packages/core/src/renderer/routes/route-is-active.injectable.ts index 59bc34e299..c520ed6552 100644 --- a/packages/core/src/renderer/routes/route-is-active.injectable.ts +++ b/packages/core/src/renderer/routes/route-is-active.injectable.ts @@ -11,7 +11,7 @@ import { matchPath } from "react-router-dom"; const routeIsActiveInjectable = getInjectable({ id: "route-is-active", - instantiate: (di, route: Route) => { + instantiate: (di, route: Route) => { const currentPath = di.inject(currentPathInjectable); return computed(() => !!matchPath(currentPath.get(), { @@ -21,7 +21,7 @@ const routeIsActiveInjectable = getInjectable({ }, lifecycle: lifecycleEnum.keyedSingleton({ - getInstanceKey: (di, route: Route) => route.path, + getInstanceKey: (di, route: Route) => route.path, }), }); diff --git a/packages/core/src/renderer/routes/route-path-parameters.injectable.ts b/packages/core/src/renderer/routes/route-path-parameters.injectable.ts index 8b2ac9a755..adf5d4144e 100644 --- a/packages/core/src/renderer/routes/route-path-parameters.injectable.ts +++ b/packages/core/src/renderer/routes/route-path-parameters.injectable.ts @@ -2,32 +2,27 @@ * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; +import { getInjectable } from "@ogre-tools/injectable"; import { computed } from "mobx"; import { matchPath } from "react-router"; import currentPathInjectable from "./current-path.injectable"; -import type { Route } from "../../common/front-end-routing/front-end-route-injection-token"; +import type { InferParamFromPath, Route } from "../../common/front-end-routing/front-end-route-injection-token"; const routePathParametersInjectable = getInjectable({ id: "route-path-parameters", - instantiate: (di, route: Route) => { + instantiate: (di) => { const currentPath = di.inject(currentPathInjectable); - // TODO: Reuse typing from route for accuracy - return computed((): Record => { + return (route: Route) => computed(() => { const match = matchPath(currentPath.get(), { path: route.path, exact: true, }); - return match ? match.params : {}; + return match?.params as InferParamFromPath | undefined; }); }, - - lifecycle: lifecycleEnum.keyedSingleton({ - getInstanceKey: (di, route: Route) => route, - }), }); export default routePathParametersInjectable; diff --git a/packages/core/src/renderer/routes/route-specific-component-injection-token.ts b/packages/core/src/renderer/routes/route-specific-component-injection-token.ts index b1c4caeda6..bc77427fc7 100644 --- a/packages/core/src/renderer/routes/route-specific-component-injection-token.ts +++ b/packages/core/src/renderer/routes/route-specific-component-injection-token.ts @@ -4,26 +4,26 @@ */ import type { Injectable } from "@ogre-tools/injectable"; import { getInjectable, getInjectionToken } from "@ogre-tools/injectable"; -import type { Route } from "../../common/front-end-routing/front-end-route-injection-token"; +import type { InferParamFromPath, Route } from "../../common/front-end-routing/front-end-route-injection-token"; export const routeSpecificComponentInjectionToken = getInjectionToken<{ - route: Route; - Component: React.ComponentType; + route: Route; + Component: React.ComponentType<{ params: InferParamFromPath }>; }>({ id: "route-specific-component-injection-token", }); -export interface GetRouteSpecificComponentOptions { +export interface GetRouteSpecificComponentOptions { id: string; - routeInjectable: Injectable, Route, void>; - Component: Params extends object ? React.ComponentType : React.ComponentType; + routeInjectable: Injectable, Route, void>; + Component: React.ComponentType<{ params?: InferParamFromPath }>; } -export const getRouteSpecificComponentInjectable = (options: GetRouteSpecificComponentOptions) => getInjectable({ +export const getRouteSpecificComponentInjectable = (options: GetRouteSpecificComponentOptions) => getInjectable({ id: options.id, instantiate: (di) => ({ route: di.inject(options.routeInjectable), - Component: options.Component as React.ComponentType, + Component: options.Component as React.ComponentType<{ params: InferParamFromPath }>, }), injectionToken: routeSpecificComponentInjectionToken, }); diff --git a/packages/utility-features/utilities/src/type-narrowing.ts b/packages/utility-features/utilities/src/type-narrowing.ts index 37f2f7f706..44335c981d 100644 --- a/packages/utility-features/utilities/src/type-narrowing.ts +++ b/packages/utility-features/utilities/src/type-narrowing.ts @@ -125,7 +125,7 @@ export function isDefined(val: T | undefined | null): val is T { export type ExtractOr = Extract extends never ? Fallback : Extract; -// @ts-expect-error +// @ts-expect-error 2677 export declare function isFunction(val: T): val is ExtractOr unknown> { return typeof val === "function"; }