|
1 | | -import { useMemo, type JSX } from 'react'; |
| 1 | +import type { JSX } from 'react'; |
2 | 2 |
|
3 | | -import { MdOutlineMonitorHeart } from 'react-icons/md'; |
4 | | - |
5 | | -import { RxRadiobutton } from 'react-icons/rx'; |
6 | | - |
7 | | -import { ImTree } from 'react-icons/im'; |
8 | | -import { HiOutlineDocumentSearch } from 'react-icons/hi'; |
9 | | - |
10 | | -import { useLocation } from '@tanstack/react-router'; |
11 | | - |
12 | | -import { FormattedMessage } from 'react-intl'; |
13 | | - |
14 | | -import type { MessagesKey } from '@/locales/messages'; |
15 | | - |
16 | | -import { DOCUMENTATION_URL } from '@/utils/constants/general'; |
17 | | - |
18 | | -import { |
19 | | - NavigationMenu, |
20 | | - NavigationMenuItem, |
21 | | - NavigationMenuList, |
22 | | -} from '@/components/ui/navigation-menu'; |
23 | | - |
24 | | -import { Separator } from '@/components/ui/separator'; |
25 | | - |
26 | | -import type { PossibleMonitorPath } from '@/types/general'; |
27 | | - |
28 | | -import { ExternalLinkIcon } from '@/components/Icons/ExternalLink'; |
29 | | - |
30 | | -import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/Tooltip'; |
31 | | - |
32 | | -import SendFeedback from './SendFeedback'; |
33 | | - |
34 | | -import NavLink from './NavLink'; |
35 | | - |
36 | | -type RouteMenuItems = { |
37 | | - navigateTo: PossibleMonitorPath; |
38 | | - idIntl: MessagesKey; |
39 | | - icon: JSX.Element; |
40 | | - selected: boolean; |
41 | | -}; |
42 | | - |
43 | | -type LinkMenuItems = { |
44 | | - url: string; |
45 | | - idIntl: MessagesKey; |
46 | | - icon: JSX.Element; |
47 | | -}; |
48 | | - |
49 | | -type LinkStringItems = { |
50 | | - url: string; |
51 | | - label: string; |
52 | | -}; |
53 | | - |
54 | | -const linkItems: LinkMenuItems[] = [ |
55 | | - { |
56 | | - url: DOCUMENTATION_URL, |
57 | | - idIntl: 'global.documentation', |
58 | | - icon: <HiOutlineDocumentSearch />, |
59 | | - }, |
60 | | -]; |
61 | | - |
62 | | -const dashboardItems: LinkStringItems[] = [ |
63 | | - { |
64 | | - url: 'https://kdevops.org/', |
65 | | - label: 'kdevops', |
66 | | - }, |
67 | | - { |
68 | | - url: 'https://netdev.bots.linux.dev/contest.html', |
69 | | - label: 'netdev-CI', |
70 | | - }, |
71 | | -]; |
72 | | - |
73 | | -type SideMenuItemProps = { |
74 | | - item: RouteMenuItems; |
75 | | -}; |
76 | | - |
77 | | -const SideMenuItem = ({ item }: SideMenuItemProps): JSX.Element => { |
78 | | - const { pathname } = useLocation(); |
79 | | - |
80 | | - const isCurrentPath = |
81 | | - pathname.startsWith(item.navigateTo) && |
82 | | - (pathname.length === item.navigateTo.length || |
83 | | - pathname[item.navigateTo.length] === '/'); |
84 | | - |
85 | | - return ( |
86 | | - <NavigationMenuItem key={item.idIntl} className="w-full"> |
87 | | - <NavLink |
88 | | - selected={isCurrentPath} |
89 | | - to={item.navigateTo} |
90 | | - search={prevSearch => ({ |
91 | | - origin: prevSearch.origin, |
92 | | - })} |
93 | | - icon={item.icon} |
94 | | - idIntl={item.idIntl} |
95 | | - /> |
96 | | - </NavigationMenuItem> |
97 | | - ); |
98 | | -}; |
| 3 | +import SideMenuContent from './SideMenuContent'; |
99 | 4 |
|
100 | 5 | const SideMenu = (): JSX.Element => { |
101 | | - const routeItems: RouteMenuItems[] = [ |
102 | | - { |
103 | | - navigateTo: '/tree', |
104 | | - idIntl: 'routes.treeMonitor', |
105 | | - icon: <ImTree className="size-5" />, |
106 | | - selected: true, |
107 | | - }, |
108 | | - { |
109 | | - navigateTo: '/hardware', |
110 | | - idIntl: 'routes.hardwareMonitor', |
111 | | - icon: <MdOutlineMonitorHeart className="size-5" />, |
112 | | - selected: false, |
113 | | - }, |
114 | | - { |
115 | | - navigateTo: '/hardware-new', |
116 | | - idIntl: 'routes.hardwareNewMonitor', |
117 | | - icon: <MdOutlineMonitorHeart className="size-5" />, |
118 | | - selected: false, |
119 | | - }, |
120 | | - { |
121 | | - navigateTo: '/issues', |
122 | | - idIntl: 'routes.issueMonitor', |
123 | | - icon: <RxRadiobutton className="size-5" />, |
124 | | - selected: false, |
125 | | - }, |
126 | | - ]; |
127 | | - |
128 | | - const linksItemElements = useMemo( |
129 | | - () => |
130 | | - linkItems.map(item => ( |
131 | | - <NavigationMenuItem key={item.idIntl} className="w-full"> |
132 | | - <NavLink |
133 | | - asTag="a" |
134 | | - icon={item.icon} |
135 | | - idIntl={item.idIntl} |
136 | | - href={item.url} |
137 | | - target="_blank" |
138 | | - /> |
139 | | - </NavigationMenuItem> |
140 | | - )), |
141 | | - [], |
142 | | - ); |
143 | | - |
144 | | - const dashboardElements = useMemo( |
145 | | - () => |
146 | | - dashboardItems.map(item => ( |
147 | | - <NavigationMenuItem key={item.label} className="w-full"> |
148 | | - <NavLink |
149 | | - asTag="a" |
150 | | - icon={<ExternalLinkIcon />} |
151 | | - label={item.label} |
152 | | - href={item.url} |
153 | | - target="_blank" |
154 | | - /> |
155 | | - </NavigationMenuItem> |
156 | | - )), |
157 | | - [], |
158 | | - ); |
159 | | - |
160 | 6 | return ( |
161 | | - <NavigationMenu |
162 | | - className="bg-bg-secondary min-h-screen flex-col justify-start pt-6" |
163 | | - orientation="vertical" |
164 | | - > |
165 | | - <div className="w-full px-4"> |
166 | | - <img src="/kernelci-logo-white.svg" className="max-w-[125px]" /> |
167 | | - </div> |
168 | | - |
169 | | - <Separator className="bg-on-secondary-10 my-4" /> |
170 | | - |
171 | | - <NavigationMenuList className="w-56 flex-col space-y-4 space-x-0"> |
172 | | - {routeItems.map(item => ( |
173 | | - <SideMenuItem item={item} key={item.idIntl} /> |
174 | | - ))} |
175 | | - <Separator className="bg-on-secondary-10 my-4" /> |
176 | | - {linksItemElements} |
177 | | - <SendFeedback className="w-full" /> |
178 | | - <Separator className="bg-on-secondary-10 my-4" /> |
179 | | - <Tooltip> |
180 | | - <TooltipTrigger asChild> |
181 | | - <div className="flex items-center gap-2 text-white"> |
182 | | - <FormattedMessage id={'sidemenu.communityDashboards'} /> |
183 | | - </div> |
184 | | - </TooltipTrigger> |
185 | | - <TooltipContent className="max-w-[450px]"> |
186 | | - <FormattedMessage id={'sidemenu.communityDashboardsMsg'} /> |
187 | | - </TooltipContent> |
188 | | - </Tooltip> |
189 | | - <div className="flex w-full flex-col space-y-0"> |
190 | | - {dashboardElements} |
191 | | - </div> |
192 | | - </NavigationMenuList> |
193 | | - </NavigationMenu> |
| 7 | + <div className="bg-bg-secondary hidden md:block"> |
| 8 | + <SideMenuContent className="min-h-screen" /> |
| 9 | + </div> |
194 | 10 | ); |
195 | 11 | }; |
196 | 12 |
|
|
0 commit comments