Skip to content

Commit

Permalink
fix(core): useMenu's default value of hideOnMissingParameter prop (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemir committed Apr 24, 2024
1 parent 0a76576 commit 9a0c1c8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/weak-impalas-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/core": patch
---

fix(core): `useMenu` `hideOnMissingParameter` prop default value set to `true`

There was an error in the `useMenu` hook's `hideOnMissingParameter` prop. Its default value should be `true` but it was missed when props are passed partially. This PR fixes the issue by setting the default value to `true`.
54 changes: 53 additions & 1 deletion packages/core/src/hooks/menu/useMenu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,59 @@ describe("useMenu Hook", () => {
);
});

it("should hide item if parameter is missing", async () => {
it("should hide item if parameter is missing by default", async () => {
const { result } = renderHook(() => useMenu(), {
wrapper: TestWrapper({
resources: legacyResourceTransform([
{
name: "visible",
list: () => null,
},
{
name: "org-users",
list: "orgs/:orgId/users",
},
]),
}),
});

expect(result.current.menuItems).toEqual(
expect.arrayContaining([expect.objectContaining({ name: "visible" })]),
);
expect(result.current.menuItems).toEqual(
expect.not.arrayContaining([
expect.objectContaining({ name: "org-users" }),
]),
);
});

it("should hide item if parameter is missing by partial props", async () => {
const { result } = renderHook(() => useMenu({ meta: {} }), {
wrapper: TestWrapper({
resources: legacyResourceTransform([
{
name: "visible",
list: () => null,
},
{
name: "org-users",
list: "orgs/:orgId/users",
},
]),
}),
});

expect(result.current.menuItems).toEqual(
expect.arrayContaining([expect.objectContaining({ name: "visible" })]),
);
expect(result.current.menuItems).toEqual(
expect.not.arrayContaining([
expect.objectContaining({ name: "org-users" }),
]),
);
});

it("should hide item if parameter is missing if set explicitly", async () => {
const { result } = renderHook(
() => useMenu({ hideOnMissingParameter: true }),
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/hooks/menu/useMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const getCleanPath = (pathname: string) => {
* @see {@link https://refine.dev/docs/api-reference/core/hooks/ui/useMenu} for more details.
*/
export const useMenu = (
{ meta, hideOnMissingParameter }: UseMenuProps = {
{ meta, hideOnMissingParameter = true }: UseMenuProps = {
hideOnMissingParameter: true,
},
): UseMenuReturnType => {
Expand Down

0 comments on commit 9a0c1c8

Please sign in to comment.