Skip to content
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

[FEAT]ListButton from @refinedev/mui doesn't implement the meta query properly #6528

Closed
arndom opened this issue Nov 27, 2024 · 4 comments · Fixed by #6530, #6558 or #6518
Closed

[FEAT]ListButton from @refinedev/mui doesn't implement the meta query properly #6528

arndom opened this issue Nov 27, 2024 · 4 comments · Fixed by #6530, #6558 or #6518
Labels
bug Something isn't working

Comments

@arndom
Copy link
Contributor

arndom commented Nov 27, 2024

Describe the bug

  • I tried to use the ListButton to route to the list page with some query filters but it completely overlooks the filters.
  • Here is what I did
<ListButton
      resource="contacts"
      meta={{
        query: {
          filters: [
            {
              field: filterField,
              operator: "contains",
              value: filterValue
            }
          ]
        }
      }}
    >
      Contacts
    </ListButton>
  • But instead of having the filters be part of the URL query, there is only /contacts

  • I followed the component definition and the error may be how the useNavigationButton from @refinedev/core is handling the meta prop
  const navigation = useNavigation();

  const to = React.useMemo(() => {
    if (!resource) return "";
    switch (props.action) {
      case "create":
      case "list": // here
        return navigation[`${props.action}Url`](resource, props.meta);
      default:
        if (!id) return "";
        return navigation[`${props.action}Url`](resource, id, props.meta);
    }
  }, [resource, id, props.meta, navigation[`${props.action}Url`]]);
  • I believe the issue is in the definition of listUrl inside the definition of useNavigation, though I'm unsure since I haven't indepthly gone through the source.

Steps To Reproduce

  • Attempt to navigate to a list page using:
<ListButton
      resource="contacts"
      meta={{
        query: {
          filters: [
            {
              field: filterField,
              operator: "contains",
              value: filterValue
            }
          ]
        }
      }}
    >
      Contacts
    </ListButton>

Expected behavior

  • the list button works with url query filters

Packages

  • "@refinedev/mui": "^5.14.4",
  • "@refinedev/core": "^4.47.1",

Additional Context

No response

@arndom arndom added the bug Something isn't working label Nov 27, 2024
@OmkarBansod02
Copy link
Contributor

The issue arises because the listUrl function in the useNavigation hook isn't properly handling query parameters from the meta object when generating URLs. This impacts both legacy and modern router implementations.
To address this, I'll update the listUrl function to handle query parameters correctly by :

  1. Passing the meta.query object to the composeRoute function.
  2. Merging existing URL parameters with new query filters.

The key change will involve updating the composeRoute call:

Screenshot 2024-11-27 222734

The updated code ensures existing parameters are preserved, new filters are added seamlessly, and the URL structure stays consistent. I'll be submitting a PR with these changes . Would you like me to proceed with the implementation?

@arndom
Copy link
Contributor Author

arndom commented Nov 27, 2024

That sounds good to me, the maintainers will point out anything that may be amiss if any.

I also suggest you check the other useNavigationButton uses incase they have a similar issue.

@aliemir
Copy link
Member

aliemir commented Dec 3, 2024

@arndom thank you for reporting! We can treat this one as a feature request.

@OmkarBansod02 Thank you for your interest, while your guess on listUrl is correct, composeRoute method is not the place for this. It will generate the route without query parameters by filling the parameter names (if any defined) in the route definition of the resources.

Instead of working on composeRoute, we can update the useNavigation method's listUrl, createUrl, editUrl, createUrl and cloneUrl methods to pass meta.query as query param of the go calls like below:

Changing the lines here

return go({
to: composeRoute(listActionRoute, resourceItem?.meta, parsed, meta),
type: "path",
}) as string;
with below:

return go({
  to: composeRoute(listActionRoute, resourceItem?.meta, parsed, meta),
  type: "path",
+ query: meta.query,
}) as string; 

query will be handled by the go method as expected.

@aliemir aliemir changed the title [BUG]ListButton from @refinedev/mui doesn't implement the meta query properly [FEAT]ListButton from @refinedev/mui doesn't implement the meta query properly Dec 3, 2024
@OmkarBansod02
Copy link
Contributor

@aliemir Thanks for pointing that out! I’ve made the changes to the useNavigation methods to pass meta.query in the go calls as suggested. here #6530

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants