mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactor cluster modals registrator and injectable
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
adcdc58290
commit
8d3a61d9d1
@ -14,3 +14,4 @@ export type { CustomCategoryViewProps, CustomCategoryViewComponents, CustomCateg
|
|||||||
export type { ShellEnvModifier, ShellEnvContext } from "../../main/shell-session/shell-env-modifier/shell-env-modifier-registration";
|
export type { ShellEnvModifier, ShellEnvContext } from "../../main/shell-session/shell-env-modifier/shell-env-modifier-registration";
|
||||||
export type { KubeObjectContextMenuItem, KubeObjectOnContextMenuOpenContext, KubeObjectOnContextMenuOpen, KubeObjectHandlers, KubeObjectHandlerRegistration } from "../../renderer/kube-object/handler";
|
export type { KubeObjectContextMenuItem, KubeObjectOnContextMenuOpenContext, KubeObjectOnContextMenuOpen, KubeObjectHandlers, KubeObjectHandlerRegistration } from "../../renderer/kube-object/handler";
|
||||||
export type { TrayMenuRegistration } from "../../main/tray/tray-menu-registration";
|
export type { TrayMenuRegistration } from "../../main/tray/tray-menu-registration";
|
||||||
|
export type { ClusterModalRegistration } from "../registries/modal-registry";
|
||||||
|
|||||||
@ -12,4 +12,3 @@ export interface ClusterModalRegistration {
|
|||||||
Component: React.ComponentType;
|
Component: React.ComponentType;
|
||||||
visible: IComputedValue<boolean>;
|
visible: IComputedValue<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
import type { Injectable } from "@ogre-tools/injectable";
|
import type { Injectable } from "@ogre-tools/injectable";
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { RenderResult } from "@testing-library/react";
|
import type { RenderResult } from "@testing-library/react";
|
||||||
import type { IComputedValue, IObservableValue } from "mobx";
|
import type { IObservableValue } from "mobx";
|
||||||
import { computed, observable, runInAction } from "mobx";
|
import { computed, observable, runInAction } from "mobx";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import type { ClusterModalRegistration } from "../../extensions/registries";
|
import type { ClusterModalRegistration } from "../../extensions/registries";
|
||||||
@ -24,8 +24,8 @@ describe("<body/> elements originated from cluster modal registration", () => {
|
|||||||
|
|
||||||
describe("given custom components for cluster view available", () => {
|
describe("given custom components for cluster view available", () => {
|
||||||
let someObservable: IObservableValue<boolean>;
|
let someObservable: IObservableValue<boolean>;
|
||||||
let clusterModalInjectable: Injectable<IComputedValue<ClusterModalRegistration[]>, any, any>;
|
let clusterModalInjectable: Injectable<ClusterModalRegistration, any, any>;
|
||||||
let clusterDialogInjectable: Injectable<IComputedValue<ClusterModalRegistration[]>, any, any>;
|
let clusterDialogInjectable: Injectable<ClusterModalRegistration, any, any>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
someObservable = observable.box(false);
|
someObservable = observable.box(false);
|
||||||
@ -34,11 +34,11 @@ describe("<body/> elements originated from cluster modal registration", () => {
|
|||||||
id: "some-cluster-modal-injectable",
|
id: "some-cluster-modal-injectable",
|
||||||
|
|
||||||
instantiate: () => {
|
instantiate: () => {
|
||||||
return computed((): ClusterModalRegistration[] => [{
|
return {
|
||||||
id: "test-modal-id",
|
id: "test-modal-id",
|
||||||
Component: () => <div data-testid="test-modal">test modal</div>,
|
Component: () => <div data-testid="test-modal">test modal</div>,
|
||||||
visible: computed(() => true),
|
visible: computed(() => true),
|
||||||
}]);
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
injectionToken: clusterModalsInjectionToken,
|
injectionToken: clusterModalsInjectionToken,
|
||||||
@ -48,11 +48,11 @@ describe("<body/> elements originated from cluster modal registration", () => {
|
|||||||
id: "dialog-with-observable-visibility-injectable",
|
id: "dialog-with-observable-visibility-injectable",
|
||||||
|
|
||||||
instantiate: () => {
|
instantiate: () => {
|
||||||
return computed((): ClusterModalRegistration[] => [{
|
return {
|
||||||
id: "dialog-with-observable-visibility-id",
|
id: "dialog-with-observable-visibility-id",
|
||||||
Component: () => <div data-testid="dialog-with-observable-visibility">dialog contents</div>,
|
Component: () => <div data-testid="dialog-with-observable-visibility">dialog contents</div>,
|
||||||
visible: computed(() => someObservable.get()),
|
visible: computed(() => someObservable.get()),
|
||||||
}]);
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
injectionToken: clusterModalsInjectionToken,
|
injectionToken: clusterModalsInjectionToken,
|
||||||
|
|||||||
@ -4,9 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type { IComputedValue } from "mobx";
|
|
||||||
import type { ClusterModalRegistration } from "../../extensions/registries";
|
import type { ClusterModalRegistration } from "../../extensions/registries";
|
||||||
|
|
||||||
export const clusterModalsInjectionToken = getInjectionToken<
|
export const clusterModalsInjectionToken = getInjectionToken<
|
||||||
IComputedValue<ClusterModalRegistration[]>
|
ClusterModalRegistration
|
||||||
>({ id: "cluster-modals-injection-token" });
|
>({ id: "cluster-modals-injection-token" });
|
||||||
|
|||||||
@ -2,28 +2,35 @@
|
|||||||
* 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 { pipeline } from "@ogre-tools/fp";
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type { ExtensionRegistrator } from "../../extensions/extension-loader/extension-registrator-injection-token";
|
import { map } from "lodash/fp";
|
||||||
import { extensionRegistratorInjectionToken } from "../../extensions/extension-loader/extension-registrator-injection-token";
|
import { extensionRegistratorInjectionToken } from "../../extensions/extension-loader/extension-registrator-injection-token";
|
||||||
import type { LensRendererExtension } from "../../extensions/lens-renderer-extension";
|
import type { LensRendererExtension } from "../../extensions/lens-renderer-extension";
|
||||||
|
import { clusterModalsInjectionToken } from "./cluster-modals-injection-token";
|
||||||
|
|
||||||
const clusterModalsRegistratorInjectable = getInjectable({
|
const clusterModalsRegistratorInjectable = getInjectable({
|
||||||
id: "cluster-modals-registrator",
|
id: "cluster-modals-registrator",
|
||||||
|
|
||||||
instantiate: (): ExtensionRegistrator => {
|
instantiate: (di) => {
|
||||||
return (ext) => {
|
return (ext) => {
|
||||||
const extension = ext as LensRendererExtension;
|
const extension = ext as LensRendererExtension;
|
||||||
|
|
||||||
return extension.clusterModals.map(registration => {
|
return pipeline(
|
||||||
return getInjectable({
|
extension.clusterModals,
|
||||||
id: registration.id,
|
|
||||||
|
|
||||||
instantiate: () => ({
|
map((modal) => {
|
||||||
Component: registration.Component,
|
return getInjectable({
|
||||||
visible: registration.visible,
|
id: modal.id,
|
||||||
}),
|
injectionToken: clusterModalsInjectionToken,
|
||||||
});
|
instantiate: () => ({
|
||||||
});
|
id: `${modal.id}-id`,
|
||||||
|
visible: modal.visible,
|
||||||
|
Component: modal.Component
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
injectionToken: extensionRegistratorInjectionToken,
|
injectionToken: extensionRegistratorInjectionToken,
|
||||||
|
|||||||
@ -2,12 +2,8 @@
|
|||||||
* 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 { pipeline } from "@ogre-tools/fp";
|
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||||
import { flatMap } from "lodash/fp";
|
|
||||||
import type { IComputedValue } from "mobx";
|
|
||||||
import type { ClusterModalRegistration } from "../../extensions/registries";
|
|
||||||
import { clusterModalsInjectionToken } from "./cluster-modals-injection-token";
|
import { clusterModalsInjectionToken } from "./cluster-modals-injection-token";
|
||||||
|
|
||||||
const clusterModalsInjectable = getInjectable({
|
const clusterModalsInjectable = getInjectable({
|
||||||
@ -15,18 +11,10 @@ const clusterModalsInjectable = getInjectable({
|
|||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||||
|
|
||||||
const modalRegistrations = computedInjectMany(clusterModalsInjectionToken);
|
const modalRegistrations = computedInjectMany(clusterModalsInjectionToken);
|
||||||
const registrations = pipeline(
|
|
||||||
modalRegistrations.get(),
|
return modalRegistrations;
|
||||||
flatMap(dereference),
|
|
||||||
);
|
|
||||||
|
|
||||||
return registrations;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const dereference = (items: IComputedValue<ClusterModalRegistration[]>) =>
|
|
||||||
items.get();
|
|
||||||
|
|
||||||
export default clusterModalsInjectable;
|
export default clusterModalsInjectable;
|
||||||
|
|||||||
@ -9,15 +9,16 @@ import React from "react";
|
|||||||
import type { ClusterModalRegistration } from "../../extensions/registries";
|
import type { ClusterModalRegistration } from "../../extensions/registries";
|
||||||
import clusterModalsInjectable from "./cluster-modals.injectable";
|
import clusterModalsInjectable from "./cluster-modals.injectable";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
|
import type { IComputedValue } from "mobx";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
clusterModals: ClusterModalRegistration[];
|
clusterModals: IComputedValue<ClusterModalRegistration[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const NonInjectedClusterModals = observer(({ clusterModals }: Dependencies) => {
|
export const NonInjectedClusterModals = observer(({ clusterModals }: Dependencies) => {
|
||||||
return (
|
return (
|
||||||
<div className={styles.clusterModals} style={{ height: 0 }}>
|
<div className={styles.clusterModals} style={{ height: 0 }}>
|
||||||
{clusterModals.map((modal) => {
|
{clusterModals.get().map((modal) => {
|
||||||
return modal.visible.get() ? <modal.Component key={modal.id} /> : null;
|
return modal.visible.get() ? <modal.Component key={modal.id} /> : null;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user