Skip to content

Commit 55109ac

Browse files
severinoAmmiratiSeverinoAmmirati
andauthored
Fix panel hide feature (#57)
Co-authored-by: SeverinoAmmirati <severino.ammirati@oncode.it>
1 parent 8c21a81 commit 55109ac

3 files changed

Lines changed: 48 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fixed hide feature for tiles menu items
13+
1014
## [4.1.0] - 2024-05-27
1115

1216
### Added

cypress/cypress/component/PanelSidebar/PanelSidebar.cy.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { PropsWithChildren, ReactNode } from "react";
22
import { PanelSideBarProvider, PanelSideBarLayout, PanelItem, PanelLinkRendererProps, usePanelSideBarContext } from "react-pattern-ui";
3-
import { faBars, faCogs } from "@fortawesome/free-solid-svg-icons";
3+
import { faBars, faCogs, faInfo } from "@fortawesome/free-solid-svg-icons";
44

5-
type AppRoutes = "home" | "settings" | "dropdownTest" | "dropdown-test1" | "dropdown-test2";
5+
type AppRoutes = "home" | "settings" | "dropdownTest" | "dropdown-test1" | "dropdown-test2" | "info";
66
type TSideBarMenuItem = PanelItem<AppRoutes>;
77

88
// Configuration object for avoiding duplicated code
@@ -80,6 +80,19 @@ const getSidebarItems = (active?: boolean, disabled?: boolean, expanded?: boolea
8080
},
8181
],
8282
},
83+
{
84+
id: "info",
85+
title: "Info",
86+
icon: faInfo,
87+
display: false,
88+
children: [
89+
{
90+
title: "Info",
91+
id: "info",
92+
active,
93+
},
94+
],
95+
},
8396
];
8497

8598
interface PanelSideBarProps extends PropsWithChildren {
@@ -246,4 +259,12 @@ describe("PanelSidebar.cy.tsx", () => {
246259
cy.get("#test-close-item").click();
247260
cy.get("li:has(.dropdown-toggle)").should("be.visible").should("not.have.class", "menu-open");
248261
});
262+
263+
it("check hidden panel", () => {
264+
cy.mount(<PanelSideBarWithTiles />);
265+
266+
cy.get("button[title=Settings]").should("be.visible");
267+
cy.get("button[title=Home]").should("be.visible");
268+
cy.get("button[title=Info]").should("not.exist");
269+
});
249270
});

src/lib/Layout/PanelSideBarLayout/PanelSideBar/PanelSidebar.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ import { PanelItem } from "./Definitions/PanelItem";
66
import { PanelSideBarItem } from "./PanelSideBarItem";
77

88
export const PanelSideBar = <TPanelItemId extends string, TPanelItem>() => {
9-
const { activePanelId, menuItems, setActivePanel, renderFirstItemsLevelAsTiles, renderTilesAsLinks, LinkRenderer, theme } =
10-
usePanelSideBarContext<TPanelItemId, TPanelItem>();
9+
const {
10+
activePanelId,
11+
menuItems,
12+
setActivePanel,
13+
renderFirstItemsLevelAsTiles,
14+
renderTilesAsLinks,
15+
LinkRenderer,
16+
theme,
17+
hiddenMenuItemIds,
18+
} = usePanelSideBarContext<TPanelItemId, TPanelItem>();
1119

1220
const className = classNames(
1321
"panel-layout",
@@ -52,15 +60,17 @@ export const PanelSideBar = <TPanelItemId extends string, TPanelItem>() => {
5260

5361
const PanelItemsRenderer = (props: { items: PanelItem<TPanelItemId, TPanelItem>[] }) => {
5462
const { items } = props;
55-
return items?.map((item, index) =>
56-
renderTilesAsLinks ? (
57-
<LinkRenderer key={index} item={item}>
58-
<ButtonIcon item={item} />
59-
</LinkRenderer>
60-
) : (
61-
<ButtonIcon key={index} item={item} />
62-
),
63-
);
63+
return items
64+
?.filter((x) => !hiddenMenuItemIds.includes(x.id))
65+
.map((item, index) =>
66+
renderTilesAsLinks ? (
67+
<LinkRenderer key={index} item={item}>
68+
<ButtonIcon item={item} />
69+
</LinkRenderer>
70+
) : (
71+
<ButtonIcon key={index} item={item} />
72+
),
73+
);
6474
};
6575

6676
return (

0 commit comments

Comments
 (0)