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

fix(core): label and route fields of useMenu.menuItems shouldn't be deprecated #6353

Merged
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
25 changes: 25 additions & 0 deletions .changeset/fifty-moons-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"@refinedev/core": patch
---

fix: The `label` and `route` fields in `useMenu().menuItems` were marked as deprecated, but they are not actually deprecated. This issue was caused by `menuItems` extending from `IResourceItem`, however, `menuItems` populates these fields and handles deprecation of these fields internally. This change removes the deprecation warning for these fields.

```tsx
export const Sider = () => {
const { menuItems } = useMenu();
menuItems.map((item) => {
// these are safe to use
console.log(item.label);
console.log(item.route);
item.children.map((child) => {
// these are safe to use
console.log(child.label);
console.log(child.route);
});
});

return <div>{/* ... */}</div>;
};
```

[Fixes #6352](https://github.com/refinedev/refine/issues/6352)
18 changes: 11 additions & 7 deletions packages/core/src/hooks/menu/useMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export type UseMenuProps = {
hideOnMissingParameter?: boolean;
};

export type TreeMenuItem = FlatTreeItem & {
route?: string;
icon?: React.ReactNode;
label?: string;
children: TreeMenuItem[];
};
export type TreeMenuItem =
// Omitted because `label` and `route` are deprecated in `resource` but not in `menuItems`. These are populated in `prepareItem` for ease of use.
Omit<FlatTreeItem, "label" | "route" | "children"> & {
route?: string;
icon?: React.ReactNode;
label?: string;
children: TreeMenuItem[];
};

const getCleanPath = (pathname: string) => {
return pathname
Expand Down Expand Up @@ -86,7 +88,9 @@ export const useMenu = (

const prepareItem = React.useCallback(
(item: FlatTreeItem): TreeMenuItem | undefined => {
if (item?.meta?.hide ?? item?.options?.hide) return undefined;
if (pickNotDeprecated(item?.meta?.hide, item?.options?.hide)) {
return undefined;
}
if (!item?.list && item.children.length === 0) return undefined;

const composed = item.list
Expand Down
Loading