2025-07-08 20:04:15 +08:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react'
|
2025-06-24 09:10:30 +08:00
|
|
|
import { usePathname } from 'next/navigation'
|
2024-04-24 04:07:28 +00:00
|
|
|
import { useShallow } from 'zustand/react/shallow'
|
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'
|
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'
|
2025-06-24 09:10:30 +08:00
|
|
|
import AppSidebarDropdown from './app-sidebar-dropdown'
|
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'
|
2025-06-24 09:10:30 +08:00
|
|
|
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
2024-12-26 12:01:51 +08:00
|
|
|
import cn from '@/utils/classnames'
|
2025-07-08 20:04:15 +08:00
|
|
|
import Divider from '../base/divider'
|
|
|
|
import { useHover, useKeyPress } from 'ahooks'
|
|
|
|
import ToggleButton from './toggle-button'
|
|
|
|
import { getKeyboardKeyCodeBySystem } from '../workflow/utils'
|
2025-07-09 15:13:02 +08:00
|
|
|
import DatasetSidebarDropdown from './dataset-sidebar-dropdown'
|
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
|
|
|
navigation: Array<{
|
|
|
|
name: string
|
|
|
|
href: string
|
2023-08-28 19:48:53 +08:00
|
|
|
icon: NavIcon
|
|
|
|
selectedIcon: NavIcon
|
2025-05-29 14:06:12 +08:00
|
|
|
disabled?: boolean
|
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
|
|
|
}
|
|
|
|
|
2025-05-06 16:37:21 +08:00
|
|
|
const AppDetailNav = ({
|
|
|
|
navigation,
|
|
|
|
extraInfo,
|
|
|
|
iconType = 'app',
|
|
|
|
}: IAppDetailNavProps) => {
|
2025-05-06 11:58:53 +08:00
|
|
|
const { appSidebarExpand, setAppSidebarExpand } = useAppStore(useShallow(state => ({
|
2024-04-24 04:07:28 +00:00
|
|
|
appSidebarExpand: state.appSidebarExpand,
|
2025-05-06 11:58:53 +08:00
|
|
|
setAppSidebarExpand: state.setAppSidebarExpand,
|
2024-04-24 04:07:28 +00:00
|
|
|
})))
|
2025-07-08 20:04:15 +08:00
|
|
|
const sidebarRef = React.useRef<HTMLDivElement>(null)
|
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
|
|
|
|
2025-07-08 20:04:15 +08:00
|
|
|
const handleToggle = useCallback(() => {
|
|
|
|
setAppSidebarExpand(appSidebarExpand === 'expand' ? 'collapse' : 'expand')
|
|
|
|
}, [appSidebarExpand, setAppSidebarExpand])
|
|
|
|
|
|
|
|
const isHoveringSidebar = useHover(sidebarRef)
|
2023-11-27 11:47:48 +08:00
|
|
|
|
2025-07-08 20:04:15 +08:00
|
|
|
// Check if the current path is a workflow canvas & fullscreen
|
2025-06-24 09:10:30 +08:00
|
|
|
const pathname = usePathname()
|
|
|
|
const inWorkflowCanvas = pathname.endsWith('/workflow')
|
2025-07-09 15:13:02 +08:00
|
|
|
const isPipelineCanvas = pathname.endsWith('/pipeline')
|
2025-06-24 09:10:30 +08:00
|
|
|
const workflowCanvasMaximize = localStorage.getItem('workflow-canvas-maximize') === 'true'
|
|
|
|
const [hideHeader, setHideHeader] = useState(workflowCanvasMaximize)
|
|
|
|
const { eventEmitter } = useEventEmitterContextContext()
|
|
|
|
|
|
|
|
eventEmitter?.useSubscription((v: any) => {
|
|
|
|
if (v?.type === 'workflow-canvas-maximize')
|
|
|
|
setHideHeader(v.payload)
|
|
|
|
})
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
useEffect(() => {
|
|
|
|
if (appSidebarExpand) {
|
|
|
|
localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand)
|
2025-05-06 11:58:53 +08:00
|
|
|
setAppSidebarExpand(appSidebarExpand)
|
2024-01-25 12:36:55 +08:00
|
|
|
}
|
2025-05-06 11:58:53 +08:00
|
|
|
}, [appSidebarExpand, setAppSidebarExpand])
|
2024-01-25 12:36:55 +08:00
|
|
|
|
2025-07-17 18:22:03 +08:00
|
|
|
useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.b`, (e) => {
|
2025-07-08 20:04:15 +08:00
|
|
|
e.preventDefault()
|
|
|
|
handleToggle()
|
|
|
|
}, { exactMatch: true, useCapture: true })
|
|
|
|
|
2025-06-24 09:10:30 +08:00
|
|
|
if (inWorkflowCanvas && hideHeader) {
|
2025-07-08 20:04:15 +08:00
|
|
|
return (
|
2025-06-24 09:10:30 +08:00
|
|
|
<div className='flex w-0 shrink-0'>
|
|
|
|
<AppSidebarDropdown navigation={navigation} />
|
|
|
|
</div>
|
|
|
|
)
|
2025-07-08 20:04:15 +08:00
|
|
|
}
|
2025-06-24 09:10:30 +08:00
|
|
|
|
2025-07-09 15:13:02 +08:00
|
|
|
if (isPipelineCanvas && hideHeader) {
|
|
|
|
return (
|
|
|
|
<div className='flex w-0 shrink-0'>
|
|
|
|
<DatasetSidebarDropdown navigation={navigation} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
return (
|
2024-01-11 13:26:34 +08:00
|
|
|
<div
|
2025-07-08 20:04:15 +08:00
|
|
|
ref={sidebarRef}
|
2025-07-09 10:45:50 +08:00
|
|
|
className={cn(
|
|
|
|
'flex shrink-0 flex-col border-r border-divider-burn bg-background-default-subtle transition-all',
|
|
|
|
expand ? 'w-[216px]' : 'w-14',
|
|
|
|
)}
|
2024-01-11 13:26:34 +08:00
|
|
|
>
|
|
|
|
<div
|
2025-07-09 10:45:50 +08:00
|
|
|
className={cn(
|
|
|
|
'shrink-0',
|
|
|
|
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
|
|
|
)}
|
2025-05-16 15:14:50 +08:00
|
|
|
{iconType !== 'app' && (
|
2025-07-09 10:45:50 +08:00
|
|
|
<DatasetInfo expand={expand} />
|
2024-12-26 12:01:51 +08:00
|
|
|
)}
|
2023-05-15 08:51:32 +08:00
|
|
|
</div>
|
2025-07-08 20:04:15 +08:00
|
|
|
<div className='relative px-4 py-2'>
|
|
|
|
<Divider
|
|
|
|
type='horizontal'
|
|
|
|
bgStyle={expand ? 'gradient' : 'solid'}
|
|
|
|
className={cn(
|
|
|
|
'my-0 h-px',
|
|
|
|
expand
|
|
|
|
? 'bg-gradient-to-r from-divider-subtle to-background-gradient-mask-transparent'
|
|
|
|
: 'bg-divider-subtle',
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{!isMobile && isHoveringSidebar && (
|
|
|
|
<ToggleButton
|
|
|
|
className='absolute -right-3 top-[-3.5px] z-20'
|
|
|
|
expand={expand}
|
|
|
|
handleToggle={handleToggle}
|
|
|
|
/>
|
|
|
|
)}
|
2024-12-26 12:01:51 +08:00
|
|
|
</div>
|
2024-01-11 13:26:34 +08:00
|
|
|
<nav
|
2025-07-08 20:04:15 +08:00
|
|
|
className={cn(
|
|
|
|
'flex grow flex-col gap-y-0.5',
|
|
|
|
expand ? 'px-3 py-2' : 'p-3',
|
|
|
|
)}
|
2024-01-11 13:26:34 +08:00
|
|
|
>
|
2023-05-15 08:51:32 +08:00
|
|
|
{navigation.map((item, index) => {
|
|
|
|
return (
|
2025-05-29 14:06:12 +08:00
|
|
|
<NavLink
|
|
|
|
key={index}
|
|
|
|
mode={appSidebarExpand}
|
|
|
|
iconMap={{ selected: item.selectedIcon, normal: item.icon }}
|
|
|
|
name={item.name}
|
|
|
|
href={item.href}
|
|
|
|
disabled={!!item.disabled}
|
|
|
|
/>
|
2023-05-15 08:51:32 +08:00
|
|
|
)
|
|
|
|
})}
|
|
|
|
</nav>
|
2025-07-09 10:45:50 +08:00
|
|
|
{iconType !== 'app' && extraInfo && extraInfo(appSidebarExpand)}
|
2023-05-15 08:51:32 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default React.memo(AppDetailNav)
|