From 9ed5b9861a8ebde4d2821c4a1c515845146f63b7 Mon Sep 17 00:00:00 2001 From: "Hung-Han (Henry) Chen" Date: Mon, 4 Oct 2021 08:53:57 +0300 Subject: [PATCH] Remove onClickDetailIcon Signed-off-by: Hung-Han (Henry) Chen --- src/common/catalog-entities/general.ts | 4 - .../catalog-entities/kubernetes-cluster.ts | 6 -- src/common/catalog-entities/web-link.ts | 6 -- src/common/catalog/catalog-entity.ts | 15 ---- .../__tests__/catalog-entity-registry.test.ts | 4 - .../+catalog/catalog-entity-details.test.tsx | 79 ------------------- .../+catalog/catalog-entity-details.tsx | 10 +-- .../+catalog/catalog-entity-item.tsx | 16 ---- .../components/+catalog/catalog.test.tsx | 60 -------------- 9 files changed, 1 insertion(+), 199 deletions(-) diff --git a/src/common/catalog-entities/general.ts b/src/common/catalog-entities/general.ts index 4e856f0eae..5d13eeabee 100644 --- a/src/common/catalog-entities/general.ts +++ b/src/common/catalog-entities/general.ts @@ -39,10 +39,6 @@ export class GeneralEntity extends CatalogEntity(this) - ?.emit("onClickDetailIcon", this, context); - } - async onContextMenuOpen(context: CatalogEntityContextMenuContext) { if (!this.metadata.source || this.metadata.source === "local") { context.menuItems.push({ diff --git a/src/common/catalog-entities/web-link.ts b/src/common/catalog-entities/web-link.ts index 76afac41e9..9d35cc5501 100644 --- a/src/common/catalog-entities/web-link.ts +++ b/src/common/catalog-entities/web-link.ts @@ -47,12 +47,6 @@ export class WebLink extends CatalogEntity(this) - ?.emit("onClickDetailIcon", this, context); - } - async onContextMenuOpen(context: CatalogEntityContextMenuContext) { if (this.metadata.source === "local") { context.menuItems.push({ diff --git a/src/common/catalog/catalog-entity.ts b/src/common/catalog/catalog-entity.ts index 877a46eb8f..d59a21686c 100644 --- a/src/common/catalog/catalog-entity.ts +++ b/src/common/catalog/catalog-entity.ts @@ -59,7 +59,6 @@ export interface CatalogCategoryEvents { load: () => void; catalogAddMenu: (context: CatalogEntityAddMenuContext) => void; contextMenuOpen: (entity: CatalogEntity, context: CatalogEntityContextMenuContext) => void; - onClickDetailIcon: (entity: CatalogEntity, context: CatalogEntityActionContext) => void; } export abstract class CatalogCategory extends (EventEmitter as new () => TypedEmitter) { @@ -231,21 +230,7 @@ export abstract class CatalogEntity< return this.metadata.name; } - /** - * Trigger when user click on the icon in details panel - * - * @remarks - * Priority < this.onClickDetailIcon, if this.onClickDetailIcon presents, onRun won't be called. - */ public abstract onRun?(context: CatalogEntityActionContext): void | Promise; public abstract onContextMenuOpen(context: CatalogEntityContextMenuContext): void | Promise; - - /** - * Trigger when user click on the icon in details panel - * - * @remarks - * Priority > this.onRun, if presents, onRun won't be called. - */ - public abstract onClickDetailIcon?(context: CatalogEntityActionContext): void; public abstract onSettingsOpen(context: CatalogEntitySettingsContext): void | Promise; } diff --git a/src/main/catalog/__tests__/catalog-entity-registry.test.ts b/src/main/catalog/__tests__/catalog-entity-registry.test.ts index 1fbcd819ed..ee8450ae26 100644 --- a/src/main/catalog/__tests__/catalog-entity-registry.test.ts +++ b/src/main/catalog/__tests__/catalog-entity-registry.test.ts @@ -32,10 +32,6 @@ class InvalidEntity extends CatalogEntity", () => { expect(onRun).toHaveBeenCalledTimes(1); }); - - it("prioritize onClickDetailIcon over onRun", () => { - const onRun = jest.fn(); - const onClickDetailIcon = jest.fn(); - - const item = new CatalogEntityItem({ - enabled: true, - apiVersion: "", - kind: "", - metadata: { - uid: "", - name: "", - labels: {}, - }, - status: { - phase: "", - }, - spec: {}, - getId: () => "", - getName: () => "", - onContextMenuOpen: () => {}, - onSettingsOpen: () => {}, - onRun, - onClickDetailIcon, - }); - - render( - {}} - /> - ); - - userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon")); - - expect(onRun).toHaveBeenCalledTimes(0); - expect(onClickDetailIcon).toHaveBeenCalledTimes(1); - }); - - - it("prioritize onClickDetailIcon over onRun, but always trigger onRun if triggerOnRunAfterOnClickDetailIcon='true'", () => { - const onRun = jest.fn(); - const onClickDetailIcon = jest.fn(); - - const item = new CatalogEntityItem({ - enabled: true, - apiVersion: "", - kind: "", - metadata: { - uid: "", - name: "", - labels: {}, - }, - status: { - phase: "", - }, - spec: { - triggerOnRunAfterOnClickDetailIcon: true - }, - getId: () => "", - getName: () => "", - onContextMenuOpen: () => {}, - onSettingsOpen: () => {}, - onRun, - onClickDetailIcon, - }); - - render( - {}} - /> - ); - - userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon")); - - expect(onClickDetailIcon).toHaveBeenCalledTimes(1); - expect(onRun).toHaveBeenCalledTimes(1); - }); }); diff --git a/src/renderer/components/+catalog/catalog-entity-details.tsx b/src/renderer/components/+catalog/catalog-entity-details.tsx index e333fedb7a..df4928b0be 100644 --- a/src/renderer/components/+catalog/catalog-entity-details.tsx +++ b/src/renderer/components/+catalog/catalog-entity-details.tsx @@ -69,15 +69,7 @@ export class CatalogEntityDetails extends Component { - if (typeof item.entity.onClickDetailIcon === "function") { - item.onClickDetailIcon(catalogEntityRunContext); - } else { - item.onRun(catalogEntityRunContext); - } - - if (typeof item.entity.onClickDetailIcon === "function" && item.entity.spec?.triggerOnRunAfterOnClickDetailIcon) { - item.onRun(catalogEntityRunContext); - } + item.onRun(catalogEntityRunContext); }} size={128} data-testid="detail-panel-hot-bar-icon" diff --git a/src/renderer/components/+catalog/catalog-entity-item.tsx b/src/renderer/components/+catalog/catalog-entity-item.tsx index 22fc290ef6..5ed01aded6 100644 --- a/src/renderer/components/+catalog/catalog-entity-item.tsx +++ b/src/renderer/components/+catalog/catalog-entity-item.tsx @@ -102,12 +102,6 @@ export class CatalogEntityItem implements ItemObject { ]; } - /** - * Trigger when user click on the icon in details panel - * - * @remarks - * Priority < this.onClickDetailIcon, if this.onClickDetailIcon presents, onRun won't be called. - */ onRun(ctx: CatalogEntityActionContext) { this.entity.onRun(ctx); } @@ -116,14 +110,4 @@ export class CatalogEntityItem implements ItemObject { async onContextMenuOpen(ctx: any) { return this.entity.onContextMenuOpen(ctx); } - - /** - * Trigger when user click on the icon in details panel - * - * @remarks - * Priority > this.onRun, if presents, onRun won't be called. - */ - onClickDetailIcon(ctx: CatalogEntityActionContext) { - this.entity.onClickDetailIcon?.(ctx); - } } diff --git a/src/renderer/components/+catalog/catalog.test.tsx b/src/renderer/components/+catalog/catalog.test.tsx index c19a066327..2bbafcfc9d 100644 --- a/src/renderer/components/+catalog/catalog.test.tsx +++ b/src/renderer/components/+catalog/catalog.test.tsx @@ -97,64 +97,4 @@ describe("", () => { afterAll(() => { jest.restoreAllMocks(); }); - - it("category.emit('onClickDetailIcon') when clicking on the icon in detail panel", () => { - const history = createMemoryHistory(); - const mockLocation = { - pathname: "", - search: "", - state: "", - hash: "", - }; - const mockMatch = { - params: {}, - isExact: true, - path: "", - url: "", - }; - - render( - - ); - - const emit = jest.spyOn(kubernetesClusterCategory, "emit"); - - userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon")); - - expect(emit).toHaveBeenCalledTimes(1); - expect(emit.mock.calls).toMatchInlineSnapshot(` - Array [ - Array [ - "onClickDetailIcon", - KubernetesCluster { - "apiVersion": "entity.k8slens.dev/v1alpha1", - "kind": "KubernetesCluster", - "metadata": Object { - "distro": "", - "kubeVersion": "", - "labels": Object {}, - "name": "", - "source": "", - "uid": "", - }, - "spec": Object { - "icon": Object {}, - "kubeconfigContext": "", - "kubeconfigPath": "", - }, - "status": Object { - "active": false, - "message": "", - "phase": "disconnected", - "reason": "", - }, - }, - Object { - "navigate": [Function], - "setCommandPaletteContext": [Function], - }, - ], - ] - `); - }); });