1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

chore: Improve typing of front end routes to fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-05-03 13:22:19 -04:00
parent 048ed7d143
commit e5c25f94a3
106 changed files with 722 additions and 1286 deletions

View File

@ -2,19 +2,85 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 type { IComputedValue } from "mobx";
import { computed } from "mobx";
import type { Simplify } from "type-fest";
import type { LensRendererExtension } from "../../extensions/lens-renderer-extension"; import type { LensRendererExtension } from "../../extensions/lens-renderer-extension";
export const frontEndRouteInjectionToken = getInjectionToken<Route<unknown>>({ declare const emptyObjectSymbol: unique symbol;
export interface EmptyObject {[emptyObjectSymbol]?: never}
export const frontEndRouteInjectionToken = getInjectionToken<Route<string>>({
id: "front-end-route-injection-token", id: "front-end-route-injection-token",
}); });
export interface Route<TParameter = void> { type InferParamFromPart<Part extends string> =
path: string; Part extends `:${infer Name}?`
? { [key in Name]?: string }
: Part extends `:${infer Name}`
? { [key in Name]: string }
: EmptyObject;
export type HelperInferParamFromPath<Path extends string> =
Path extends `/${infer First}/${infer Tail}`
? InferParamFromPart<First> & HelperInferParamFromPath<`/${Tail}`>
: Path extends `/${infer First}`
? InferParamFromPart<First>
: EmptyObject;
export type InferParamFromPath<Path extends string> = keyof Simplify<Omit<HelperInferParamFromPath<Path>, typeof emptyObjectSymbol>> extends never
? EmptyObject
: Simplify<Omit<HelperInferParamFromPath<Path>, typeof emptyObjectSymbol>>;
export type ParametersFromRouteInjectable<RouteInjectable> =
RouteInjectable extends Injectable<Route<infer Path extends string>, Route<string>, void>
? InferParamFromPath<Path>
: never;
export type RouteFromInjectable<RouteInjectable> =
RouteInjectable extends Injectable<Route<infer Path extends string>, Route<string>, void>
? Route<Path>
: never;
export interface Route<Path extends string> {
id: string;
path: Path;
clusterFrame: boolean; clusterFrame: boolean;
isEnabled: IComputedValue<boolean>; isEnabled: IComputedValue<boolean>;
extension?: LensRendererExtension; extension?: LensRendererExtension;
readonly parameterSignature?: TParameter;
} }
export interface RouteOptions<Path extends string> {
id: string;
path: Path | ((di: DiContainerForInjection) => Path);
clusterFrame: boolean;
/**
* defaults to `true`
*/
isEnabled?: IComputedValue<boolean> | ((di: DiContainerForInjection) => IComputedValue<boolean>);
extension?: LensRendererExtension;
}
export const getFrontEndRouteInjectable = <Path extends string>({
id,
path,
isEnabled,
...rest
}: RouteOptions<Path>) => getInjectable({
id,
instantiate: (di) => ({
...rest,
id,
path: isString(path)
? path
: path(di),
isEnabled: isFunction(isEnabled)
? isEnabled(di)
: isEnabled ?? computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
});

View File

@ -2,9 +2,10 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { getInjectionToken } from "@ogre-tools/injectable";
import type { HasRequiredKeys } from "type-fest"; 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<TParameters extends object> = ( export type NavigateWithParameterOptions<TParameters extends object> = (
HasRequiredKeys<TParameters> extends true HasRequiredKeys<TParameters> extends true
@ -12,32 +13,29 @@ export type NavigateWithParameterOptions<TParameters extends object> = (
: { parameters?: TParameters } : { parameters?: TParameters }
); );
export type NavigateWithParameterOptionsForRoute<TRoute> = (
TRoute extends Route<infer Params extends object>
? NavigateWithParameterOptions<Params>
: { parameters?: undefined }
);
export interface BaseNavigateToRouteOptions { export interface BaseNavigateToRouteOptions {
query?: Record<string, string>; query?: Record<string, string>;
fragment?: string; fragment?: string;
withoutAffectingBackButton?: boolean; withoutAffectingBackButton?: boolean;
} }
export type NavigateToRouteOptions<TRoute> = ( export type NavigateToRouteOptions<Path extends string> = (
TRoute extends Route<void> HasRequiredKeys<InferParamFromPath<Path>> extends true
? ([] | [options: BaseNavigateToRouteOptions]) ? ([options: BaseNavigateToRouteOptions & { parameters: InferParamFromPath<Path> }])
: TRoute extends Route<infer Params extends object> : ([] | [options: BaseNavigateToRouteOptions & { parameters?: InferParamFromPath<Path> }])
? HasRequiredKeys<Params> extends true
? [options: BaseNavigateToRouteOptions & { parameters: Params }]
: ([] | [options: BaseNavigateToRouteOptions & { parameters?: Params }])
: ([] | [options: BaseNavigateToRouteOptions])
); );
export interface NavigateToRoute { export interface NavigateToRoute {
<Route>(route: Route, ...options: NavigateToRouteOptions<Route>): void; <Path extends string>(route: Route<Path>, ...options: NavigateToRouteOptions<Path>): void;
} }
export type NavigateToSpecificRoute<InjectableRoute> =
InjectableRoute extends Injectable<Route<infer Path>, Route<string>, void>
? HasRequiredKeys<InferParamFromPath<Path>> extends true
? (parameters: InferParamFromPath<Path>) => void
: (parameters?: InferParamFromPath<Path>) => void
: never;
export const navigateToRouteInjectionToken = getInjectionToken<NavigateToRoute>( export const navigateToRouteInjectionToken = getInjectionToken<NavigateToRoute>(
{ id: "navigate-to-route-injection-token" }, { id: "navigate-to-route-injection-token" },
); );

View File

@ -2,20 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token";
import { computed } from "mobx";
import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token";
const addClusterRouteInjectable = getInjectable({ const addClusterRouteInjectable = getFrontEndRouteInjectable({
id: "add-cluster-route", id: "add-cluster-route",
instantiate: () => ({
path: "/add-cluster", path: "/add-cluster",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default addClusterRouteInjectable; export default addClusterRouteInjectable;

View File

@ -2,26 +2,15 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import type { ParametersFromRouteInjectable } from "../../front-end-route-injection-token";
import { computed } from "mobx"; import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token";
import type { Route } from "../../front-end-route-injection-token";
import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token";
export interface CatalogPathParameters { export type CatalogPathParameters = ParametersFromRouteInjectable<typeof catalogRouteInjectable>;
group?: string;
kind?: string;
}
const catalogRouteInjectable = getInjectable({ const catalogRouteInjectable = getFrontEndRouteInjectable({
id: "catalog-route", id: "catalog-route",
instantiate: (): Route<CatalogPathParameters> => ({
path: "/catalog/:group?/:kind?", path: "/catalog/:group?/:kind?",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default catalogRouteInjectable; export default catalogRouteInjectable;

View File

@ -16,9 +16,7 @@ const navigateToCatalogInjectable = getInjectable({
const navigateToRoute = di.inject(navigateToRouteInjectionToken); const navigateToRoute = di.inject(navigateToRouteInjectionToken);
const catalogRoute = di.inject(catalogRouteInjectable); const catalogRoute = di.inject(catalogRouteInjectable);
return (parameters) => navigateToRoute(catalogRoute, { return (parameters) => navigateToRoute(catalogRoute, { parameters });
parameters,
});
}, },
}); });

View File

@ -2,20 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token";
import { computed } from "mobx";
import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token";
const clusterViewRouteInjectable = getInjectable({ const clusterViewRouteInjectable = getFrontEndRouteInjectable({
id: "cluster-view-route", id: "cluster-view-route",
instantiate: () => ({
path: "/cluster/:clusterId", path: "/cluster/:clusterId",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default clusterViewRouteInjectable; export default clusterViewRouteInjectable;

View File

@ -15,8 +15,7 @@ const navigateToClusterViewInjectable = getInjectable({
const navigateToRoute = di.inject(navigateToRouteInjectionToken); const navigateToRoute = di.inject(navigateToRouteInjectionToken);
const route = di.inject(clusterViewRouteInjectable); const route = di.inject(clusterViewRouteInjectable);
return (clusterId) => return (clusterId) => navigateToRoute(route, { parameters: { clusterId }});
navigateToRoute(route, { parameters: { clusterId }});
}, },
}); });

View File

@ -2,21 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "config-maps-route",
instantiate: (di) => ({
path: "/configmaps", path: "/configmaps",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "configmaps", apiName: "configmaps",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default configMapsRouteInjectable; export default configMapsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "horizontal-pod-autoscalers-route",
instantiate: (di) => ({
path: "/hpa", path: "/hpa",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "horizontalpodautoscalers", apiName: "horizontalpodautoscalers",
group: "autoscaling", group: "autoscaling",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default horizontalPodAutoscalersRouteInjectable; export default horizontalPodAutoscalersRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "leases",
instantiate: (di) => ({
path: "/leases", path: "/leases",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "leases", apiName: "leases",
group: "coordination.k8s.io", group: "coordination.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default leasesRouteInjectable; export default leasesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "limit-ranges-route",
instantiate: (di) => ({
path: "/limitranges", path: "/limitranges",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "limitranges", apiName: "limitranges",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default limitRangesRouteInjectable; export default limitRangesRouteInjectable;

View File

@ -2,25 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token";
shouldShowResourceInjectionToken, import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token";
} 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";
const mutatingWebhookConfigurationsRouteInjectable = getInjectable({ const mutatingWebhookConfigurationsRouteInjectable = getFrontEndRouteInjectable({
id: "mutatingwebhookconfigurations", id: "mutatingwebhookconfigurations",
instantiate: (di) => ({
path: "/mutatingwebhookconfigurations", path: "/mutatingwebhookconfigurations",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "mutatingwebhookconfigurations", apiName: "mutatingwebhookconfigurations",
group: "admissionregistration.k8s.io", group: "admissionregistration.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default mutatingWebhookConfigurationsRouteInjectable; export default mutatingWebhookConfigurationsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "pod-disruption-budgets-route",
instantiate: (di) => ({
path: "/poddisruptionbudgets", path: "/poddisruptionbudgets",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "poddisruptionbudgets", apiName: "poddisruptionbudgets",
group: "policy", group: "policy",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default podDisruptionBudgetsRouteInjectable; export default podDisruptionBudgetsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "priority-classes-route",
instantiate: (di) => ({
path: "/priorityclasses", path: "/priorityclasses",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "priorityclasses", apiName: "priorityclasses",
group: "scheduling.k8s.io", group: "scheduling.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default priorityClassesRouteInjectable; export default priorityClassesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "resource-quotas-route",
instantiate: (di) => ({
path: "/resourcequotas", path: "/resourcequotas",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "resourcequotas", apiName: "resourcequotas",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default resourceQuotasRouteInjectable; export default resourceQuotasRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "runtime-classes-route",
instantiate: (di) => ({
path: "/runtimeclasses", path: "/runtimeclasses",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "runtimeclasses", apiName: "runtimeclasses",
group: "node.k8s.io", group: "node.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default runtimeClassesRouteInjectable; export default runtimeClassesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "secrets-route",
instantiate: (di) => ({
path: "/secrets", path: "/secrets",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "secrets", apiName: "secrets",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default secretsRouteInjectable; export default secretsRouteInjectable;

View File

@ -3,22 +3,16 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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";
import { getInjectable } from "@ogre-tools/injectable";
const validatingWebhookConfigurationsRouteInjectable = getInjectable({ const validatingWebhookConfigurationsRouteInjectable = getFrontEndRouteInjectable({
id: "validatingwebhookconfigurations", id: "validatingwebhookconfigurations",
instantiate: (di) => ({
path: "/validatingwebhookconfigurations", path: "/validatingwebhookconfigurations",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "validatingwebhookconfigurations", apiName: "validatingwebhookconfigurations",
group: "admissionregistration.k8s.io", group: "admissionregistration.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default validatingWebhookConfigurationsRouteInjectable; export default validatingWebhookConfigurationsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "vertical-pod-autoscalers-route",
instantiate: (di) => ({
path: "/vpa", path: "/vpa",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "verticalpodautoscalers", apiName: "verticalpodautoscalers",
group: "autoscaling.k8s.io", group: "autoscaling.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default verticalPodAutoscalersRouteInjectable; export default verticalPodAutoscalersRouteInjectable;

View File

@ -2,26 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token";
import { computed } from "mobx";
import type { Route } from "../../../front-end-route-injection-token";
import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token";
export interface CustomResourcesPathParameters { const customResourcesRouteInjectable = getFrontEndRouteInjectable({
group: string;
name: string;
}
const customResourcesRouteInjectable = getInjectable({
id: "custom-resources-route", id: "custom-resources-route",
path: "/crd/:group?/:name?",
instantiate: (): Route<CustomResourcesPathParameters> => ({
path: "/crd/:group/:name",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default customResourcesRouteInjectable; export default customResourcesRouteInjectable;

View File

@ -4,10 +4,9 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { navigateToRouteInjectionToken } from "../../../navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../navigate-to-route-injection-token";
import type { CustomResourcesPathParameters } from "./custom-resources-route.injectable";
import customResourcesRouteInjectable from "./custom-resources-route.injectable"; import customResourcesRouteInjectable from "./custom-resources-route.injectable";
export type NavigateToCustomResources = (parameters: CustomResourcesPathParameters) => void; export type NavigateToCustomResources = NavigateToSpecificRoute<typeof customResourcesRouteInjectable>;
const navigateToCustomResourcesInjectable = getInjectable({ const navigateToCustomResourcesInjectable = getInjectable({
id: "navigate-to-custom-resources", id: "navigate-to-custom-resources",

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "events-route",
instantiate: (di) => ({
path: "/events", path: "/events",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "events", apiName: "events",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default eventsRouteInjectable; export default eventsRouteInjectable;

View File

@ -2,26 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token";
import { computed } from "mobx";
import type { Route } from "../../../../front-end-route-injection-token";
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
export interface HelmChartsPathParameters { const helmChartsRouteInjectable = getFrontEndRouteInjectable({
repo?: string;
chartName?: string;
}
const helmChartsRouteInjectable = getInjectable({
id: "helm-charts-route", id: "helm-charts-route",
instantiate: (): Route<HelmChartsPathParameters> => ({
path: "/helm/charts/:repo?/:chartName?", path: "/helm/charts/:repo?/:chartName?",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default helmChartsRouteInjectable; export default helmChartsRouteInjectable;

View File

@ -3,11 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { HelmChartsPathParameters } from "./helm-charts-route.injectable";
import helmChartsRouteInjectable 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"; import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token";
export type NavigateToHelmCharts = (parameters?: HelmChartsPathParameters) => void; export type NavigateToHelmCharts = NavigateToSpecificRoute<typeof helmChartsRouteInjectable>;
const navigateToHelmChartsInjectable = getInjectable({ const navigateToHelmChartsInjectable = getInjectable({
id: "navigate-to-helm-charts", id: "navigate-to-helm-charts",
@ -16,10 +16,7 @@ const navigateToHelmChartsInjectable = getInjectable({
const navigateToRoute = di.inject(navigateToRouteInjectionToken); const navigateToRoute = di.inject(navigateToRouteInjectionToken);
const route = di.inject(helmChartsRouteInjectable); const route = di.inject(helmChartsRouteInjectable);
return (parameters) => return (parameters) => navigateToRoute(route, { parameters });
navigateToRoute(route, {
parameters,
});
}, },
}); });

View File

@ -2,26 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token";
import { computed } from "mobx";
import type { Route } from "../../../../front-end-route-injection-token";
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
export interface HelmReleasesPathParameters { export interface HelmReleasesPathParameters {
namespace?: string; namespace?: string;
name?: string; name?: string;
} }
const helmReleasesRouteInjectable = getInjectable({ const helmReleasesRouteInjectable = getFrontEndRouteInjectable({
id: "helm-releases-route", id: "helm-releases-route",
instantiate: (): Route<HelmReleasesPathParameters> => ({
path: "/helm/releases/:namespace?/:name?", path: "/helm/releases/:namespace?/:name?",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default helmReleasesRouteInjectable; export default helmReleasesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "namespaces-route",
instantiate: (di) => ({
path: "/namespaces", path: "/namespaces",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "namespaces", apiName: "namespaces",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default namespacesRouteInjectable; export default namespacesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "endpoints-route",
instantiate: (di) => ({
path: "/endpoints", path: "/endpoints",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "endpoints", apiName: "endpoints",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default endpointsRouteInjectable; export default endpointsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token";
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
import { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-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", id: "ingress-classes-route",
instantiate: (di) => ({
path: "/ingress-classes", path: "/ingress-classes",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "ingressclasses", apiName: "ingressclasses",
group: "networking.k8s.io", group: "networking.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default ingressClassesRouteInjectable; export default ingressClassesRouteInjectable;

View File

@ -2,18 +2,15 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { shouldShowResourceInjectionToken } from "../../../../../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token";
import { computedOr } from "@k8slens/utilities"; 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", id: "ingresses-route",
instantiate: (di) => ({
path: "/ingresses", path: "/ingresses",
clusterFrame: true, clusterFrame: true,
isEnabled: computedOr( isEnabled: (di) => computedOr(
di.inject(shouldShowResourceInjectionToken, { di.inject(shouldShowResourceInjectionToken, {
apiName: "ingresses", apiName: "ingresses",
group: "networking.k8s.io", group: "networking.k8s.io",
@ -23,9 +20,6 @@ const ingressesRouteInjectable = getInjectable({
group: "extensions", group: "extensions",
}), }),
), ),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default ingressesRouteInjectable; export default ingressesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "network-policies-route",
instantiate: (di) => ({
path: "/network-policies", path: "/network-policies",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "networkpolicies", apiName: "networkpolicies",
group: "networking.k8s.io", group: "networking.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default networkPoliciesRouteInjectable; export default networkPoliciesRouteInjectable;

View File

@ -3,11 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { PortForwardsPathParameters } from "./port-forwards-route.injectable";
import portForwardsRouteInjectable 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"; import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token";
export type NavigateToPortForwards = (parameters?: PortForwardsPathParameters) => void; export type NavigateToPortForwards = NavigateToSpecificRoute<typeof portForwardsRouteInjectable>;
const navigateToPortForwardsInjectable = getInjectable({ const navigateToPortForwardsInjectable = getInjectable({
id: "navigate-to-port-forwards", id: "navigate-to-port-forwards",
@ -16,8 +16,7 @@ const navigateToPortForwardsInjectable = getInjectable({
const navigateToRoute = di.inject(navigateToRouteInjectionToken); const navigateToRoute = di.inject(navigateToRouteInjectionToken);
const route = di.inject(portForwardsRouteInjectable); const route = di.inject(portForwardsRouteInjectable);
return (parameters) => return (parameters) => navigateToRoute(route, { parameters });
navigateToRoute(route, { parameters });
}, },
}); });

View File

@ -2,25 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token";
import { computed } from "mobx";
import type { Route } from "../../../../front-end-route-injection-token";
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
export interface PortForwardsPathParameters { const portForwardsRouteInjectable = getFrontEndRouteInjectable({
forwardPort?: string;
}
const portForwardsRouteInjectable = getInjectable({
id: "port-forwards-route", id: "port-forwards-route",
instantiate: (): Route<PortForwardsPathParameters> => ({
path: "/port-forwards/:forwardPort?", path: "/port-forwards/:forwardPort?",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default portForwardsRouteInjectable; export default portForwardsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "services-route",
instantiate: (di) => ({
path: "/services", path: "/services",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "services", apiName: "services",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default servicesRouteInjectable; export default servicesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "nodes-route",
instantiate: (di) => ({
path: "/nodes", path: "/nodes",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "nodes", apiName: "nodes",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default nodesRouteInjectable; export default nodesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "cluster-overview-route",
instantiate: (di) => ({
path: "/overview", path: "/overview",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "nodes", apiName: "nodes",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default clusterOverviewRouteInjectable; export default clusterOverviewRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "persistent-volume-claims-route",
instantiate: (di) => ({
path: "/persistent-volume-claims", path: "/persistent-volume-claims",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "persistentvolumeclaims", apiName: "persistentvolumeclaims",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default persistentVolumeClaimsRouteInjectable; export default persistentVolumeClaimsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "persistent-volumes-route",
instantiate: (di) => ({
path: "/persistent-volumes", path: "/persistent-volumes",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "persistentvolumes", apiName: "persistentvolumes",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default persistentVolumesRouteInjectable; export default persistentVolumesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "storage-classes-route",
instantiate: (di) => ({
path: "/storage-classes", path: "/storage-classes",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "storageclasses", apiName: "storageclasses",
group: "storage.k8s.io", group: "storage.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default storageClassesRouteInjectable; export default storageClassesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "cluster-role-bindings-route",
instantiate: (di) => ({
path: "/cluster-role-bindings", path: "/cluster-role-bindings",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "clusterrolebindings", apiName: "clusterrolebindings",
group: "rbac.authorization.k8s.io", group: "rbac.authorization.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default clusterRoleBindingsRouteInjectable; export default clusterRoleBindingsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "cluster-roles-route",
instantiate: (di) => ({
path: "/cluster-roles", path: "/cluster-roles",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "clusterroles", apiName: "clusterroles",
group: "rbac.authorization.k8s.io", group: "rbac.authorization.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default clusterRolesRouteInjectable; export default clusterRolesRouteInjectable;

View File

@ -2,25 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "pod-security-policies-route",
instantiate: (di) => {
return {
path: "/pod-security-policies", path: "/pod-security-policies",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "podsecuritypolicies", apiName: "podsecuritypolicies",
group: "policy", group: "policy",
}), }),
};
},
injectionToken: frontEndRouteInjectionToken,
}); });
export default podSecurityPoliciesRouteInjectable; export default podSecurityPoliciesRouteInjectable;

View File

@ -2,25 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "role-bindings-route",
instantiate: (di) => {
return {
path: "/role-bindings", path: "/role-bindings",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "rolebindings", apiName: "rolebindings",
group: "rbac.authorization.k8s.io", group: "rbac.authorization.k8s.io",
}), }),
};
},
injectionToken: frontEndRouteInjectionToken,
}); });
export default roleBindingsRouteInjectable; export default roleBindingsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "roles-route",
instantiate: (di) => ({
path: "/roles", path: "/roles",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "roles", apiName: "roles",
group: "rbac.authorization.k8s.io", group: "rbac.authorization.k8s.io",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default rolesRouteInjectable; export default rolesRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "service-accounts-route",
instantiate: (di) => ({
path: "/service-accounts", path: "/service-accounts",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "serviceaccounts", apiName: "serviceaccounts",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default serviceAccountsRouteInjectable; export default serviceAccountsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "cron-jobs-route",
instantiate: (di) => ({
path: "/cronjobs", path: "/cronjobs",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "cronjobs", apiName: "cronjobs",
group: "batch", group: "batch",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default cronJobsRouteInjectable; export default cronJobsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "daemonsets-route",
instantiate: (di) => ({
path: "/daemonsets", path: "/daemonsets",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "daemonsets", apiName: "daemonsets",
group: "apps", group: "apps",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default daemonsetsRouteInjectable; export default daemonsetsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "deployments-route",
instantiate: (di) => ({
path: "/deployments", path: "/deployments",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "deployments", apiName: "deployments",
group: "apps", group: "apps",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default deploymentsRouteInjectable; export default deploymentsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "jobs-route",
instantiate: (di) => ({
path: "/jobs", path: "/jobs",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "jobs", apiName: "jobs",
group: "batch", group: "batch",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default jobsRouteInjectable; export default jobsRouteInjectable;

View File

@ -2,20 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../../../front-end-route-injection-token";
import { computed } from "mobx";
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
const workloadsOverviewRouteInjectable = getInjectable({ const workloadsOverviewRouteInjectable = getFrontEndRouteInjectable({
id: "workloads-overview-route", id: "workloads-overview-route",
instantiate: () => ({
path: "/workloads", path: "/workloads",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default workloadsOverviewRouteInjectable; export default workloadsOverviewRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "pods-route",
instantiate: (di) => ({
path: "/pods", path: "/pods",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "pods", apiName: "pods",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default podsRouteInjectable; export default podsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "replicasets-route",
instantiate: (di) => ({
path: "/replicasets", path: "/replicasets",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "replicasets", apiName: "replicasets",
group: "apps", group: "apps",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default replicasetsRouteInjectable; export default replicasetsRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "replication-controllers-route",
instantiate: (di) => ({
path: "/replication-controllers", path: "/replication-controllers",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "replicationcontrollers", apiName: "replicationcontrollers",
group: "", // core group: "", // core
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default replicationControllersRouteInjectable; export default replicationControllersRouteInjectable;

View File

@ -2,23 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 { 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", id: "statefulsets-route",
instantiate: (di) => ({
path: "/statefulsets", path: "/statefulsets",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "statefulsets", apiName: "statefulsets",
group: "apps", group: "apps",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default statefulsetsRouteInjectable; export default statefulsetsRouteInjectable;

View File

@ -2,25 +2,16 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token";
import { computed } from "mobx";
import type { Route } from "../../front-end-route-injection-token";
import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token";
export interface EntitySettingsPathParameters { export interface EntitySettingsPathParameters {
entityId: string; entityId: string;
} }
const entitySettingsRouteInjectable = getInjectable({ const entitySettingsRouteInjectable = getFrontEndRouteInjectable({
id: "entity-settings-route", id: "entity-settings-route",
instantiate: (): Route<EntitySettingsPathParameters> => ({
path: "/entity/:entityId/settings", path: "/entity/:entityId/settings",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default entitySettingsRouteInjectable; export default entitySettingsRouteInjectable;

View File

@ -2,20 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../front-end-route-injection-token";
import { computed } from "mobx";
import { frontEndRouteInjectionToken } from "../../front-end-route-injection-token";
const extensionsRouteInjectable = getInjectable({ const extensionsRouteInjectable = getFrontEndRouteInjectable({
id: "extensions-route", id: "extensions-route",
instantiate: () => ({
path: "/extensions", path: "/extensions",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default extensionsRouteInjectable; export default extensionsRouteInjectable;

View File

@ -2,25 +2,19 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx"; import { computed } from "mobx";
import welcomeRouteConfigInjectable from "./welcome-route-config.injectable"; 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", id: "default-welcome-route",
instantiate: (di) => {
const welcomeRoute = di.inject(welcomeRouteConfigInjectable);
return {
path: "/welcome", path: "/welcome",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => welcomeRoute === "/welcome"), isEnabled: (di) => {
}; const welcomeRoute = di.inject(welcomeRouteConfigInjectable);
},
injectionToken: frontEndRouteInjectionToken, return computed(() => welcomeRoute === "/welcome");
},
}); });
export default defaultWelcomeRouteInjectable; export default defaultWelcomeRouteInjectable;

View File

@ -2,25 +2,13 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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 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", id: "welcome-route",
path: (di) => di.inject(welcomeRouteConfigInjectable),
instantiate: (di) => {
const welcomeRoute = di.inject(welcomeRouteConfigInjectable);
return {
path: welcomeRoute,
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
};
},
injectionToken: frontEndRouteInjectionToken,
}); });
export default welcomeRouteInjectable; export default welcomeRouteInjectable;

View File

@ -50,7 +50,7 @@ import type { PageParamInit } from "./renderer-api/navigation";
interface LensRendererExtensionDependencies extends LensExtensionDependencies { interface LensRendererExtensionDependencies extends LensExtensionDependencies {
navigateToRoute: NavigateToRoute; navigateToRoute: NavigateToRoute;
getExtensionPageParameters: GetExtensionPageParameters; getExtensionPageParameters: GetExtensionPageParameters;
readonly routes: IComputedValue<Route<unknown>[]>; readonly routes: IComputedValue<Route<string>[]>;
readonly entityRegistry: CatalogEntityRegistry; readonly entityRegistry: CatalogEntityRegistry;
readonly categoryRegistry: CatalogCategoryRegistry; readonly categoryRegistry: CatalogCategoryRegistry;
} }

View File

@ -9,8 +9,8 @@ import type { ApplicationBuilder } from "../../../../renderer/components/test-ut
import type { KubernetesCluster } from "../../../../common/catalog-entities"; import type { KubernetesCluster } from "../../../../common/catalog-entities";
import { getApplicationBuilder } 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 { 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 { computed, runInAction } from "mobx"; import { runInAction } from "mobx";
import React from "react"; import React from "react";
import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token";
import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-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", id: "test-route",
instantiate: () => ({
path: "/test-route", path: "/test-route",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const testRouteComponentInjectable = getInjectable({ const testRouteComponentInjectable = getInjectable({

View File

@ -6,7 +6,7 @@ import type { RenderResult } from "@testing-library/react";
import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } 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 { 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 type { IObservableValue } from "mobx";
import { observable, runInAction, computed } from "mobx"; import { observable, runInAction, computed } from "mobx";
import React from "react"; import React from "react";
@ -83,16 +83,10 @@ describe("reactively hide kube object menu item", () => {
}); });
}); });
const testRouteInjectable = getInjectable({ const testRouteInjectable = getFrontEndRouteInjectable({
id: "test-route", id: "test-route",
instantiate: () => ({
path: "/test-route", path: "/test-route",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const testRouteComponentInjectable = getInjectable({ const testRouteComponentInjectable = getInjectable({

View File

@ -9,8 +9,8 @@ import type { ApplicationBuilder } from "../../../../renderer/components/test-ut
import type { KubernetesCluster } from "../../../../common/catalog-entities"; import type { KubernetesCluster } from "../../../../common/catalog-entities";
import { getApplicationBuilder } 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 { 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 { computed, runInAction } from "mobx"; import { runInAction } from "mobx";
import React from "react"; import React from "react";
import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token"; import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token";
import { routeSpecificComponentInjectionToken } from "../../../../renderer/routes/route-specific-component-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", id: "test-route",
instantiate: () => ({
path: "/test-route", path: "/test-route",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const testRouteComponentInjectable = getInjectable({ const testRouteComponentInjectable = getInjectable({

View File

@ -6,7 +6,7 @@ import type { RenderResult } from "@testing-library/react";
import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } 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 { 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 type { IObservableValue } from "mobx";
import { observable, runInAction, computed } from "mobx"; import { observable, runInAction, computed } from "mobx";
import React from "react"; import React from "react";
@ -88,16 +88,10 @@ describe("reactively hide kube object status", () => {
}); });
}); });
const testRouteInjectable = getInjectable({ const testRouteInjectable = getFrontEndRouteInjectable({
id: "test-route", id: "test-route",
instantiate: () => ({
path: "/test-route", path: "/test-route",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const testRouteComponentInjectable = getInjectable({ const testRouteComponentInjectable = getInjectable({

View File

@ -8,7 +8,7 @@ import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { IAtom } from "mobx"; import type { IAtom } from "mobx";
import { runInAction, createAtom, computed } 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 { routeSpecificComponentInjectionToken } from "../../../renderer/routes/route-specific-component-injection-token";
import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } 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", id: "test-route",
instantiate: () => ({
path: "/test-route", path: "/test-route",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const rerenderParentFor = (atom: IAtom) => () => { const rerenderParentFor = (atom: IAtom) => () => {

View File

@ -12,7 +12,7 @@ import { sidebarItemInjectionToken } from "@k8slens/cluster-sidebar";
import { computed, runInAction } from "mobx"; import { computed, runInAction } from "mobx";
import { noop } from "lodash/fp"; import { noop } from "lodash/fp";
import routeIsActiveInjectable from "../../renderer/routes/route-is-active.injectable"; 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 type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } 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"; import writeJsonFileInjectable from "../../common/fs/write-json-file.injectable";
@ -324,16 +324,10 @@ const someChildSidebarItemInjectable = getInjectable({
injectionToken: sidebarItemInjectionToken, injectionToken: sidebarItemInjectionToken,
}); });
const testRouteInjectable = getInjectable({ const testRouteInjectable = getFrontEndRouteInjectable({
id: "some-route-injectable-id", id: "some-route-injectable-id",
instantiate: () => ({
path: "/some-child-page", path: "/some-child-page",
clusterFrame: true, clusterFrame: true,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const testRouteComponentInjectable = getInjectable({ const testRouteComponentInjectable = getInjectable({

View File

@ -8,7 +8,7 @@ import { sidebarItemInjectionToken } from "@k8slens/cluster-sidebar";
import { runInAction } from "mobx"; import { runInAction } from "mobx";
import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token";
import React from "react"; 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 type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } 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"; 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", id: "some-route-injectable-id",
instantiate: (di) => ({
path: "/some-child-page", path: "/some-child-page",
clusterFrame: true, clusterFrame: true,
isEnabled: di.inject(shouldShowResourceInjectionToken, { isEnabled: (di) => di.inject(shouldShowResourceInjectionToken, {
apiName: "namespaces", apiName: "namespaces",
group: "", group: "",
}), }),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const testRouteComponentInjectable = getInjectable({ const testRouteComponentInjectable = getInjectable({

View File

@ -5,12 +5,12 @@
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import React from "react"; import React from "react";
import { computed, runInAction } from "mobx"; import { runInAction } from "mobx";
import type { RenderResult } from "@testing-library/react"; import type { RenderResult } from "@testing-library/react";
import { routeSpecificComponentInjectionToken } from "../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../renderer/routes/route-specific-component-injection-token";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { Route } from "../common/front-end-routing/front-end-route-injection-token"; import type { RouteFromInjectable } from "../common/front-end-routing/front-end-route-injection-token";
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 type { ApplicationBuilder } from "../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } 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"; import currentRouteInjectable from "../renderer/routes/current-route.injectable";
@ -44,7 +44,7 @@ describe("navigating between routes", () => {
}); });
describe("when navigating to route", () => { describe("when navigating to route", () => {
let route: Route; let route: RouteFromInjectable<typeof testRouteWithoutPathParametersInjectable>;
beforeEach(() => { beforeEach(() => {
const navigateToRoute = windowDi.inject(navigateToRouteInjectionToken); const navigateToRoute = windowDi.inject(navigateToRouteInjectionToken);
@ -77,7 +77,7 @@ describe("navigating between routes", () => {
}); });
it("does not have path parameters", () => { it("does not have path parameters", () => {
const pathParameters = windowDi.inject(routePathParametersInjectable, route); const pathParameters = windowDi.inject(routePathParametersInjectable)(route);
expect(pathParameters.get()).toEqual({}); expect(pathParameters.get()).toEqual({});
}); });
@ -120,10 +120,7 @@ describe("navigating between routes", () => {
}); });
describe("when navigating to route with path parameters", () => { describe("when navigating to route with path parameters", () => {
let route: Route<{ let route: RouteFromInjectable<typeof routeWithOptionalPathParametersInjectable>;
someParameter?: string | undefined;
someOtherParameter?: string | undefined;
}>;
beforeEach(() => { beforeEach(() => {
route = windowDi.inject(routeWithOptionalPathParametersInjectable); route = windowDi.inject(routeWithOptionalPathParametersInjectable);
@ -157,7 +154,7 @@ describe("navigating between routes", () => {
}); });
it("knows path parameters", () => { it("knows path parameters", () => {
const pathParameters = windowDi.inject(routePathParametersInjectable, route); const pathParameters = windowDi.inject(routePathParametersInjectable)(route);
expect(pathParameters.get()).toEqual({ expect(pathParameters.get()).toEqual({
someParameter: "some-value", someParameter: "some-value",
@ -167,10 +164,7 @@ describe("navigating between routes", () => {
}); });
describe("when navigating to route without path parameters", () => { describe("when navigating to route without path parameters", () => {
let route: Route<{ let route: RouteFromInjectable<typeof routeWithOptionalPathParametersInjectable>;
someParameter?: string | undefined;
someOtherParameter?: string | undefined;
}>;
beforeEach(() => { beforeEach(() => {
route = windowDi.inject(routeWithOptionalPathParametersInjectable); route = windowDi.inject(routeWithOptionalPathParametersInjectable);
@ -193,7 +187,7 @@ describe("navigating between routes", () => {
}); });
it("knows path parameters", () => { it("knows path parameters", () => {
const pathParameters = windowDi.inject(routePathParametersInjectable, route); const pathParameters = windowDi.inject(routePathParametersInjectable)(route);
expect(pathParameters.get()).toEqual({ expect(pathParameters.get()).toEqual({
someParameter: undefined, someParameter: undefined,
@ -204,15 +198,10 @@ describe("navigating between routes", () => {
}); });
}); });
const testRouteWithoutPathParametersInjectable = getInjectable({ const testRouteWithoutPathParametersInjectable = getFrontEndRouteInjectable({
id: "some-route", id: "some-route",
injectionToken: frontEndRouteInjectionToken,
instantiate: (): Route<void> => ({
path: "/some-path", path: "/some-path",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
}); });
const testRouteWithoutPathParametersComponentInjectable = getInjectable({ const testRouteWithoutPathParametersComponentInjectable = getInjectable({
@ -226,15 +215,10 @@ const testRouteWithoutPathParametersComponentInjectable = getInjectable({
injectionToken: routeSpecificComponentInjectionToken, injectionToken: routeSpecificComponentInjectionToken,
}); });
const routeWithOptionalPathParametersInjectable = getInjectable({ const routeWithOptionalPathParametersInjectable = getFrontEndRouteInjectable({
id: "some-route", id: "some-route",
injectionToken: frontEndRouteInjectionToken,
instantiate: (): Route<{ someParameter?: string; someOtherParameter?: string }> => ({
path: "/some-path/:someParameter?/:someOtherParameter?", path: "/some-path/:someParameter?/:someOtherParameter?",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
}); });
const routeWithOptionalPathParametersComponentInjectable = getInjectable({ const routeWithOptionalPathParametersComponentInjectable = getInjectable({
@ -242,7 +226,7 @@ const routeWithOptionalPathParametersComponentInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const route = di.inject(routeWithOptionalPathParametersInjectable); const route = di.inject(routeWithOptionalPathParametersInjectable);
const pathParameters = di.inject(routePathParametersInjectable, route); const pathParameters = di.inject(routePathParametersInjectable)(route);
return { return {
route, route,

View File

@ -8,8 +8,8 @@ import type { RenderResult } from "@testing-library/react";
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
import { getApplicationBuilder } 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 currentPathInjectable from "../../renderer/routes/current-path.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 { computed, runInAction } from "mobx"; import { runInAction } from "mobx";
import React from "react"; import React from "react";
import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token"; import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token";
import { observableHistoryInjectionToken, searchParamsOptions } from "@k8slens/routing"; import { observableHistoryInjectionToken, searchParamsOptions } from "@k8slens/routing";
@ -210,16 +210,10 @@ describe("preferences - closing-preferences", () => {
}); });
}); });
const testFrontPageRouteInjectable = getInjectable({ const testFrontPageRouteInjectable = getFrontEndRouteInjectable({
id: "some-front-page", id: "some-front-page",
instantiate: () => ({
path: "/some-front-page", path: "/some-front-page",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const testFrontPageRouteComponentInjectable = getInjectable({ const testFrontPageRouteComponentInjectable = getInjectable({
@ -233,16 +227,10 @@ const testFrontPageRouteComponentInjectable = getInjectable({
injectionToken: routeSpecificComponentInjectionToken, injectionToken: routeSpecificComponentInjectionToken,
}); });
const testRouteInjectable = getInjectable({ const testRouteInjectable = getFrontEndRouteInjectable({
id: "some-page", id: "some-page",
instantiate: () => ({
path: "/some-page", path: "/some-page",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const testRouteComponentInjectable = getInjectable({ const testRouteComponentInjectable = getInjectable({

View File

@ -2,20 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token";
import { computed } from "mobx";
import { frontEndRouteInjectionToken } from "../../../common/front-end-routing/front-end-route-injection-token";
const preferencesRouteForLegacyExtensionsInjectable = getInjectable({ const preferencesRouteForLegacyExtensionsInjectable = getFrontEndRouteInjectable({
id: "preferences-route-for-legacy-extensions", id: "preferences-route-for-legacy-extensions",
instantiate: () => ({
path: "/preferences/extension/:extensionId/:preferenceTabId?", path: "/preferences/extension/:extensionId/:preferenceTabId?",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default preferencesRouteForLegacyExtensionsInjectable; export default preferencesRouteForLegacyExtensionsInjectable;

View File

@ -2,20 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getFrontEndRouteInjectable } from "../../../common/front-end-routing/front-end-route-injection-token";
import { computed } from "mobx";
import { frontEndRouteInjectionToken } from "../../../common/front-end-routing/front-end-route-injection-token";
const preferencesRouteInjectable = getInjectable({ const preferencesRouteInjectable = getFrontEndRouteInjectable({
id: "preferences-route", id: "preferences-route",
instantiate: () => ({
path: "/preferences/:preferenceTabId?", path: "/preferences/:preferenceTabId?",
clusterFrame: false, clusterFrame: false,
isEnabled: computed(() => true),
}),
injectionToken: frontEndRouteInjectionToken,
}); });
export default preferencesRouteInjectable; export default preferencesRouteInjectable;

View File

@ -14,19 +14,13 @@ const currentPreferenceTabIdInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const preferencesRoute = di.inject(preferencesRouteInjectable); const preferencesRoute = di.inject(preferencesRouteInjectable);
const preferencesRouteForLegacyExtensions = di.inject(preferencesRouteForLegacyExtensionsInjectable); const preferencesRouteForLegacyExtensions = di.inject(preferencesRouteForLegacyExtensionsInjectable);
const routePathParameters = di.inject(routePathParametersInjectable);
const nonLegacyRoutePathParameters = di.inject( const nonLegacyRoutePathParameters = routePathParameters(preferencesRoute);
routePathParametersInjectable, const legacyRoutePathParameters = routePathParameters(preferencesRouteForLegacyExtensions);
preferencesRoute,
);
const legacyRoutePathParameters = di.inject(
routePathParametersInjectable,
preferencesRouteForLegacyExtensions,
);
return computed(() => { return computed(() => {
const nonLegacyPreferenceTabId = nonLegacyRoutePathParameters.get().preferenceTabId; const nonLegacyPreferenceTabId = nonLegacyRoutePathParameters.get()?.preferenceTabId;
if (nonLegacyPreferenceTabId) { if (nonLegacyPreferenceTabId) {
return nonLegacyPreferenceTabId; return nonLegacyPreferenceTabId;
@ -34,7 +28,7 @@ const currentPreferenceTabIdInjectable = getInjectable({
const legacyParameters = legacyRoutePathParameters.get(); const legacyParameters = legacyRoutePathParameters.get();
if (legacyParameters.extensionId) { if (legacyParameters?.extensionId) {
if (legacyParameters.preferenceTabId) { if (legacyParameters.preferenceTabId) {
return `extension-${legacyParameters.extensionId}-${legacyParameters.preferenceTabId}`; return `extension-${legacyParameters.extensionId}-${legacyParameters.preferenceTabId}`;
} }

View File

@ -15,7 +15,7 @@ import type { Route } from "../../common/front-end-routing/front-end-route-injec
describe("setting-welcome-page", () => { describe("setting-welcome-page", () => {
let builder: ApplicationBuilder; let builder: ApplicationBuilder;
let rendered : RenderResult; let rendered : RenderResult;
let welcomeRoute: Route; let welcomeRoute: Route<string>;
beforeEach(() => { beforeEach(() => {
builder = getApplicationBuilder(); builder = getApplicationBuilder();

View File

@ -4,6 +4,7 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { navigateToUrlInjectionToken } from "../../common/front-end-routing/navigate-to-url-injection-token"; 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 { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token";
import { buildURL } from "@k8slens/utilities"; import { buildURL } from "@k8slens/utilities";
@ -13,15 +14,15 @@ const navigateToRouteInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const navigateToUrl = di.inject(navigateToUrlInjectionToken); const navigateToUrl = di.inject(navigateToUrlInjectionToken);
return async (route, options) => { return ((route, options) => {
const url = buildURL(route.path, { const url = buildURL(route.path, {
params: options?.parameters as object, params: options?.parameters as object,
query: options?.query, query: options?.query,
fragment: options?.fragment, fragment: options?.fragment,
}); });
await navigateToUrl(url, options); void navigateToUrl(url, options);
}; }) as NavigateToRoute;
}, },
injectionToken: navigateToRouteInjectionToken, injectionToken: navigateToRouteInjectionToken,

View File

@ -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;

View File

@ -6,7 +6,7 @@
import styles from "./catalog.module.scss"; import styles from "./catalog.module.scss";
import type { IComputedValue } from "mobx"; 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 { disposeOnUnmount, observer } from "mobx-react";
import React from "react"; import React from "react";
import type { CatalogCategory, CatalogCategoryRegistry, CatalogEntity } from "../../../common/catalog"; 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 { browseCatalogTab } from "./catalog-browse-tab";
import catalogEntityStoreInjectable from "./catalog-entity-store.injectable"; import catalogEntityStoreInjectable from "./catalog-entity-store.injectable";
import catalogPreviousActiveTabStorageInjectable from "./catalog-previous-active-tab-storage/catalog-previous-active-tab-storage.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 type { CategoryColumns, GetCategoryColumnsParams } from "./columns/get.injectable";
import getCategoryColumnsInjectable from "./columns/get.injectable"; import getCategoryColumnsInjectable from "./columns/get.injectable";
import type { CustomCategoryViewComponents } from "./custom-views"; 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 showEntityDetailsInjectable from "./entity-details/show.injectable";
import type { Hotbar } from "../../../features/hotbar/storage/common/hotbar"; import type { Hotbar } from "../../../features/hotbar/storage/common/hotbar";
import activeHotbarInjectable from "../../../features/hotbar/storage/common/active.injectable"; 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<typeof catalogRouteInjectable>;
}
interface Dependencies { interface Dependencies {
catalogPreviousActiveTabStorage: StorageLayer<string | null>; catalogPreviousActiveTabStorage: StorageLayer<string | null>;
@ -60,10 +65,6 @@ interface Dependencies {
emitEvent: EmitAppEvent; emitEvent: EmitAppEvent;
showEntityDetails: ShowEntityDetails; showEntityDetails: ShowEntityDetails;
onCatalogEntityListClick: OnCatalogEntityListClick; onCatalogEntityListClick: OnCatalogEntityListClick;
routeParameters: {
group: IComputedValue<string>;
kind: IComputedValue<string>;
};
navigateToCatalog: NavigateToCatalog; navigateToCatalog: NavigateToCatalog;
catalogCategoryRegistry: CatalogCategoryRegistry; catalogCategoryRegistry: CatalogCategoryRegistry;
visitEntityContextMenu: VisitEntityContextMenu; visitEntityContextMenu: VisitEntityContextMenu;
@ -75,28 +76,19 @@ interface Dependencies {
} }
@observer @observer
class NonInjectedCatalog extends React.Component<Dependencies> { class NonInjectedCatalog extends React.Component<Dependencies & CatalogProps> {
private readonly menuItems = observable.array<CatalogEntityContextMenu>(); private readonly menuItems = observable.array<CatalogEntityContextMenu>();
@observable activeTab: string | undefined = undefined; readonly activeTab = observable.box<string>();
constructor(props: Dependencies) { readonly routeActiveTab = computed(() => {
super(props); const { params: { group, kind }, catalogPreviousActiveTabStorage } = this.props;
makeObservable(this);
}
@computed if (group && kind) {
get routeActiveTab(): string { return `${group}/${kind}`;
const { routeParameters: { group, kind }, catalogPreviousActiveTabStorage } = this.props;
const dereferencedGroup = group.get();
const dereferencedKind = kind.get();
if (dereferencedGroup && dereferencedKind) {
return `${dereferencedGroup}/${dereferencedKind}`;
} }
return catalogPreviousActiveTabStorage.get() || browseCatalogTab; return catalogPreviousActiveTabStorage.get() || browseCatalogTab;
} });
componentDidMount() { componentDidMount() {
const { const {
@ -109,8 +101,8 @@ class NonInjectedCatalog extends React.Component<Dependencies> {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
catalogEntityStore.watch(), catalogEntityStore.watch(),
reaction(() => this.routeActiveTab, (routeTab) => { reaction(() => this.routeActiveTab.get(), (routeTab) => {
catalogPreviousActiveTabStorage.set(this.routeActiveTab); catalogPreviousActiveTabStorage.set(routeTab);
void (async () => { void (async () => {
try { try {
@ -122,7 +114,7 @@ class NonInjectedCatalog extends React.Component<Dependencies> {
const item = catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab); const item = catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab);
runInAction(() => { runInAction(() => {
this.activeTab = routeTab; this.activeTab.set(routeTab);
catalogEntityStore.activeCategory.set(item); catalogEntityStore.activeCategory.set(item);
}); });
} catch (error) { } catch (error) {
@ -141,14 +133,14 @@ class NonInjectedCatalog extends React.Component<Dependencies> {
const currentCategory = catalogEntityStore.activeCategory.get(); const currentCategory = catalogEntityStore.activeCategory.get();
const someCategory = categories[0]; const someCategory = categories[0];
if (this.routeActiveTab === browseCatalogTab || !someCategory) { if (this.routeActiveTab.get() === browseCatalogTab || !someCategory) {
return; return;
} }
const currentCategoryShouldBeShown = Boolean(categories.find(item => item.getId() === someCategory.getId())); const currentCategoryShouldBeShown = Boolean(categories.find(item => item.getId() === someCategory.getId()));
if (!currentCategory || !currentCategoryShouldBeShown) { if (!currentCategory || !currentCategoryShouldBeShown) {
this.activeTab = someCategory.getId(); this.activeTab.set(someCategory.getId());
this.props.catalogEntityStore.activeCategory.set(someCategory); this.props.catalogEntityStore.activeCategory.set(someCategory);
} }
}), }),
@ -296,7 +288,7 @@ class NonInjectedCatalog extends React.Component<Dependencies> {
<MainLayout <MainLayout
sidebar={( sidebar={(
<CatalogMenu <CatalogMenu
activeTab={this.activeTab} activeTab={this.activeTab.get()}
onItemClick={this.onTabChange} onItemClick={this.onTabChange}
/> />
)} )}
@ -318,14 +310,13 @@ class NonInjectedCatalog extends React.Component<Dependencies> {
} }
} }
export const Catalog = withInjectables<Dependencies>(NonInjectedCatalog, { export const Catalog = withInjectables<Dependencies, CatalogProps>(NonInjectedCatalog, {
getProps: (di, props) => ({ getProps: (di, props) => ({
...props, ...props,
catalogEntityStore: di.inject(catalogEntityStoreInjectable), catalogEntityStore: di.inject(catalogEntityStoreInjectable),
catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable), catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable),
getCategoryColumns: di.inject(getCategoryColumnsInjectable), getCategoryColumns: di.inject(getCategoryColumnsInjectable),
customCategoryViews: di.inject(customCategoryViewsInjectable), customCategoryViews: di.inject(customCategoryViewsInjectable),
routeParameters: di.inject(catalogRouteParametersInjectable),
navigateToCatalog: di.inject(navigateToCatalogInjectable), navigateToCatalog: di.inject(navigateToCatalogInjectable),
emitEvent: di.inject(emitAppEventInjectable), emitEvent: di.inject(emitAppEventInjectable),
activeHotbar: di.inject(activeHotbarInjectable), activeHotbar: di.inject(activeHotbarInjectable),

View File

@ -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;

View File

@ -5,16 +5,13 @@
import "./cluster-view.scss"; import "./cluster-view.scss";
import React from "react"; import React from "react";
import type { IComputedValue } from "mobx"; import { computed, reaction } from "mobx";
import { computed, makeObservable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { ClusterStatus } from "./cluster-status"; import { ClusterStatus } from "./cluster-status";
import type { ClusterFrameHandler } from "./cluster-frame-handler"; import type { ClusterFrameHandler } from "./cluster-frame-handler";
import type { Cluster } from "../../../common/cluster/cluster";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";
import type { NavigateToCatalog } from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable"; 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 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 clusterFrameHandlerInjectable from "./cluster-frame-handler.injectable";
import type { CatalogEntityRegistry } from "../../api/catalog/entity/registry"; import type { CatalogEntityRegistry } from "../../api/catalog/entity/registry";
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable"; 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 requestClusterActivationInjectable from "../../../features/cluster/activation/renderer/request-activation.injectable";
import type { GetClusterById } from "../../../features/cluster/storage/common/get-by-id.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 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<typeof clusterViewRouteInjectable>;
}
interface Dependencies { interface Dependencies {
clusterId: IComputedValue<string>;
clusterFrames: ClusterFrameHandler; clusterFrames: ClusterFrameHandler;
navigateToCatalog: NavigateToCatalog; navigateToCatalog: NavigateToCatalog;
entityRegistry: CatalogEntityRegistry; entityRegistry: CatalogEntityRegistry;
@ -34,34 +35,27 @@ interface Dependencies {
} }
@observer @observer
class NonInjectedClusterView extends React.Component<Dependencies> { class NonInjectedClusterView extends React.Component<Dependencies & ClusterViewProps> {
constructor(props: Dependencies) {
super(props);
makeObservable(this);
}
get clusterId() { get clusterId() {
return this.props.clusterId.get(); return this.props.params.clusterId;
} }
@computed get cluster(): Cluster | undefined { readonly cluster = computed(() => this.props.getClusterById(this.clusterId));
return this.props.getClusterById(this.clusterId);
}
private readonly isViewLoaded = computed(() => this.props.clusterFrames.hasLoadedView(this.clusterId), { private readonly isViewLoaded = computed(() => this.props.clusterFrames.hasLoadedView(this.clusterId), {
keepAlive: true, keepAlive: true,
requiresReaction: true, requiresReaction: true,
}); });
@computed get isReady(): boolean { readonly isReady = computed(() => {
const { cluster } = this; const cluster = this.cluster.get();
if (!cluster) { if (!cluster) {
return false; return false;
} }
return cluster.ready.get() && cluster.available.get() && this.isViewLoaded.get(); return cluster.ready.get() && cluster.available.get() && this.isViewLoaded.get();
} });
componentDidMount() { componentDidMount() {
this.bindEvents(); this.bindEvents();
@ -94,8 +88,9 @@ class NonInjectedClusterView extends React.Component<Dependencies> {
]); ]);
} }
renderStatus(): StrictReactNode { renderStatus() {
const { cluster, isReady } = this; const cluster = this.cluster.get();
const isReady = this.isReady.get();
if (cluster && !isReady) { if (cluster && !isReady) {
return <ClusterStatus cluster={cluster} className="box center"/>; return <ClusterStatus cluster={cluster} className="box center"/>;
@ -113,9 +108,9 @@ class NonInjectedClusterView extends React.Component<Dependencies> {
} }
} }
export const ClusterView = withInjectables<Dependencies>(NonInjectedClusterView, { export const ClusterView = withInjectables<Dependencies, ClusterViewProps>(NonInjectedClusterView, {
getProps: (di) => ({ getProps: (di, props) => ({
...di.inject(clusterViewRouteParametersInjectable), ...props,
navigateToCatalog: di.inject(navigateToCatalogInjectable), navigateToCatalog: di.inject(navigateToCatalogInjectable),
clusterFrames: di.inject(clusterFrameHandlerInjectable), clusterFrames: di.inject(clusterFrameHandlerInjectable),
entityRegistry: di.inject(catalogEntityRegistryInjectable), entityRegistry: di.inject(catalogEntityRegistryInjectable),

View File

@ -7,9 +7,7 @@ import "./leases.scss";
import * as React from "react"; import * as React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { Lease } from "@k8slens/kube-object";
import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { KubeObjectStatusIcon } from "../kube-object-status-icon";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { KubeObjectListLayout } from "../kube-object-list-layout"; import { KubeObjectListLayout } from "../kube-object-list-layout";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
import { KubeObjectAge } from "../kube-object/age"; import { KubeObjectAge } from "../kube-object/age";
@ -25,14 +23,12 @@ enum columnId {
age = "age", age = "age",
} }
export type LeaseProps = KubeObjectDetailsProps<Lease>;
interface Dependencies { interface Dependencies {
leaseStore: LeaseStore; leaseStore: LeaseStore;
} }
@observer @observer
class NonInjectedLease extends React.Component<LeaseProps & Dependencies> { class NonInjectedLease extends React.Component<Dependencies> {
render() { render() {
const { leaseStore } = this.props; const { leaseStore } = this.props;
@ -76,7 +72,7 @@ class NonInjectedLease extends React.Component<LeaseProps & Dependencies> {
} }
} }
export const Leases = withInjectables<Dependencies, LeaseProps>(NonInjectedLease, { export const Leases = withInjectables<Dependencies>(NonInjectedLease, {
getProps: (di, props) => ({ getProps: (di, props) => ({
...props, ...props,
leaseStore: di.inject(leaseStoreInjectable), leaseStore: di.inject(leaseStoreInjectable),

View File

@ -7,9 +7,7 @@ import "./pod-disruption-budgets.scss";
import * as React from "react"; import * as React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { PodDisruptionBudget } from "@k8slens/kube-object";
import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { KubeObjectStatusIcon } from "../kube-object-status-icon";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { KubeObjectListLayout } from "../kube-object-list-layout"; import { KubeObjectListLayout } from "../kube-object-list-layout";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
import { KubeObjectAge } from "../kube-object/age"; import { KubeObjectAge } from "../kube-object/age";
@ -28,14 +26,12 @@ enum columnId {
age = "age", age = "age",
} }
export type PodDisruptionBudgetsProps = KubeObjectDetailsProps<PodDisruptionBudget>;
interface Dependencies { interface Dependencies {
podDisruptionBudgetStore: PodDisruptionBudgetStore; podDisruptionBudgetStore: PodDisruptionBudgetStore;
} }
@observer @observer
class NonInjectedPodDisruptionBudgets extends React.Component<PodDisruptionBudgetsProps & Dependencies> { class NonInjectedPodDisruptionBudgets extends React.Component<Dependencies> {
render() { render() {
return ( return (
<SiblingsInTabLayout> <SiblingsInTabLayout>
@ -86,7 +82,7 @@ class NonInjectedPodDisruptionBudgets extends React.Component<PodDisruptionBudge
} }
} }
export const PodDisruptionBudgets = withInjectables<Dependencies, PodDisruptionBudgetsProps>(NonInjectedPodDisruptionBudgets, { export const PodDisruptionBudgets = withInjectables<Dependencies>(NonInjectedPodDisruptionBudgets, {
getProps: (di, props) => ({ getProps: (di, props) => ({
...props, ...props,
podDisruptionBudgetStore: di.inject(podDisruptionBudgetStoreInjectable), podDisruptionBudgetStore: di.inject(podDisruptionBudgetStoreInjectable),

View File

@ -7,16 +7,13 @@ import "./priority-classes.scss";
import * as React from "react"; import * as React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { PriorityClass } from "@k8slens/kube-object";
import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { KubeObjectStatusIcon } from "../kube-object-status-icon";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { KubeObjectListLayout } from "../kube-object-list-layout"; import { KubeObjectListLayout } from "../kube-object-list-layout";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
import { KubeObjectAge } from "../kube-object/age"; import { KubeObjectAge } from "../kube-object/age";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";
import priorityClassStoreInjectable from "./store.injectable"; import priorityClassStoreInjectable from "./store.injectable";
import type { PriorityClassStore } from "./store"; import type { PriorityClassStore } from "./store";
import autoBindReact from "auto-bind/react";
enum columnId { enum columnId {
name = "name", name = "name",
@ -25,19 +22,12 @@ enum columnId {
age = "age", age = "age",
} }
export type PriorityClassesProps = KubeObjectDetailsProps<PriorityClass>;
interface Dependencies { interface Dependencies {
priorityClassStore: PriorityClassStore; priorityClassStore: PriorityClassStore;
} }
@observer @observer
class NonInjectedPriorityClasses extends React.Component<PriorityClassesProps & Dependencies> { class NonInjectedPriorityClasses extends React.Component<Dependencies> {
constructor(props: PriorityClassesProps & Dependencies) {
super(props);
autoBindReact(this);
}
render() { render() {
const { priorityClassStore } = this.props; const { priorityClassStore } = this.props;
@ -78,7 +68,7 @@ class NonInjectedPriorityClasses extends React.Component<PriorityClassesProps &
} }
} }
export const PriorityClasses = withInjectables<Dependencies, PriorityClassesProps>(NonInjectedPriorityClasses, { export const PriorityClasses = withInjectables<Dependencies>(NonInjectedPriorityClasses, {
getProps: (di, props) => ({ getProps: (di, props) => ({
...props, ...props,
priorityClassStore: di.inject(priorityClassStoreInjectable), priorityClassStore: di.inject(priorityClassStoreInjectable),

View File

@ -7,16 +7,13 @@ import "./runtime-classes.scss";
import * as React from "react"; import * as React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { RuntimeClass } from "@k8slens/kube-object";
import { KubeObjectStatusIcon } from "../kube-object-status-icon"; import { KubeObjectStatusIcon } from "../kube-object-status-icon";
import type { KubeObjectDetailsProps } from "../kube-object-details";
import { KubeObjectListLayout } from "../kube-object-list-layout"; import { KubeObjectListLayout } from "../kube-object-list-layout";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
import { KubeObjectAge } from "../kube-object/age"; import { KubeObjectAge } from "../kube-object/age";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";
import runtimeClassStoreInjectable from "./store.injectable"; import runtimeClassStoreInjectable from "./store.injectable";
import type { RuntimeClassStore } from "./store"; import type { RuntimeClassStore } from "./store";
import autoBindReact from "auto-bind/react";
enum columnId { enum columnId {
name = "name", name = "name",
@ -24,19 +21,12 @@ enum columnId {
age = "age", age = "age",
} }
export type RuntimeClassesProps = KubeObjectDetailsProps<RuntimeClass>;
interface Dependencies { interface Dependencies {
runtimeClassStore: RuntimeClassStore; runtimeClassStore: RuntimeClassStore;
} }
@observer @observer
class NonInjectedRuntimeClasses extends React.Component<RuntimeClassesProps & Dependencies> { class NonInjectedRuntimeClasses extends React.Component<Dependencies> {
constructor(props: RuntimeClassesProps & Dependencies) {
super(props);
autoBindReact(this);
}
render() { render() {
const { runtimeClassStore } = this.props; const { runtimeClassStore } = this.props;
@ -74,7 +64,7 @@ class NonInjectedRuntimeClasses extends React.Component<RuntimeClassesProps & De
} }
} }
export const RuntimeClasses = withInjectables<Dependencies, RuntimeClassesProps>(NonInjectedRuntimeClasses, { export const RuntimeClasses = withInjectables<Dependencies>(NonInjectedRuntimeClasses, {
getProps: (di, props) => ({ getProps: (di, props) => ({
...props, ...props,
runtimeClassStore: di.inject(runtimeClassStoreInjectable), runtimeClassStore: di.inject(runtimeClassStoreInjectable),

View File

@ -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;

View File

@ -8,19 +8,19 @@ import "./view.scss";
import React from "react"; import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { KubeObjectListLayout } from "../kube-object-list-layout"; import { KubeObjectListLayout } from "../kube-object-list-layout";
import type { IComputedValue } from "mobx"; import { computed } from "mobx";
import { computed, makeObservable } from "mobx";
import type { ApiManager } from "../../../common/k8s-api/api-manager"; import type { ApiManager } from "../../../common/k8s-api/api-manager";
import { formatJSONValue, safeJSONPathValue } from "@k8slens/utilities"; import { formatJSONValue, safeJSONPathValue } from "@k8slens/utilities";
import { TabLayout } from "../layout/tab-layout-2"; import { TabLayout } from "../layout/tab-layout-2";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";
import customResourcesRouteParametersInjectable from "./route-parameters.injectable";
import { KubeObjectAge } from "../kube-object/age"; import { KubeObjectAge } from "../kube-object/age";
import type { CustomResourceDefinitionStore } from "../custom-resource-definitions/store"; import type { CustomResourceDefinitionStore } from "../custom-resource-definitions/store";
import apiManagerInjectable from "../../../common/k8s-api/api-manager/manager.injectable"; import apiManagerInjectable from "../../../common/k8s-api/api-manager/manager.injectable";
import customResourceDefinitionStoreInjectable from "../custom-resource-definitions/store.injectable"; import customResourceDefinitionStoreInjectable from "../custom-resource-definitions/store.injectable";
import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge";
import type { TableCellProps } from "@k8slens/list-layout"; 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 { enum columnId {
name = "name", name = "name",
@ -29,29 +29,29 @@ enum columnId {
} }
interface Dependencies { interface Dependencies {
group: IComputedValue<string>;
name: IComputedValue<string>;
apiManager: ApiManager; apiManager: ApiManager;
customResourceDefinitionStore: CustomResourceDefinitionStore; customResourceDefinitionStore: CustomResourceDefinitionStore;
} }
export interface CustomResourcesProps {
params: ParametersFromRouteInjectable<typeof customResourcesRouteInjectable>;
}
@observer @observer
class NonInjectedCustomResources extends React.Component<Dependencies> { class NonInjectedCustomResources extends React.Component<Dependencies & CustomResourcesProps> {
constructor(props: Dependencies) { readonly crd = computed(() => {
super(props); if (this.props.params.group && this.props.params.name) {
makeObservable(this); return this.props.customResourceDefinitionStore.getByGroup(this.props.params.group, this.props.params.name);
} }
@computed get crd() { return undefined;
return this.props.customResourceDefinitionStore.getByGroup(this.props.group.get(), this.props.name.get()); });
}
@computed get store() { readonly store = computed(() => this.props.apiManager.getStore(this.crd.get()?.getResourceApiBase()));
return this.props.apiManager.getStore(this.crd?.getResourceApiBase());
}
render() { render() {
const { crd, store } = this; const crd = this.crd.get();
const store = this.store.get();
if (!crd || !store) { if (!crd || !store) {
return null; return null;
@ -132,9 +132,9 @@ class NonInjectedCustomResources extends React.Component<Dependencies> {
} }
} }
export const CustomResources = withInjectables<Dependencies>(NonInjectedCustomResources, { export const CustomResources = withInjectables<Dependencies, CustomResourcesProps>(NonInjectedCustomResources, {
getProps: (di) => ({ getProps: (di, props) => ({
...di.inject(customResourcesRouteParametersInjectable), ...props,
apiManager: di.inject(apiManagerInjectable), apiManager: di.inject(apiManagerInjectable),
customResourceDefinitionStore: di.inject(customResourceDefinitionStoreInjectable), customResourceDefinitionStore: di.inject(customResourceDefinitionStoreInjectable),
}), }),

View File

@ -4,16 +4,26 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx"; 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 catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
import entitySettingsRouteParametersInjectable from "./route-parameters.injectable"; import routePathParametersInjectable from "../../routes/route-path-parameters.injectable";
const currentCatalogEntityForSettingsInjectable = getInjectable({ const currentCatalogEntityForSettingsInjectable = getInjectable({
id: "current-catalog-entity-for-settings", id: "current-catalog-entity-for-settings",
instantiate: (di) => { instantiate: (di) => {
const { entityId } = di.inject(entitySettingsRouteParametersInjectable); const route = di.inject(entitySettingsRouteInjectable);
const pathParameters = di.inject(routePathParametersInjectable)(route);
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); 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);
});
}, },
}); });

View File

@ -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;

View File

@ -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 getDetailsUrlInjectable from "../kube-detail-params/get-details-url.injectable";
import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge";
import type { KubeEventApi } from "@k8slens/kube-api"; 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 { enum columnId {
message = "message", message = "message",
@ -48,6 +50,7 @@ export interface EventsProps extends Partial<KubeObjectListLayoutProps<KubeEvent
className?: IClassName; className?: IClassName;
compact?: boolean; compact?: boolean;
compactLimit?: number; compactLimit?: number;
params?: ParametersFromRouteInjectable<typeof eventsRouteInjectable>;
} }
const defaultProps: Partial<EventsProps> = { const defaultProps: Partial<EventsProps> = {

View File

@ -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;

View File

@ -14,13 +14,14 @@ import type { IComputedValue } from "mobx";
import type { IAsyncComputed } from "@ogre-tools/injectable-react"; import type { IAsyncComputed } from "@ogre-tools/injectable-react";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; 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 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 navigateToHelmChartsInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable";
import { HelmChartIcon } from "./icon"; import { HelmChartIcon } from "./icon";
import helmChartsInjectable from "./helm-charts/helm-charts.injectable"; import helmChartsInjectable from "./helm-charts/helm-charts.injectable";
import selectedHelmChartInjectable from "./helm-charts/selected-helm-chart.injectable"; import selectedHelmChartInjectable from "./helm-charts/selected-helm-chart.injectable";
import { noop } from "lodash"; 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 { enum columnId {
name = "name", name = "name",
@ -31,17 +32,17 @@ enum columnId {
} }
interface Dependencies { interface Dependencies {
routeParameters: {
chartName: IComputedValue<string>;
repo: IComputedValue<string>;
};
navigateToHelmCharts: NavigateToHelmCharts; navigateToHelmCharts: NavigateToHelmCharts;
charts: IAsyncComputed<HelmChart[]>; charts: IAsyncComputed<HelmChart[]>;
selectedChart: IComputedValue<HelmChart | undefined>; selectedChart: IComputedValue<HelmChart | undefined>;
} }
export interface HelmChartsProps {
params: ParametersFromRouteInjectable<typeof helmChartsRouteInjectable>;
}
@observer @observer
class NonInjectedHelmCharts extends Component<Dependencies> { class NonInjectedHelmCharts extends Component<Dependencies & HelmChartsProps> {
onDetails = (chart: HelmChart) => { onDetails = (chart: HelmChart) => {
if (chart === this.props.selectedChart.get()) { if (chart === this.props.selectedChart.get()) {
this.hideDetails(); this.hideDetails();
@ -144,9 +145,9 @@ class NonInjectedHelmCharts extends Component<Dependencies> {
} }
} }
export const HelmCharts = withInjectables<Dependencies>(NonInjectedHelmCharts, { export const HelmCharts = withInjectables<Dependencies, HelmChartsProps>(NonInjectedHelmCharts, {
getProps: (di) => ({ getProps: (di, props) => ({
routeParameters: di.inject(helmChartsRouteParametersInjectable), ...props,
navigateToHelmCharts: di.inject(navigateToHelmChartsInjectable), navigateToHelmCharts: di.inject(navigateToHelmChartsInjectable),
charts: di.inject(helmChartsInjectable), charts: di.inject(helmChartsInjectable),
selectedChart: di.inject(selectedHelmChartInjectable), selectedChart: di.inject(selectedHelmChartInjectable),

View File

@ -4,31 +4,31 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx"; 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"; import helmChartsInjectable from "./helm-charts.injectable";
const selectedHelmChartInjectable = getInjectable({ const selectedHelmChartInjectable = getInjectable({
id: "selected-helm-chart", id: "selected-helm-chart",
instantiate: (di) => { instantiate: (di) => {
const { chartName, repo } = di.inject(helmChartsRouteParametersInjectable); const route = di.inject(helmChartsRouteInjectable);
const pathParameters = di.inject(routePathParametersInjectable)(route);
const helmCharts = di.inject(helmChartsInjectable); const helmCharts = di.inject(helmChartsInjectable);
return computed(() => { return computed(() => {
const dereferencedChartName = chartName.get(); const { chartName, repo } = pathParameters.get() ?? {};
const deferencedRepository = repo.get();
if (!dereferencedChartName || !deferencedRepository) { if (!chartName || !repo) {
return undefined; return undefined;
} }
return helmCharts.value return helmCharts.value
.get() .get()
.find( .find((chart) => (
(chart) => chart.getName() === chartName
chart.getName() === dereferencedChartName && && chart.getRepository() === repo
chart.getRepository() === deferencedRepository, ));
);
}); });
}, },
}); });

View File

@ -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;

View File

@ -4,21 +4,32 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx"; 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({ const targetHelmReleaseInjectable = getInjectable({
id: "target-helm-release", id: "target-helm-release",
instantiate: (di) => { instantiate: (di) => {
const routeParameters = di.inject(helmReleasesRouteParametersInjectable); const route = di.inject(helmReleasesRouteInjectable);
const pathParameters = di.inject(routePathParametersInjectable)(route);
return computed((): TargetHelmRelease | undefined => { return computed((): TargetHelmRelease | undefined => {
const name = routeParameters.name.get(); const { name, namespace } = pathParameters.get() ?? {};
const namespace = routeParameters.namespace.get();
return name && namespace ? { name, namespace } : undefined; if (name && namespace) {
return {
name,
namespace,
};
}
return undefined;
}); });
}, },
}); });

View File

@ -6,7 +6,7 @@
import "../item-object-list/item-list-layout.scss"; import "../item-object-list/item-list-layout.scss";
import "./releases.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 type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";
import type { ItemListStore } from "../item-object-list"; import type { ItemListStore } from "../item-object-list";
@ -20,10 +20,12 @@ import type { RemovableHelmRelease } from "./removable-releases";
import type { IComputedValue } from "mobx"; import type { IComputedValue } from "mobx";
import releasesInjectable from "./releases.injectable"; import releasesInjectable from "./releases.injectable";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; 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 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 navigateToHelmReleasesInjectable from "../../../common/front-end-routing/routes/cluster/helm/releases/navigate-to-helm-releases.injectable";
import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; 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 { enum columnId {
name = "name", name = "name",
@ -39,11 +41,15 @@ enum columnId {
interface Dependencies { interface Dependencies {
releases: IComputedValue<RemovableHelmRelease[]>; releases: IComputedValue<RemovableHelmRelease[]>;
releasesArePending: IComputedValue<boolean>; releasesArePending: IComputedValue<boolean>;
namespace: IComputedValue<string>;
navigateToHelmReleases: NavigateToHelmReleases; navigateToHelmReleases: NavigateToHelmReleases;
} }
class NonInjectedHelmReleases extends Component<Dependencies> { export interface HelmReleasesProps {
params: ParametersFromRouteInjectable<typeof helmReleasesRouteInjectable>;
}
@observer
class NonInjectedHelmReleases extends React.Component<Dependencies & HelmReleasesProps> {
onDetails = (item: HelmRelease) => { onDetails = (item: HelmRelease) => {
this.showDetails(item); this.showDetails(item);
}; };
@ -206,11 +212,11 @@ class NonInjectedHelmReleases extends Component<Dependencies> {
} }
} }
export const HelmReleases = withInjectables<Dependencies>(NonInjectedHelmReleases, { export const HelmReleases = withInjectables<Dependencies, HelmReleasesProps>(NonInjectedHelmReleases, {
getProps: (di) => ({ getProps: (di, props) => ({
...props,
releases: di.inject(removableReleasesInjectable), releases: di.inject(removableReleasesInjectable),
releasesArePending: di.inject(releasesInjectable).pending, releasesArePending: di.inject(releasesInjectable).pending,
navigateToHelmReleases: di.inject(navigateToHelmReleasesInjectable), navigateToHelmReleases: di.inject(navigateToHelmReleasesInjectable),
...di.inject(helmReleasesRouteParametersInjectable),
}), }),
}); });

View File

@ -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;

View File

@ -14,12 +14,12 @@ import { PortForwardDetails } from "./port-forward-details";
import { withInjectables } from "@ogre-tools/injectable-react"; import { withInjectables } from "@ogre-tools/injectable-react";
import portForwardStoreInjectable from "../../port-forward/port-forward-store/port-forward-store.injectable"; import portForwardStoreInjectable from "../../port-forward/port-forward-store/port-forward-store.injectable";
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout"; import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
import type { IComputedValue } from "mobx"; import { computed } from "mobx";
import { computed, makeObservable } from "mobx";
import portForwardsRouteParametersInjectable from "./port-forwards-route-parameters.injectable";
import type { NavigateToPortForwards } from "../../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable"; 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 navigateToPortForwardsInjectable from "../../../common/front-end-routing/routes/cluster/network/port-forwards/navigate-to-port-forwards.injectable";
import { NamespaceSelectBadge } from "../namespaces/namespace-select-badge"; 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 { enum columnId {
name = "name", name = "name",
@ -33,38 +33,33 @@ enum columnId {
interface Dependencies { interface Dependencies {
portForwardStore: PortForwardStore; portForwardStore: PortForwardStore;
forwardPort: IComputedValue<string>;
navigateToPortForwards: NavigateToPortForwards; navigateToPortForwards: NavigateToPortForwards;
} }
@observer export interface PortForwardsProps {
class NonInjectedPortForwards extends React.Component<Dependencies> { params: ParametersFromRouteInjectable<typeof portForwardsRouteInjectable>;
constructor(props: Dependencies) {
super(props);
makeObservable(this);
} }
@observer
class NonInjectedPortForwards extends React.Component<Dependencies & PortForwardsProps> {
componentDidMount() { componentDidMount() {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
this.props.portForwardStore.watch(), this.props.portForwardStore.watch(),
]); ]);
} }
@computed readonly selectedPortForward = computed(() => {
get selectedPortForward() { const forwardPort = this.props.params.forwardPort;
const forwardPort = this.props.forwardPort.get();
if (!forwardPort) { if (!forwardPort) {
return undefined; return undefined;
} }
return this.props.portForwardStore.getById(forwardPort); return this.props.portForwardStore.getById(forwardPort);
} });
onDetails = (item: PortForwardItem) => { onDetails = (item: PortForwardItem) => {
if (item === this.selectedPortForward) { if (item === this.selectedPortForward.get()) {
this.hideDetails(); this.hideDetails();
} else { } else {
this.showDetails(item); this.showDetails(item);
@ -97,6 +92,8 @@ class NonInjectedPortForwards extends React.Component<Dependencies> {
render() { render() {
const selectedPortForward = this.selectedPortForward.get();
return ( return (
<SiblingsInTabLayout> <SiblingsInTabLayout>
<ItemListLayout<PortForwardItem, false> <ItemListLayout<PortForwardItem, false>
@ -149,12 +146,12 @@ class NonInjectedPortForwards extends React.Component<Dependencies> {
customizeRemoveDialog={selectedItems => ({ customizeRemoveDialog={selectedItems => ({
message: this.renderRemoveDialogMessage(selectedItems), message: this.renderRemoveDialogMessage(selectedItems),
})} })}
detailsItem={this.selectedPortForward} detailsItem={selectedPortForward}
onDetails={this.onDetails} onDetails={this.onDetails}
/> />
{this.selectedPortForward && ( {selectedPortForward && (
<PortForwardDetails <PortForwardDetails
portForward={this.selectedPortForward} portForward={selectedPortForward}
hideDetails={this.hideDetails} hideDetails={this.hideDetails}
/> />
)} )}
@ -163,10 +160,10 @@ class NonInjectedPortForwards extends React.Component<Dependencies> {
} }
} }
export const PortForwards = withInjectables<Dependencies>(NonInjectedPortForwards, { export const PortForwards = withInjectables<Dependencies, PortForwardsProps>(NonInjectedPortForwards, {
getProps: (di) => ({ getProps: (di, props) => ({
...props,
portForwardStore: di.inject(portForwardStoreInjectable), portForwardStore: di.inject(portForwardStoreInjectable),
...di.inject(portForwardsRouteParametersInjectable),
navigateToPortForwards: di.inject(navigateToPortForwardsInjectable), navigateToPortForwards: di.inject(navigateToPortForwardsInjectable),
}), }),
}); });

View File

@ -32,8 +32,7 @@ import assert from "assert";
import { openMenu } from "react-select-event"; import { openMenu } from "react-select-event";
import userEvent from "@testing-library/user-event"; import userEvent from "@testing-library/user-event";
import lensProxyPortInjectable from "../../../main/lens-proxy/lens-proxy-port.injectable"; 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 { NavigateToRoute } from "../../../common/front-end-routing/navigate-to-route-injection-token";
import type { NavigateToRouteOptions } from "../../../common/front-end-routing/navigate-to-route-injection-token";
import { navigateToRouteInjectionToken } 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 { LensMainExtension } from "../../../extensions/lens-main-extension";
import type { LensExtension } from "../../../extensions/lens-extension"; import type { LensExtension } from "../../../extensions/lens-extension";
@ -153,7 +152,7 @@ export interface ApplicationBuilder {
preferences: { preferences: {
close: () => void; close: () => void;
navigate: () => void; navigate: () => void;
navigateTo: <T>(route: Route<T>, params: NavigateToRouteOptions<Route<T>>) => void; navigateTo: NavigateToRoute;
navigation: { navigation: {
click: (id: string) => void; click: (id: string) => void;
}; };
@ -503,13 +502,12 @@ export const getApplicationBuilder = () => {
navigateToPreferences(); navigateToPreferences();
}, },
navigateTo: (route, params) => { navigateTo: ((...args) => {
const windowDi = builder.applicationWindow.only.di; const windowDi = builder.applicationWindow.only.di;
const navigateToRoute = windowDi.inject(navigateToRouteInjectionToken); const navigateToRoute = windowDi.inject(navigateToRouteInjectionToken);
navigateToRoute(route, params); navigateToRoute(...args);
}, }) as NavigateToRoute,
navigation: { navigation: {
click: (pathId: string) => { click: (pathId: string) => {
@ -562,6 +560,7 @@ export const getApplicationBuilder = () => {
windowDi.override(activeKubernetesClusterInjectable, () => computed(() => catalogEntityFromCluster(cluster))); windowDi.override(activeKubernetesClusterInjectable, () => computed(() => catalogEntityFromCluster(cluster)));
// TODO: Figure out a way to remove this stub. // TODO: Figure out a way to remove this stub.
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
windowDi.override(namespaceStoreInjectable, () => ({ windowDi.override(namespaceStoreInjectable, () => ({
isLoaded: true, isLoaded: true,
get contextNamespaces() { get contextNamespaces() {
@ -580,7 +579,8 @@ export const getApplicationBuilder = () => {
isSelectedAll: () => false, isSelectedAll: () => false,
getTotalCount: () => namespaceItems.length, getTotalCount: () => namespaceItems.length,
isSelected: () => false, isSelected: () => false,
} as Partial<NamespaceStore> as NamespaceStore)); // eslint-disable-next-line @typescript-eslint/no-explicit-any
} as Partial<NamespaceStore> as any));
}); });
await builder.beforeApplicationStart(({ mainDi }) => { await builder.beforeApplicationStart(({ mainDi }) => {

View File

@ -14,27 +14,29 @@ import { computed } from "mobx";
import currentRouteComponentInjectable from "../../routes/current-route-component.injectable"; import currentRouteComponentInjectable from "../../routes/current-route-component.injectable";
import { Redirect } from "react-router"; import { Redirect } from "react-router";
import startUrlInjectable from "./start-url.injectable"; import startUrlInjectable from "./start-url.injectable";
import currentPathInjectable from "../../routes/current-path.injectable";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { withInjectables } from "@ogre-tools/injectable-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 { interface Dependencies {
currentRouteComponent: IComputedValue<React.ElementType<object> | undefined>; currentRouteComponent: IComputedValue<React.ComponentType<{ params: InferParamFromPath<string> }> | undefined>;
startUrl: IComputedValue<string>; startUrl: IComputedValue<string>;
currentPath: IComputedValue<string>; matchedRoute: IComputedValue<MatchedRoute | undefined>;
} }
const NonInjectedClusterFrameLayout = observer((props: Dependencies) => { const NonInjectedClusterFrameLayout = observer((props: Dependencies) => {
const Component = props.currentRouteComponent.get(); const Component = props.currentRouteComponent.get();
const starting = props.startUrl.get(); const starting = props.startUrl.get();
const current = props.currentPath.get(); const matchedRoute = props.matchedRoute.get();
return ( return (
<MainLayout sidebar={<Sidebar />} footer={<Dock />}> <MainLayout sidebar={<Sidebar />} footer={<Dock />}>
{Component ? ( {(Component && matchedRoute) ? (
<Component /> <Component params={matchedRoute.pathParameters} />
) : // NOTE: this check is to prevent an infinite loop ) : // NOTE: this check is to prevent an infinite loop
starting !== current ? ( starting !== matchedRoute?.route.path ? (
<Redirect to={starting} /> <Redirect to={starting} />
) : ( ) : (
<div className={styles.centering}> <div className={styles.centering}>
@ -53,7 +55,7 @@ const ClusterFrameLayout = withInjectables<Dependencies>(NonInjectedClusterFrame
...props, ...props,
currentRouteComponent: di.inject(currentRouteComponentInjectable), currentRouteComponent: di.inject(currentRouteComponentInjectable),
startUrl: di.inject(startUrlInjectable), startUrl: di.inject(startUrlInjectable),
currentPath: di.inject(currentPathInjectable), matchedRoute: di.inject(matchingRouteInjectable),
}), }),
}); });

View File

@ -3,15 +3,18 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; 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({ const matchedClusterIdInjectable = getInjectable({
id: "matched-cluster-id", id: "matched-cluster-id",
instantiate: (di) => { 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);
}, },
}); });

View File

@ -36,8 +36,6 @@ export type PageParamDeclaration<Value> = (
? StringPageParamDeclaration<Value> ? StringPageParamDeclaration<Value>
: Value extends Array<infer InnerValue> : Value extends Array<infer InnerValue>
? ArrayPageParamDeclaration<InnerValue> ? ArrayPageParamDeclaration<InnerValue>
: Value extends unknown
? FallthroughPageParamDeclaration
: DefaultPageParamDeclaration<Value> : DefaultPageParamDeclaration<Value>
); );

View File

@ -15,7 +15,7 @@ const currentRouteInjectable = getInjectable({
return computed(() => { return computed(() => {
const match = matchingRoute.get(); const match = matchingRoute.get();
if (match && match.route.isEnabled.get()) { if (match?.route.isEnabled.get()) {
return match.route; return match.route;
} }

View File

@ -15,7 +15,7 @@ import extensionPageParametersInjectable from "./extension-page-parameters.injec
import { getRouteSpecificComponentInjectable } from "./route-specific-component-injection-token"; import { getRouteSpecificComponentInjectable } from "./route-specific-component-injection-token";
import type { IComputedValue } from "mobx"; import type { IComputedValue } from "mobx";
import { computed } 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 { getExtensionRoutePath } from "./for-extension";
import extensionShouldBeEnabledForClusterFrameInjectable from "../extension-loader/extension-should-be-enabled-for-cluster-frame.injectable"; import extensionShouldBeEnabledForClusterFrameInjectable from "../extension-loader/extension-should-be-enabled-for-cluster-frame.injectable";
import type { PageRegistration } from "./page-registration"; import type { PageRegistration } from "./page-registration";
@ -65,17 +65,12 @@ export default extensionRouteRegistratorInjectable;
const toRouteInjectableFor = (di: DiContainerForInjection, extension: LensRendererExtension) => ( const toRouteInjectableFor = (di: DiContainerForInjection, extension: LensRendererExtension) => (
(clusterFrame: boolean, getIsEnabled: (registration: PageRegistration) => IComputedValue<boolean>) => ( (clusterFrame: boolean, getIsEnabled: (registration: PageRegistration) => IComputedValue<boolean>) => (
(registration: PageRegistration) => { (registration: PageRegistration) => {
const routeInjectable = getInjectable({ const routeInjectable = getFrontEndRouteInjectable({
id: `route-${registration.id ?? ""}-for-extension-${extension.sanitizedExtensionId}`, id: `route-${registration.id ?? ""}-for-extension-${extension.sanitizedExtensionId}`,
instantiate: () => ({
path: getExtensionRoutePath(extension, registration.id), path: getExtensionRoutePath(extension, registration.id),
clusterFrame, clusterFrame,
isEnabled: getIsEnabled(registration), isEnabled: getIsEnabled(registration),
extension, extension,
}),
injectionToken: frontEndRouteInjectionToken,
}); });
const normalizedParams = di.inject(extensionPageParametersInjectable, { const normalizedParams = di.inject(extensionPageParametersInjectable, {

View File

@ -4,10 +4,15 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import routesInjectable from "./routes.injectable"; import routesInjectable from "./routes.injectable";
import { matches } from "lodash/fp";
import { computed } from "mobx"; import { computed } from "mobx";
import { matchPath } from "react-router"; import { matchPath } from "react-router";
import currentPathInjectable from "./current-path.injectable"; 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<string>;
pathParameters: InferParamFromPath<string>;
}
const matchingRouteInjectable = getInjectable({ const matchingRouteInjectable = getInjectable({
id: "matching-route", id: "matching-route",
@ -16,21 +21,22 @@ const matchingRouteInjectable = getInjectable({
const routes = di.inject(routesInjectable); const routes = di.inject(routesInjectable);
const currentPath = di.inject(currentPathInjectable); const currentPath = di.inject(currentPathInjectable);
return computed(() => { return computed((): MatchedRoute | undefined => {
const matchedRoutes = routes.get().map((route) => { for (const route of routes.get()) {
const match = matchPath(currentPath.get(), { const match = matchPath(currentPath.get(), {
path: route.path, path: route.path,
exact: true, exact: true,
}); });
if (match) {
return { return {
route, route,
isMatching: !!match, pathParameters: match.params,
pathParameters: match ? match.params : {},
}; };
}); }
}
return matchedRoutes.find(matches({ isMatching: true })); return undefined;
}); });
}, },
}); });

Some files were not shown because too many files have changed in this diff Show More