mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Simplify dependencies for a component
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Mikko Aspiala <mikko.aspiala@houston-inc.com>
This commit is contained in:
parent
cfaf5f9402
commit
293cdb87ec
@ -37,16 +37,12 @@ import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus } from "../com
|
|||||||
import { disposer, storedKubeConfigFolder, toJS } from "../common/utils";
|
import { disposer, storedKubeConfigFolder, toJS } from "../common/utils";
|
||||||
import type { Response } from "request";
|
import type { Response } from "request";
|
||||||
|
|
||||||
export interface IHasName {
|
|
||||||
readonly name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cluster
|
* Cluster
|
||||||
*
|
*
|
||||||
* @beta
|
* @beta
|
||||||
*/
|
*/
|
||||||
export class Cluster implements ClusterModel, ClusterState, IHasName {
|
export class Cluster implements ClusterModel, ClusterState {
|
||||||
/** Unique id for a cluster */
|
/** Unique id for a cluster */
|
||||||
public readonly id: ClusterId;
|
public readonly id: ClusterId;
|
||||||
private kubeCtl: Kubectl;
|
private kubeCtl: Kubectl;
|
||||||
|
|||||||
@ -25,7 +25,8 @@ import { hideDetails } from "../../kube-detail-params";
|
|||||||
import { apiManager } from "../../../../common/k8s-api/api-manager";
|
import { apiManager } from "../../../../common/k8s-api/api-manager";
|
||||||
import { KubeObjectMenuRegistry } from "../../../../extensions/registries";
|
import { KubeObjectMenuRegistry } from "../../../../extensions/registries";
|
||||||
import { getActiveClusterEntity } from "../../../api/catalog-entity-registry";
|
import { getActiveClusterEntity } from "../../../api/catalog-entity-registry";
|
||||||
|
import type { KubeObjectMenuDependencies } from "../kube-object-menu";
|
||||||
|
import type { KubeObject } from "../../../../common/k8s-api/kube-object";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
Component: React.ReactType<any>
|
Component: React.ReactType<any>
|
||||||
@ -36,12 +37,12 @@ export const InjectNaive = ({ Component, ...props }: Props) => {
|
|||||||
const kubeObjectMenuRegistry = KubeObjectMenuRegistry.getInstance();
|
const kubeObjectMenuRegistry = KubeObjectMenuRegistry.getInstance();
|
||||||
const cluster = getActiveClusterEntity();
|
const cluster = getActiveClusterEntity();
|
||||||
|
|
||||||
const dependencies = {
|
const dependencies: KubeObjectMenuDependencies<KubeObject> = {
|
||||||
|
clusterName: cluster.name,
|
||||||
editResourceTab,
|
editResourceTab,
|
||||||
hideDetails,
|
hideDetails,
|
||||||
apiManager,
|
apiManager,
|
||||||
kubeObjectMenuRegistry,
|
kubeObjectMenuRegistry,
|
||||||
cluster,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -32,7 +32,6 @@ import type {
|
|||||||
} from "../../../extensions/registries";
|
} from "../../../extensions/registries";
|
||||||
import type { IGettableStore } from "../../../common/k8s-api/api-manager";
|
import type { IGettableStore } from "../../../common/k8s-api/api-manager";
|
||||||
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||||
import type { IHasName } from "../../../main/cluster";
|
|
||||||
import { ConfirmDialog } from "../confirm-dialog";
|
import { ConfirmDialog } from "../confirm-dialog";
|
||||||
import asyncFn from "@async-fn/jest";
|
import asyncFn from "@async-fn/jest";
|
||||||
|
|
||||||
@ -40,7 +39,6 @@ describe("kube-object-menu", () => {
|
|||||||
let hideDetailsStub: () => void;
|
let hideDetailsStub: () => void;
|
||||||
let editResourceTabStub: () => void;
|
let editResourceTabStub: () => void;
|
||||||
let apiManagerStub: IGettableStore;
|
let apiManagerStub: IGettableStore;
|
||||||
let clusterStub: IHasName;
|
|
||||||
let kubeObjectMenuRegistryStub: IHasGettableItemsForKind;
|
let kubeObjectMenuRegistryStub: IHasGettableItemsForKind;
|
||||||
let objectStub: KubeObject | null;
|
let objectStub: KubeObject | null;
|
||||||
let dependencies: KubeObjectMenuDependencies<KubeObject>;
|
let dependencies: KubeObjectMenuDependencies<KubeObject>;
|
||||||
@ -63,8 +61,6 @@ describe("kube-object-menu", () => {
|
|||||||
): TKubeObjectStore | undefined => undefined,
|
): TKubeObjectStore | undefined => undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
clusterStub = { name: "Some cluster name" };
|
|
||||||
|
|
||||||
const MenuItemComponentStub: React.FC = () => <div>Some menu item</div>;
|
const MenuItemComponentStub: React.FC = () => <div>Some menu item</div>;
|
||||||
|
|
||||||
const dynamicMenuItemStub: KubeObjectMenuRegistration = {
|
const dynamicMenuItemStub: KubeObjectMenuRegistration = {
|
||||||
@ -85,8 +81,8 @@ describe("kube-object-menu", () => {
|
|||||||
editResourceTabStub = () => {};
|
editResourceTabStub = () => {};
|
||||||
|
|
||||||
dependencies = {
|
dependencies = {
|
||||||
|
clusterName: "Some cluster name",
|
||||||
apiManager: apiManagerStub,
|
apiManager: apiManagerStub,
|
||||||
cluster: clusterStub,
|
|
||||||
kubeObjectMenuRegistry: kubeObjectMenuRegistryStub,
|
kubeObjectMenuRegistry: kubeObjectMenuRegistryStub,
|
||||||
hideDetails: hideDetailsStub,
|
hideDetails: hideDetailsStub,
|
||||||
editResourceTab: editResourceTabStub,
|
editResourceTab: editResourceTabStub,
|
||||||
|
|||||||
@ -27,12 +27,11 @@ import identity from "lodash/identity";
|
|||||||
|
|
||||||
import type { IHasGettableItemsForKind } from "../../../extensions/registries";
|
import type { IHasGettableItemsForKind } from "../../../extensions/registries";
|
||||||
import type { IGettableStore } from "../../../common/k8s-api/api-manager";
|
import type { IGettableStore } from "../../../common/k8s-api/api-manager";
|
||||||
import type { IHasName } from "../../../main/cluster";
|
|
||||||
|
|
||||||
export interface KubeObjectMenuDependencies<TKubeObject>{
|
export interface KubeObjectMenuDependencies<TKubeObject>{
|
||||||
apiManager: IGettableStore;
|
apiManager: IGettableStore;
|
||||||
kubeObjectMenuRegistry: IHasGettableItemsForKind;
|
kubeObjectMenuRegistry: IHasGettableItemsForKind;
|
||||||
cluster: IHasName;
|
clusterName: string,
|
||||||
hideDetails: () => void;
|
hideDetails: () => void;
|
||||||
editResourceTab: (kubeObject: TKubeObject) => void;
|
editResourceTab: (kubeObject: TKubeObject) => void;
|
||||||
}
|
}
|
||||||
@ -93,7 +92,7 @@ export class KubeObjectMenu<
|
|||||||
}
|
}
|
||||||
|
|
||||||
const breadcrumbParts = [
|
const breadcrumbParts = [
|
||||||
this.dependencies.cluster?.name,
|
this.dependencies.clusterName,
|
||||||
object.getNs(),
|
object.getNs(),
|
||||||
object.kind,
|
object.kind,
|
||||||
object.getName(),
|
object.getName(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user