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:
parent
74ba7ed782
commit
9ed5b9861a
@ -39,10 +39,6 @@ export class GeneralEntity extends CatalogEntity<CatalogEntityMetadata, CatalogE
|
|||||||
navigate(this.spec.path);
|
navigate(this.spec.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
onClickDetailIcon() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public onSettingsOpen(): void {
|
public onSettingsOpen(): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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) {
|
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
||||||
if (!this.metadata.source || this.metadata.source === "local") {
|
if (!this.metadata.source || this.metadata.source === "local") {
|
||||||
context.menuItems.push({
|
context.menuItems.push({
|
||||||
|
|||||||
@ -47,12 +47,6 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onClickDetailIcon(context: CatalogEntityActionContext) {
|
|
||||||
catalogCategoryRegistry
|
|
||||||
.getCategoryForEntity<WebLinkCategory>(this)
|
|
||||||
?.emit("onClickDetailIcon", this, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
||||||
if (this.metadata.source === "local") {
|
if (this.metadata.source === "local") {
|
||||||
context.menuItems.push({
|
context.menuItems.push({
|
||||||
|
|||||||
@ -59,7 +59,6 @@ export interface CatalogCategoryEvents {
|
|||||||
load: () => void;
|
load: () => void;
|
||||||
catalogAddMenu: (context: CatalogEntityAddMenuContext) => void;
|
catalogAddMenu: (context: CatalogEntityAddMenuContext) => void;
|
||||||
contextMenuOpen: (entity: CatalogEntity, context: CatalogEntityContextMenuContext) => void;
|
contextMenuOpen: (entity: CatalogEntity, context: CatalogEntityContextMenuContext) => void;
|
||||||
onClickDetailIcon: (entity: CatalogEntity, context: CatalogEntityActionContext) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class CatalogCategory extends (EventEmitter as new () => TypedEmitter<CatalogCategoryEvents>) {
|
export abstract class CatalogCategory extends (EventEmitter as new () => TypedEmitter<CatalogCategoryEvents>) {
|
||||||
@ -231,21 +230,7 @@ export abstract class CatalogEntity<
|
|||||||
return this.metadata.name;
|
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 onRun?(context: CatalogEntityActionContext): void | Promise<void>;
|
||||||
public abstract onContextMenuOpen(context: CatalogEntityContextMenuContext): 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>;
|
public abstract onSettingsOpen(context: CatalogEntitySettingsContext): void | Promise<void>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,10 +32,6 @@ class InvalidEntity extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public onClickDetailIcon(): void {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public onSettingsOpen(): void {
|
public onSettingsOpen(): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,84 +70,5 @@ describe("<CatalogEntityDetails />", () => {
|
|||||||
|
|
||||||
expect(onRun).toHaveBeenCalledTimes(1);
|
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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -69,15 +69,7 @@ export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Pro
|
|||||||
background={item.entity.spec.icon?.background}
|
background={item.entity.spec.icon?.background}
|
||||||
disabled={!item?.enabled}
|
disabled={!item?.enabled}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (typeof item.entity.onClickDetailIcon === "function") {
|
item.onRun(catalogEntityRunContext);
|
||||||
item.onClickDetailIcon(catalogEntityRunContext);
|
|
||||||
} else {
|
|
||||||
item.onRun(catalogEntityRunContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof item.entity.onClickDetailIcon === "function" && item.entity.spec?.triggerOnRunAfterOnClickDetailIcon) {
|
|
||||||
item.onRun(catalogEntityRunContext);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
size={128}
|
size={128}
|
||||||
data-testid="detail-panel-hot-bar-icon"
|
data-testid="detail-panel-hot-bar-icon"
|
||||||
|
|||||||
@ -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) {
|
onRun(ctx: CatalogEntityActionContext) {
|
||||||
this.entity.onRun(ctx);
|
this.entity.onRun(ctx);
|
||||||
}
|
}
|
||||||
@ -116,14 +110,4 @@ export class CatalogEntityItem<T extends CatalogEntity> implements ItemObject {
|
|||||||
async onContextMenuOpen(ctx: any) {
|
async onContextMenuOpen(ctx: any) {
|
||||||
return this.entity.onContextMenuOpen(ctx);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,64 +97,4 @@ describe("<Catalog />", () => {
|
|||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
jest.restoreAllMocks();
|
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],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
]
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user