| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  | import React, { useEffect } from 'react' | 
					
						
							|  |  |  | import { useShallow } from 'zustand/react/shallow' | 
					
						
							| 
									
										
										
										
											2025-04-14 15:45:23 +08:00
										 |  |  | import { RiLayoutLeft2Line, RiLayoutRight2Line } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import NavLink from './navLink' | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | import type { NavIcon } from './navLink' | 
					
						
							| 
									
										
										
										
											2023-11-27 11:47:48 +08:00
										 |  |  | import AppBasic from './basic' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import AppInfo from './app-info' | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | import DatasetInfo from './dataset-info' | 
					
						
							| 
									
										
										
										
											2023-11-27 11:47:48 +08:00
										 |  |  | import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { useStore as useAppStore } from '@/app/components/app/store' | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export type IAppDetailNavProps = { | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |   iconType?: 'app' | 'dataset' | 'notion' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   title: string | 
					
						
							|  |  |  |   desc: string | 
					
						
							| 
									
										
										
										
											2024-09-30 15:38:43 +08:00
										 |  |  |   isExternal?: boolean | 
					
						
							| 
									
										
										
										
											2023-05-19 17:36:44 +08:00
										 |  |  |   icon: string | 
					
						
							|  |  |  |   icon_background: string | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   navigation: Array<{ | 
					
						
							|  |  |  |     name: string | 
					
						
							|  |  |  |     href: string | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  |     icon: NavIcon | 
					
						
							|  |  |  |     selectedIcon: NavIcon | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   }> | 
					
						
							| 
									
										
										
										
											2024-01-16 12:14:09 +08:00
										 |  |  |   extraInfo?: (modeState: string) => React.ReactNode | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 15:38:43 +08:00
										 |  |  | const AppDetailNav = ({ title, desc, isExternal, icon, icon_background, navigation, extraInfo, iconType = 'app' }: IAppDetailNavProps) => { | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |   const { appSidebarExpand, setAppSiderbarExpand } = useAppStore(useShallow(state => ({ | 
					
						
							|  |  |  |     appSidebarExpand: state.appSidebarExpand, | 
					
						
							|  |  |  |     setAppSiderbarExpand: state.setAppSiderbarExpand, | 
					
						
							|  |  |  |   }))) | 
					
						
							| 
									
										
										
										
											2023-11-27 11:47:48 +08:00
										 |  |  |   const media = useBreakpoints() | 
					
						
							|  |  |  |   const isMobile = media === MediaType.mobile | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |   const expand = appSidebarExpand === 'expand' | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   const handleToggle = (state: string) => { | 
					
						
							|  |  |  |     setAppSiderbarExpand(state === 'expand' ? 'collapse' : 'expand') | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-11-27 11:47:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (appSidebarExpand) { | 
					
						
							|  |  |  |       localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand) | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |       setAppSiderbarExpand(appSidebarExpand) | 
					
						
							| 
									
										
										
										
											2024-01-25 12:36:55 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |   }, [appSidebarExpand, setAppSiderbarExpand]) | 
					
						
							| 
									
										
										
										
											2024-01-25 12:36:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |     <div | 
					
						
							|  |  |  |       className={`
 | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         flex shrink-0 flex-col border-r border-divider-burn bg-background-default-subtle transition-all | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |         ${expand ? 'w-[216px]' : 'w-14'} | 
					
						
							|  |  |  |       `}
 | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <div | 
					
						
							|  |  |  |         className={`
 | 
					
						
							|  |  |  |           shrink-0 | 
					
						
							| 
									
										
										
										
											2025-02-07 18:56:43 +08:00
										 |  |  |           ${expand ? 'p-2' : 'p-1'} | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |         `}
 | 
					
						
							|  |  |  |       > | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         {iconType === 'app' && ( | 
					
						
							| 
									
										
										
										
											2024-07-23 17:11:02 +08:00
										 |  |  |           <AppInfo expand={expand} /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         )} | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |         {iconType === 'dataset' && ( | 
					
						
							|  |  |  |           <DatasetInfo | 
					
						
							|  |  |  |             name={title} | 
					
						
							|  |  |  |             description={desc} | 
					
						
							|  |  |  |             isExternal={isExternal} | 
					
						
							|  |  |  |             expand={expand} | 
					
						
							|  |  |  |             extraInfo={extraInfo && extraInfo(appSidebarExpand)} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         )} | 
					
						
							|  |  |  |         {!['app', 'dataset'].includes(iconType) && ( | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           <AppBasic | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |             mode={appSidebarExpand} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |             iconType={iconType} | 
					
						
							|  |  |  |             icon={icon} | 
					
						
							|  |  |  |             icon_background={icon_background} | 
					
						
							|  |  |  |             name={title} | 
					
						
							|  |  |  |             type={desc} | 
					
						
							| 
									
										
										
										
											2024-09-30 15:38:43 +08:00
										 |  |  |             isExternal={isExternal} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |           /> | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |       <div className='px-4'> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         <div className={cn('mx-auto mt-1 h-[1px] bg-divider-subtle', !expand && 'w-6')} /> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |       <nav | 
					
						
							|  |  |  |         className={`
 | 
					
						
							| 
									
										
										
										
											2024-07-23 17:11:02 +08:00
										 |  |  |           grow space-y-1 | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |           ${expand ? 'p-4' : 'px-2.5 py-4'} | 
					
						
							|  |  |  |         `}
 | 
					
						
							|  |  |  |       > | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         {navigation.map((item, index) => { | 
					
						
							|  |  |  |           return ( | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |             <NavLink key={index} mode={appSidebarExpand} iconMap={{ selected: item.selectedIcon, normal: item.icon }} name={item.name} href={item.href} /> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |           ) | 
					
						
							|  |  |  |         })} | 
					
						
							|  |  |  |       </nav> | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         !isMobile && ( | 
					
						
							|  |  |  |           <div | 
					
						
							|  |  |  |             className={`
 | 
					
						
							|  |  |  |               shrink-0 py-3 | 
					
						
							|  |  |  |               ${expand ? 'px-6' : 'px-4'} | 
					
						
							|  |  |  |             `}
 | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <div | 
					
						
							| 
									
										
										
										
											2025-04-14 15:45:23 +08:00
										 |  |  |               className='flex h-6 w-6 cursor-pointer items-center justify-center' | 
					
						
							| 
									
										
										
										
											2024-04-24 04:07:28 +00:00
										 |  |  |               onClick={() => handleToggle(appSidebarExpand)} | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |             > | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 expand | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                   ? <RiLayoutRight2Line className='h-5 w-5 text-components-menu-item-text' /> | 
					
						
							| 
									
										
										
										
											2025-04-14 15:45:23 +08:00
										 |  |  |                   : <RiLayoutLeft2Line className='h-5 w-5 text-components-menu-item-text' /> | 
					
						
							| 
									
										
										
										
											2024-01-11 13:26:34 +08:00
										 |  |  |               } | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default React.memo(AppDetailNav) |