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

[QUESTION] refine support meta sync with browser uri #6677

Closed
huntkalio opened this issue Feb 13, 2025 · 2 comments
Closed

[QUESTION] refine support meta sync with browser uri #6677

huntkalio opened this issue Feb 13, 2025 · 2 comments

Comments

@huntkalio
Copy link

I'm using Refine to implement control planes for certain middleware, and now I have multiple clusters to manage, each with similar middleware.
I want to add a cluster selection dropdown in the header, where selecting a cluster will make Refine query resources from the corresponding cluster. I'm wondering how to pass cluster parameters. I hope users can see the cluster parameters in the URI, so that copying and reopening the URI would still show the corresponding cluster.
1,I've tried passing them in meta, but this doesn't reflect in the URI
2. I'ver tied add a cluster prefix var in Refind resource like this
`
const cluster = Cookies.get("cluster") || "abc";

{
  name: "mysql",
  list:   "/cluster/" + cluster + "/mysql",
  create: "/cluster/" + cluster + "/mysql/create",
  edit:   "/cluster/" + cluster + "/mysql/edit/:id",
  show:   "/cluster/" + cluster + "/mysql/show/:id",
  meta: {
    canDelete: true,
  },
},

`
but this seems a bit awkward,and every times change cluster need reload page。

Does refine have any feature to solve this question?

@BatuhanW BatuhanW changed the title refine support meta sync with browser uri [QUESTION] refine support meta sync with browser uri Feb 13, 2025
@alicanerdurmaz
Copy link
Member

Hello @huntkalio,

Refine has the multiTenancyProvider feature for this case, but it's available in the Enterprise Edition. I'd like to give 1-2 tips for the Community Edition.

  1. First you can get the cluster from the route params, and you can tell Refine this as follows:
{
  name: "mysql",
  list:   "/cluster/" + ":clusterId" + "/mysql",
  create: "/cluster/" + ":clusterId" + "/mysql/create",
...
},
  1. After that, you’ll need to update the paths of your pages, of course. This may vary depending on whether you’re using React Router or Next.js.
  2. Then, you can use the <Link/> component to change the current cluster.
    Simple example:
import { Link } from "react-router-dom";

const ClusterSwitcher = ({ cluster }) => {
  return (
    <Link to={`/dashboard/${cluster}`}>
      Switch to {cluster}
    </Link>
  );
};

About cookies

The cluster value is being read from cookies only once when the component renders. If the cookie changes, the component doesn't re-render automatically because React doesn't track cookie changes.

You can check various sources for information on how to sync the cookie with React's state.

@huntkalio
Copy link
Author

Okay, thanks. I will try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants