Skip to content

Commit

Permalink
fix: add click trigger
Browse files Browse the repository at this point in the history
Signed-off-by: codeSafari10 <[email protected]>
  • Loading branch information
codeSafari10 committed Sep 14, 2024
1 parent fe9faf1 commit 4a019a1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/custom/permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface HasKeyProps<ReasonEvent> {
Key?: Key;
predicate?: (capabilitiesRegistry: unknown) => [boolean, ReasonEvent]; // returns a boolean and an event if the user does not have the permission
children: React.ReactNode;
allowClick?: boolean;
notifyOnclick?: boolean;
invert_action?: InvertAction[];
}

Expand All @@ -40,7 +40,13 @@ export const createCanShow = (
CAN: (action: string, subject: string) => boolean,
eventBus: () => EventBus<ReasonEvent>
) => {
return ({ Key, children, predicate, invert_action = ['disable'] }: HasKeyProps<ReasonEvent>) => {
return ({
Key,
children,
notifyOnclick = true,
predicate,
invert_action = ['disable']
}: HasKeyProps<ReasonEvent>) => {
if (!children) {
return null;
}
Expand All @@ -65,11 +71,12 @@ export const createCanShow = (
return null;
}

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

const onClick = isClickable
? () => {
const onClick = notifyOnclick
? (e: React.MouseEvent<HTMLDivElement | HTMLElement>) => {
e.stopPropagation();
console.log('cant perform action : reason', reason, eventBus);
const mesheryEventBus = eventBus();
mesheryEventBus.publish(reason);
Expand All @@ -85,6 +92,7 @@ export const createCanShow = (
pointerEvents,
opacity: opacity
}}
onClick={onClick}
>
{React.cloneElement(children as React.ReactElement, {
style: {
Expand Down

0 comments on commit 4a019a1

Please sign in to comment.