Skip to content

fix(core): pass meta to useCan params #6826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/great-birds-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/core": major
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@refinedev/core": major
"@refinedev/core": patch

---

fix: pass meta params to useCan hook params

Now access control provider can receive additional arguments through meta params.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ButtonCanAccessProps = {
enabled?: boolean;
hideIfUnauthorized?: boolean;
};
meta?: Record<string, unknown>;
};

type ButtonCanAccessValues = {
Expand All @@ -43,7 +44,7 @@ export const useButtonCanAccess = (
const { data: canAccess } = useCan({
resource: props.resource?.name,
action: props.action === "clone" ? "create" : props.action,
params: { id: props.id, resource: props.resource },
params: { ...props.meta, id: props.id, resource: props.resource },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pass this like this:

Suggested change
params: { ...props.meta, id: props.id, resource: props.resource },
params: { meta: { ...props.meta }, id: props.id, resource: props.resource },

I believe we can manage better with this way

queryOptions: {
enabled: accessControlEnabled,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function useNavigationButton(
const { canAccess, title, hidden, disabled } = useButtonCanAccess({
action: props.action,
accessControl: props.accessControl,
meta: props.meta,
id,
resource,
});
Expand Down
Loading