Add triggerOnRunAfterOnClickDetailIcon

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen committed 2021-10-04 08:50:39 +03:00
1 parent b9c485d0af
commit aed5760ba0
5 files changed
+50 -2

No files matched your search

+3 -1
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
+1
View File
@@ -261,6 +261,7 @@ export function catalogEntityFromCluster(cluster: Cluster) {
name: cluster.name,
source: "local",
labels: {
triggerOnRunAfterOnClickDetailIcon: "true",
...cluster.labels,
},
distro: cluster.distribution,
@@ -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);
});
});
@@ -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"
@@ -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;