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

Remove onClickDetailIcon

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen 2021-10-04 08:53:57 +03:00
parent 74ba7ed782
commit 9ed5b9861a
No known key found for this signature in database
GPG Key ID: 54B44603D251B788
9 changed files with 1 additions and 199 deletions

View File

@ -39,10 +39,6 @@ export class GeneralEntity extends CatalogEntity<CatalogEntityMetadata, CatalogE
navigate(this.spec.path);
}
onClickDetailIcon() {
return;
}
public onSettingsOpen(): void {
return;
}

View File

@ -101,12 +101,6 @@ export class KubernetesCluster extends CatalogEntity<KubernetesClusterMetadata,
//
}
onClickDetailIcon(context: CatalogEntityActionContext) {
catalogCategoryRegistry
.getCategoryForEntity<KubernetesClusterCategory>(this)
?.emit("onClickDetailIcon", this, context);
}
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
if (!this.metadata.source || this.metadata.source === "local") {
context.menuItems.push({

View File

@ -47,12 +47,6 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
return;
}
onClickDetailIcon(context: CatalogEntityActionContext) {
catalogCategoryRegistry
.getCategoryForEntity<WebLinkCategory>(this)
?.emit("onClickDetailIcon", this, context);
}
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
if (this.metadata.source === "local") {
context.menuItems.push({

View File

@ -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<CatalogCategoryEvents>) {
@ -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<void>;
public abstract onContextMenuOpen(context: CatalogEntityContextMenuContext): void | Promise<void>;
/**
* 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<void>;
}

View File

@ -32,10 +32,6 @@ class InvalidEntity extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
return;
}
public onClickDetailIcon(): void {
return;
}
public onSettingsOpen(): void {
return;
}

View File

@ -70,84 +70,5 @@ describe("<CatalogEntityDetails />", () => {
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(
<CatalogEntityDetails
item={item}
hideDetails={() => {}}
/>
);
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(
<CatalogEntityDetails
item={item}
hideDetails={() => {}}
/>
);
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
expect(onClickDetailIcon).toHaveBeenCalledTimes(1);
expect(onRun).toHaveBeenCalledTimes(1);
});
});

View File

@ -69,15 +69,7 @@ export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Pro
background={item.entity.spec.icon?.background}
disabled={!item?.enabled}
onClick={() => {
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"

View File

@ -102,12 +102,6 @@ export class CatalogEntityItem<T extends CatalogEntity> 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<T extends CatalogEntity> 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);
}
}

View File

@ -97,64 +97,4 @@ describe("<Catalog />", () => {
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(
<Catalog history={history} location={mockLocation} match={mockMatch} />
);
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],
},
],
]
`);
});
});