演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
182 lines
6.6 KiB
TypeScript
182 lines
6.6 KiB
TypeScript
'use client'
|
|
|
|
import type { MainNavItem, MainNavProps } from './types'
|
|
import { cn } from '@langgenius/dify-ui/cn'
|
|
import { useQuery, useSuspenseQuery } from '@tanstack/react-query'
|
|
import { useAtomValue } from 'jotai'
|
|
import { lazy, Suspense, useMemo, useRef } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import Badge from '@/app/components/base/badge'
|
|
import { DifyLogo } from '@/app/components/base/logo/dify-logo'
|
|
import EnvNav from '@/app/components/header/env-nav'
|
|
import StepByStepTourMount from '@/app/components/step-by-step-tour/mount'
|
|
import {
|
|
isCurrentWorkspaceDatasetOperatorAtom,
|
|
isCurrentWorkspaceManagerAtom,
|
|
} from '@/context/workspace-state'
|
|
import { userProfileQueryOptions } from '@/features/account-profile/client'
|
|
import { isAgentV2Enabled } from '@/features/agent-v2/feature-flag'
|
|
import { isContactsManagementEnabled } from '@/features/contacts/management/feature-flag'
|
|
import { useMarketplace } from '@/features/marketplace/client'
|
|
import { useCanViewSkills } from '@/features/skills/permissions'
|
|
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
|
|
import Link from '@/next/link'
|
|
import { usePathname } from '@/next/navigation'
|
|
import { consoleQuery } from '@/service/console'
|
|
import AccountSection from './components/account-section'
|
|
import HelpMenu from './components/help-menu'
|
|
import MainNavLink from './components/nav-link'
|
|
import { MainNavSearchButton } from './components/search-button'
|
|
import { WorkspaceCard } from './components/workspace-card'
|
|
import { isMainNavRouteVisible, MAIN_NAV_ROUTES } from './routes'
|
|
|
|
const WebAppsSection = lazy(() => import('./components/web-apps-section'))
|
|
|
|
export function MainNav({ className, initialPlatform }: MainNavProps) {
|
|
const { t } = useTranslation(['common', 'navigation', 'contacts'])
|
|
const pathname = usePathname()
|
|
const isCurrentWorkspaceDatasetOperator = useAtomValue(isCurrentWorkspaceDatasetOperatorAtom)
|
|
const isCurrentWorkspaceManager = useAtomValue(isCurrentWorkspaceManagerAtom)
|
|
const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions())
|
|
const marketplaceEnabled = useMarketplace() !== null
|
|
const { data: currentEnv } = useSuspenseQuery({
|
|
...userProfileQueryOptions(),
|
|
select: (data) => data.meta.currentEnv,
|
|
})
|
|
const agentV2Enabled = isAgentV2Enabled()
|
|
const contactsEnabled = isContactsManagementEnabled()
|
|
const canViewSkills = useCanViewSkills()
|
|
const { data: enableSkill } = useQuery(
|
|
consoleQuery.features.get.queryOptions({
|
|
select: (features) => features.enable_skill,
|
|
}),
|
|
)
|
|
const showEnvTag = currentEnv === 'TESTING' || currentEnv === 'DEVELOPMENT'
|
|
const helpMenuTriggerRef = useRef<HTMLButtonElement>(null)
|
|
|
|
const navItems = useMemo<MainNavItem[]>(
|
|
() =>
|
|
MAIN_NAV_ROUTES.filter((route) =>
|
|
isMainNavRouteVisible(route, {
|
|
agentV2Enabled,
|
|
canViewContacts: isCurrentWorkspaceManager,
|
|
contactsEnabled,
|
|
canViewSkills,
|
|
isCurrentWorkspaceDatasetOperator,
|
|
marketplaceEnabled,
|
|
skillEnabled: enableSkill === true,
|
|
}),
|
|
).map((route) => {
|
|
const label =
|
|
'label' in route
|
|
? route.label
|
|
: 'ns' in route
|
|
? t(($) => $[route.labelKey], { ns: route.ns })
|
|
: t(($) => $[route.labelKey], { ns: 'navigation' })
|
|
|
|
return {
|
|
href: route.href,
|
|
label,
|
|
active: route.active,
|
|
icon: route.icon,
|
|
activeIcon: route.activeIcon,
|
|
}
|
|
}),
|
|
[
|
|
agentV2Enabled,
|
|
contactsEnabled,
|
|
canViewSkills,
|
|
enableSkill,
|
|
isCurrentWorkspaceDatasetOperator,
|
|
isCurrentWorkspaceManager,
|
|
marketplaceEnabled,
|
|
t,
|
|
],
|
|
)
|
|
|
|
const renderLogo = () => {
|
|
const appTitle =
|
|
systemFeatures.branding.enabled && systemFeatures.branding.application_title
|
|
? systemFeatures.branding.application_title
|
|
: '甘肃省房地产价格评估行业协会'
|
|
|
|
return (
|
|
<Link
|
|
href="/"
|
|
className="flex h-8 shrink-0 items-center overflow-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"
|
|
aria-label={appTitle}
|
|
>
|
|
{systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo ? (
|
|
<img
|
|
src={systemFeatures.branding.workspace_logo}
|
|
className="block h-5.5 w-auto object-contain"
|
|
alt=""
|
|
/>
|
|
) : (
|
|
<DifyLogo alt="甘肃省房地产价格评估行业协会" />
|
|
)}
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<aside
|
|
className={cn(
|
|
'relative flex h-full w-60 shrink-0 flex-col overflow-hidden bg-background-body transition-all',
|
|
className,
|
|
)}
|
|
>
|
|
<div className="flex min-h-0 w-60 flex-1 flex-col overflow-hidden">
|
|
<div className="flex items-center justify-between ps-4 pe-2 pt-3 pb-2">
|
|
{renderLogo()}
|
|
<MainNavSearchButton initialPlatform={initialPlatform} />
|
|
</div>
|
|
<div className="p-2">
|
|
<WorkspaceCard />
|
|
</div>
|
|
<nav
|
|
aria-label={t(($) => $['navigation.primary'], { ns: 'common' })}
|
|
className="isolate flex flex-col gap-px p-2"
|
|
>
|
|
{navItems.map((item) => (
|
|
<MainNavLink key={item.href} item={item} pathname={pathname}>
|
|
{item.href === '/agents' && (
|
|
<Badge
|
|
size="xs"
|
|
variant="dimm"
|
|
text={t(($) => $['menus.status'], { ns: 'navigation' })}
|
|
className="ms-auto shrink-0"
|
|
/>
|
|
)}
|
|
</MainNavLink>
|
|
))}
|
|
</nav>
|
|
{!isCurrentWorkspaceDatasetOperator && (
|
|
<Suspense fallback={null}>
|
|
<WebAppsSection />
|
|
</Suspense>
|
|
)}
|
|
{showEnvTag && (
|
|
<div className="mt-auto shrink-0 px-3 pb-2">
|
|
<EnvNav />
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="isolate w-60 shrink-0">
|
|
<StepByStepTourMount
|
|
recoveryAnchorRef={systemFeatures.branding.enabled ? undefined : helpMenuTriggerRef}
|
|
className="relative z-1 ms-2.5 -mb-1 h-8 w-45.75 overflow-visible"
|
|
/>
|
|
<div className="flex w-60 items-center justify-between bg-linear-to-b from-background-body-transparent to-background-body to-50% py-3 ps-3 pe-1 backdrop-blur-[2px]">
|
|
<div className="flex min-w-0 items-center gap-1 overflow-hidden">
|
|
<AccountSection />
|
|
</div>
|
|
<div className="flex shrink-0 items-center justify-center rounded-full p-1">
|
|
<HelpMenu triggerRef={helpMenuTriggerRef} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
)
|
|
}
|