Skip to content

Commit 4a019a1

Browse files
committed
fix: add click trigger
Signed-off-by: codeSafari10 <[email protected]>
1 parent fe9faf1 commit 4a019a1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/custom/permissions.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface HasKeyProps<ReasonEvent> {
2929
Key?: Key;
3030
predicate?: (capabilitiesRegistry: unknown) => [boolean, ReasonEvent]; // returns a boolean and an event if the user does not have the permission
3131
children: React.ReactNode;
32-
allowClick?: boolean;
32+
notifyOnclick?: boolean;
3333
invert_action?: InvertAction[];
3434
}
3535

@@ -40,7 +40,13 @@ export const createCanShow = (
4040
CAN: (action: string, subject: string) => boolean,
4141
eventBus: () => EventBus<ReasonEvent>
4242
) => {
43-
return ({ Key, children, predicate, invert_action = ['disable'] }: HasKeyProps<ReasonEvent>) => {
43+
return ({
44+
Key,
45+
children,
46+
notifyOnclick = true,
47+
predicate,
48+
invert_action = ['disable']
49+
}: HasKeyProps<ReasonEvent>) => {
4450
if (!children) {
4551
return null;
4652
}
@@ -65,11 +71,12 @@ export const createCanShow = (
6571
return null;
6672
}
6773

68-
const isClickable = children && (children as React.ReactElement).props.onClick;
69-
const pointerEvents = isClickable ? 'auto' : 'none';
74+
const pointerEvents = notifyOnclick ? 'auto' : 'none';
75+
console.log('cant perform action ', reason, eventBus);
7076

71-
const onClick = isClickable
72-
? () => {
77+
const onClick = notifyOnclick
78+
? (e: React.MouseEvent<HTMLDivElement | HTMLElement>) => {
79+
e.stopPropagation();
7380
console.log('cant perform action : reason', reason, eventBus);
7481
const mesheryEventBus = eventBus();
7582
mesheryEventBus.publish(reason);
@@ -85,6 +92,7 @@ export const createCanShow = (
8592
pointerEvents,
8693
opacity: opacity
8794
}}
95+
onClick={onClick}
8896
>
8997
{React.cloneElement(children as React.ReactElement, {
9098
style: {

0 commit comments

Comments
 (0)