Skip to content

Commit daf079b

Browse files
authored
chore: updated Root.tsx for navigation changes (#1705)
1 parent 2ad3475 commit daf079b

File tree

1 file changed

+54
-6
lines changed
  • workspaces/redhat-resource-optimization/packages/app/src/components/Root

1 file changed

+54
-6
lines changed

workspaces/redhat-resource-optimization/packages/app/src/components/Root/Root.tsx

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React, { PropsWithChildren } from 'react';
17+
import React, { PropsWithChildren, useState } from 'react';
1818
import { makeStyles } from '@material-ui/core';
1919
import HomeIcon from '@material-ui/icons/Home';
2020
import ExtensionIcon from '@material-ui/icons/Extension';
@@ -76,6 +76,49 @@ const Logo = (props: { isOpen?: boolean }) => {
7676
return logo;
7777
};
7878

79+
const CollapsibleSubmenu = ({
80+
icon,
81+
text,
82+
children,
83+
}: {
84+
icon: React.ReactElement;
85+
text: string;
86+
children: React.ReactNode;
87+
}) => {
88+
const [isOpen, setIsOpen] = useState(false);
89+
const { isOpen: sidebarOpen } = useSidebarOpenState();
90+
91+
return (
92+
<>
93+
<div
94+
onClick={() => setIsOpen(!isOpen)}
95+
onKeyDown={e => {
96+
if (e.key === 'Enter' || e.key === ' ') {
97+
e.preventDefault();
98+
setIsOpen(!isOpen);
99+
}
100+
}}
101+
role="button"
102+
tabIndex={0}
103+
style={{
104+
display: 'flex',
105+
alignItems: 'center',
106+
cursor: 'pointer',
107+
padding: '16px 16px',
108+
userSelect: 'none',
109+
}}
110+
>
111+
{icon}
112+
{sidebarOpen && <span style={{ marginLeft: 12, flex: 1 }}>{text}</span>}
113+
{sidebarOpen && (
114+
<span style={{ fontSize: '12px' }}>{isOpen ? '▼' : '▶'}</span>
115+
)}
116+
</div>
117+
{isOpen && <div style={{ marginLeft: 40 }}>{children}</div>}
118+
</>
119+
);
120+
};
121+
79122
const SidebarLogo = () => {
80123
const classes = useSidebarLogoStyles();
81124
const { isOpen } = useSidebarOpenState();
@@ -105,11 +148,16 @@ export const Root = ({ children }: PropsWithChildren<{}>) => (
105148
<SidebarItem icon={CreateComponentIcon} to="create" text="Create..." />
106149
{/* End global nav */}
107150
<SidebarDivider />
108-
<SidebarItem
109-
icon={ResourceOptimizationIconOutlined}
110-
to="/redhat-resource-optimization"
111-
text="Optimizations"
112-
/>
151+
<CollapsibleSubmenu
152+
icon={<ResourceOptimizationIconOutlined />}
153+
text="Cost management"
154+
>
155+
<SidebarItem
156+
icon={ResourceOptimizationIconOutlined}
157+
to="/redhat-resource-optimization"
158+
text="Optimizations"
159+
/>
160+
</CollapsibleSubmenu>
113161
<SidebarItem
114162
icon={OrchestratorIcon}
115163
to="orchestrator"

0 commit comments

Comments
 (0)