Skip to content

Commit

Permalink
fix(core): label and route fields of useMenu.menuItems shouldn'…
Browse files Browse the repository at this point in the history
…t be deprecated (#6353) (resolves #6352)
  • Loading branch information
alicanerdurmaz authored Sep 23, 2024
1 parent da9da4e commit a0f2d7b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
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

0 comments on commit a0f2d7b

Please sign in to comment.