Demonstrate even step further to have an interface as dependency instead of concrete instance

Signed-off-by: Janne Savolainen <janne.savolainen@houston-inc.com>
This commit is contained in:
Janne Savolainen authored and Janne Savolainen committed 2021-12-04 12:16:33 +02:00
1 parent 91b14ee3fc
commit 29d0634729
2 files changed
+18 -10

No files matched your search

@@ -32,10 +32,13 @@ export interface KubeObjectMenuRegistration {
components: KubeObjectMenuComponents;
}
export class KubeObjectMenuRegistry extends BaseRegistry<KubeObjectMenuRegistration> {
getItemsForKind(kind: string, apiVersion: string) {
return this.getItems().filter((item) => {
return item.kind === kind && item.apiVersions.includes(apiVersion);
});
}
export interface IHasGettableItemsForKind {
getItemsForKind(kind: string, apiVersion: string): any;
}
export class KubeObjectMenuRegistry extends BaseRegistry<KubeObjectMenuRegistration> implements IHasGettableItemsForKind {
getItemsForKind = (kind: string, apiVersion: string) =>
this.getItems().filter((item) =>
item.kind === kind && item.apiVersions.includes(apiVersion),
);
}
@@ -25,7 +25,10 @@ import type { KubeObject } from "../../../common/k8s-api/kube-object";
import { MenuActions, MenuActionsProps } from "../menu/menu-actions";
import identity from "lodash/identity";
import type { KubeObjectMenuRegistry } from "../../../extensions/registries";
import type {
IHasGettableItemsForKind,
} from "../../../extensions/registries";
import type { CatalogEntityRegistry } from "../../api/catalog-entity-registry";
import type { IGettableStore } from "../../../common/k8s-api/api-manager";
@@ -38,10 +41,10 @@ export interface KubeObjectMenuProps<T> extends MenuActionsProps {
interface KubeObjectMenuDependencies<T> extends KubeObjectMenuProps<T>{
apiManager: IGettableStore,
kubeObjectMenuRegistry: IHasGettableItemsForKind
hideDetails: Function,
editResourceTab: Function,
catalogEntityRegistry: CatalogEntityRegistry,
kubeObjectMenuRegistry: KubeObjectMenuRegistry
}
export class KubeObjectMenu<T extends KubeObject> extends React.Component<KubeObjectMenuDependencies<T>> {
@@ -125,11 +128,13 @@ export class KubeObjectMenu<T extends KubeObject> extends React.Component<KubeOb
return this.dependencies.kubeObjectMenuRegistry
.getItemsForKind(object.kind, object.apiVersion)
.map(({ components: { MenuItem }}, index) => (
.map(({ components: { MenuItem }}: { components: { MenuItem: React.ReactType<any> }}, index: number) => (
<MenuItem
object={object}
key={`menu-item-${index}`}
toolbar={toolbar}
// TODO: Fix misuse of index in key
key={`menu-item-${index}`}
/>
));
}