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

Add triggerOnRunAfterOnClickDetailIcon

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen 2021-09-29 16:04:41 +03:00
parent b9c485d0af
commit aed5760ba0
No known key found for this signature in database
GPG Key ID: 54B44603D251B788
5 changed files with 50 additions and 2 deletions

View File

@ -75,7 +75,9 @@ export function syncWeblinks() {
uid: weblinkData.id,
name: weblinkData.name,
source: "local",
labels: {}
labels: {
triggerOnRunAfterOnClickDetailIcon: "true",
}
},
spec: {
url: weblinkData.url

View File

@ -261,6 +261,7 @@ export function catalogEntityFromCluster(cluster: Cluster) {
name: cluster.name,
source: "local",
labels: {
triggerOnRunAfterOnClickDetailIcon: "true",
...cluster.labels,
},
distro: cluster.distribution,

View File

@ -108,5 +108,46 @@ describe("<CatalogEntityDetails />", () => {
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: {
triggerOnRunAfterOnClickDetailIcon: "true",
},
},
status: {
phase: "",
},
spec: { },
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

@ -74,6 +74,10 @@ export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Pro
} else {
item.onRun(catalogEntityRunContext);
}
if (typeof item.entity.onClickDetailIcon === "function" && Boolean(item.entity.metadata?.labels?.triggerOnRunAfterOnClickDetailIcon)) {
item.onRun(catalogEntityRunContext);
}
}}
size={128}
data-testid="detail-panel-hot-bar-icon"

View File

@ -30,7 +30,7 @@ import { MenuItem } from "../menu";
import { ConfirmDialog } from "../confirm-dialog";
import { HotbarStore } from "../../../common/hotbar-store";
import { Icon } from "../icon";
import type { CatalogEntityItem } from "./catalog-entity.store";
import type { CatalogEntityItem } from "./catalog-entity-item";
export interface CatalogEntityDrawerMenuProps<T extends CatalogEntity> extends MenuActionsProps {
item: CatalogEntityItem<T> | null | undefined;