Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat(web): open the main nav in a drawer on narrow screens (#45650)
yyhb9bf6ea18258
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.jsonindex f73faf1104d..4e3ef8dbda6 100644--- a/oxlint-suppressions.json+++ b/oxlint-suppressions.json@@ -2780,11 +2780,6 @@"count": 4}},- "web/app/components/detail-sidebar/index.tsx": {- "better-tailwindcss/enforce-logical-properties": {- "count": 1- }- },"web/app/components/explore/installed-app/index.tsx": {"better-tailwindcss/enforce-logical-properties": {"count": 1@@ -2946,11 +2941,6 @@"count": 1}},- "web/app/components/integrations/__tests__/page.spec.tsx": {- "typescript/no-deprecated": {- "count": 2- }- },"web/app/components/integrations/sidebar-nav-item.tsx": {"better-tailwindcss/enforce-logical-properties": {"count": 2diff --git a/web/app/components/app-sidebar/dataset-detail-sidebar.tsx b/web/app/components/app-sidebar/dataset-detail-sidebar.tsxindex c2bf43f6d5e..1d589c8e174 100644--- a/web/app/components/app-sidebar/dataset-detail-sidebar.tsx+++ b/web/app/components/app-sidebar/dataset-detail-sidebar.tsx@@ -1,18 +1,12 @@'use client'-import { useMediaQuery } from '@langgenius/dify-ui/use-media-query'import { DetailSidebarFrame } from '@/app/components/detail-sidebar'-import { usePathname } from '@/next/navigation'import DatasetDetailSection from './dataset-detail-section'import { DatasetDetailTop } from './dataset-detail-top'export function DatasetDetailSidebar() {- const isBelowSm = useMediaQuery('(width < 40rem)', {})- const pathname = usePathname()-return (<DetailSidebarFrame- compact={isBelowSm && pathname.endsWith('/settings')}renderTop={({ expand, onToggle }) => <DatasetDetailTop expand={expand} onToggle={onToggle} />}renderSection={({ expand }) => <DatasetDetailSection expand={expand} />}/>diff --git a/web/app/components/detail-sidebar/__tests__/index.spec.tsx b/web/app/components/detail-sidebar/__tests__/index.spec.tsxindex 5b2f636fb5b..8f6e6ded06e 100644--- a/web/app/components/detail-sidebar/__tests__/index.spec.tsx+++ b/web/app/components/detail-sidebar/__tests__/index.spec.tsx@@ -6,12 +6,21 @@ import userEvent from '@testing-library/user-event'import { Provider } from 'jotai'import { useHydrateAtoms } from 'jotai/utils'import Cookies from 'js-cookie'-import { useState } from 'react'import { renderWithConsoleQuery } from '@/test/console/query-data'import { DetailSidebarFrame } from '..'import { DETAIL_SIDEBAR_COOKIE_NAME } from '../cookie'import { detailSidebarModeAtom } from '../state'+const media = vi.hoisted(() => ({ compact: false, pathname: '/app/app-1/overview' }))++vi.mock('@langgenius/dify-ui/use-media-query', () => ({+ useMediaQuery: (query: string) => query === '(width < 48rem)' && media.compact,+}))++vi.mock('@/next/navigation', () => ({+ usePathname: () => media.pathname,+}))+vi.mock('@/app/components/main-nav/components/account-section', () => ({default: ({ compact }: { compact?: boolean }) => (<button type="button" aria-label="account">@@ -49,12 +58,12 @@ function renderDetailSidebarFrame(compact = false,mode: DetailSidebarMode = 'expand',) {- return renderWithConsoleQuery(+ media.compact = compact+ const tree = () => (<Provider><InitialDetailSidebarMode mode={mode}><HotkeysProvider defaultOptions={{ hotkey: { platform } }}><DetailSidebarFrame- compact={compact}renderTop={({ expand, onToggle }) => (<div data-testid="detail-top" data-expand={expand}><button type="button" data-testid="detail-toggle" onClick={onToggle}>@@ -75,13 +84,16 @@ function renderDetailSidebarFrame(<textarea aria-label="Description" /></HotkeysProvider></InitialDetailSidebarMode>- </Provider>,- { accountProfileMeta: { currentEnv } },+ </Provider>)+ const view = renderWithConsoleQuery(tree(), { accountProfileMeta: { currentEnv } })+ return { ...view, rerenderTree: () => view.rerender(tree()) }}describe('DetailSidebarFrame', () => {beforeEach(() => {+ media.compact = false+ media.pathname = '/app/app-1/overview'Cookies.remove(DETAIL_SIDEBAR_COOKIE_NAME)})@@ -115,6 +127,19 @@ describe('DetailSidebarFrame', () => {expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBeUndefined()})+ it('collapses compact navigation after the route changes', async () => {+ const user = userEvent.setup()+ const view = renderDetailSidebarFrame(null, 'mac', true)++ await user.click(screen.getByRole('button', { name: 'Toggle' }))+ expect(screen.getByRole('button', { name: 'account' })).toHaveTextContent('Expanded account')++ media.pathname = '/app/app-1/logs'+ view.rerenderTree()++ expect(screen.getByRole('button', { name: 'account' })).toHaveTextContent('Compact account')+ })+describe.each(['mac', 'windows'] as const)('%s shortcut', (platform) => {const modifiers = platform === 'mac' ? { metaKey: true } : { ctrlKey: true }@@ -201,37 +226,31 @@ describe('DetailSidebarFrame', () => {expect(Cookies.get(DETAIL_SIDEBAR_COOKIE_NAME)).toBe('collapse')})- it('does not restore a stale hover preview after leaving compact layout', async () => {- const user = userEvent.setup()+ it('does not restore a stale hover preview after leaving compact layout', () => {+ media.compact = false+ const sidebar = () => (+ <Provider>+ <InitialDetailSidebarMode mode="collapse">+ <HotkeysProvider>+ <DetailSidebarFrame+ renderTop={({ expand }) => <div data-testid="detail-top" data-expand={expand} />}+ renderSection={() => <div>Section</div>}+ />+ </HotkeysProvider>+ </InitialDetailSidebarMode>+ </Provider>+ )- function ResponsiveDetailSidebar() {- const [compact, setCompact] = useState(false)- return (- <Provider>- <InitialDetailSidebarMode mode="collapse">- <HotkeysProvider>- <button type="button" onClick={() => setCompact((value) => !value)}>- Switch layout- </button>- <DetailSidebarFrame- compact={compact}- renderTop={({ expand }) => <div data-testid="detail-top" data-expand={expand} />}- renderSection={() => <div>Section</div>}- />- </HotkeysProvider>- </InitialDetailSidebarMode>- </Provider>- )- }-- renderWithConsoleQuery(<ResponsiveDetailSidebar />, {+ const view = renderWithConsoleQuery(sidebar(), {accountProfileMeta: { currentEnv: null },})fireEvent.mouseEnter(screen.getByTestId('detail-top').parentElement!)expect(screen.getByRole('button', { name: 'account' })).toHaveTextContent('Expanded account')- await user.click(screen.getByRole('button', { name: 'Switch layout' }))- await user.click(screen.getByRole('button', { name: 'Switch layout' }))+ media.compact = true+ view.rerender(sidebar())+ media.compact = false+ view.rerender(sidebar())expect(screen.getByRole('button', { name: 'account' })).toHaveTextContent('Compact account')})diff --git a/web/app/components/detail-sidebar/index.tsx b/web/app/components/detail-sidebar/index.tsxindex 1e82b347974..885f28d255b 100644--- a/web/app/components/detail-sidebar/index.tsx+++ b/web/app/components/detail-sidebar/index.tsx@@ -2,6 +2,7 @@import type { ReactNode } from 'react'import { cn } from '@langgenius/dify-ui/cn'+import { useMediaQuery } from '@langgenius/dify-ui/use-media-query'import { useHotkey } from '@tanstack/react-hotkeys'import { useSuspenseQuery } from '@tanstack/react-query'import { useAtomValue, useSetAtom } from 'jotai'@@ -10,6 +11,7 @@ import EnvNav from '@/app/components/header/env-nav'import AccountSection from '@/app/components/main-nav/components/account-section'import HelpMenu from '@/app/components/main-nav/components/help-menu'import { userProfileQueryOptions } from '@/features/account-profile/client'+import { usePathname } from '@/next/navigation'import { DETAIL_SIDEBAR_TOGGLE_HOTKEY } from './hotkeys'import { detailSidebarModeAtom, setDetailSidebarModeAtom } from './state'@@ -20,7 +22,6 @@ type DetailSidebarRenderProps = {type DetailSidebarFrameProps = {className?: string- compact?: booleanrenderTop: (props: DetailSidebarRenderProps) => ReactNoderenderSection: (props: Pick<DetailSidebarRenderProps, 'expand'>) => ReactNode}@@ -43,7 +44,6 @@ function SecondarySidebarHelpMenu({ triggerClassName }: { triggerClassName?: strexport function DetailSidebarFrame({className,- compact = false,renderTop,renderSection,}: DetailSidebarFrameProps) {@@ -51,9 +51,12 @@ export function DetailSidebarFrame({...userProfileQueryOptions(),select: (data) => data.meta.currentEnv,})+ const compact = useMediaQuery('(width < 48rem)', {})const storedMode = useAtomValue(detailSidebarModeAtom)const setStoredMode = useSetAtom(setDetailSidebarModeAtom)- const [compactExpanded, setCompactExpanded] = useState(false)+ const pathname = usePathname()+ const [compactExpandedOn, setCompactExpandedOn] = useState<{ pathname: string } | null>(null)+ const compactExpanded = compactExpandedOn?.pathname === pathnameconst [hoverPreviewOpen, setHoverPreviewOpen] = useState(false)const closePreviewTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)if (compact && hoverPreviewOpen) setHoverPreviewOpen(false)@@ -69,7 +72,7 @@ export function DetailSidebarFrame({function handleToggleDetailNavigation() {if (compact) {- setCompactExpanded((expanded) => !expanded)+ setCompactExpandedOn(compactExpanded ? null : { pathname })return}@@ -143,7 +146,7 @@ export function DetailSidebarFrame({className={cn('flex min-h-0 w-14 shrink-0 flex-col overflow-hidden rounded-lg bg-components-panel-bg','data-visible-expanded:z-40 data-visible-expanded:w-60',- 'data-overlay:absolute data-overlay:inset-y-1 data-overlay:left-1',+ 'data-overlay:absolute data-overlay:inset-y-1 data-overlay:inset-s-1','data-overlay:bg-components-panel-bg-blur data-overlay:shadow-[0px_12px_16px_0px_var(--color-shadow-shadow-5),0px_4px_6px_0px_var(--color-shadow-shadow-1)] data-overlay:backdrop-blur-[5px]',)}data-visible-expanded={visibleExpanded || undefined}diff --git a/web/app/components/integrations/__tests__/page.spec.tsx b/web/app/components/integrations/__tests__/page.spec.tsxindex b66cb29e63b..79b13146fca 100644--- a/web/app/components/integrations/__tests__/page.spec.tsx+++ b/web/app/components/integrations/__tests__/page.spec.tsx@@ -243,16 +243,18 @@ it('defaults to models and preserves a real model search across section navigatiit('closes compact navigation after changing the settings section', async () => {const user = userEvent.setup()- vi.spyOn(window, 'matchMedia').mockImplementation((query) => ({- matches: query === '(width < 48rem)',- media: query,- onchange: null,- addEventListener: vi.fn(),- removeEventListener: vi.fn(),- addListener: vi.fn(),- removeListener: vi.fn(),- dispatchEvent: vi.fn(),- }))+ const matchMedia = vi.spyOn(window, 'matchMedia').mockImplementation(+ (query) =>+ ({+ matches: false,+ media: query,+ onchange: null,+ addEventListener: vi.fn(),+ removeEventListener: vi.fn(),+ dispatchEvent: vi.fn(),+ }) as unknown as MediaQueryList,+ )+ onTestFinished(() => matchMedia.mockRestore())renderPage({ ui: <SettingsIntegrations /> })await user.click(screen.getByRole('button', {diff --git a/web/app/components/integrations/index.tsx b/web/app/components/integrations/index.tsxindex 05d5fc73250..23adce66e9c 100644--- a/web/app/components/integrations/index.tsx+++ b/web/app/components/integrations/index.tsx@@ -1,6 +1,5 @@'use client'-import type { DrawerActions } from '@langgenius/dify-ui/drawer'import type { CSSProperties, ReactNode } from 'react'import type { IntegrationSection } from './routes'import type { DocPathWithoutLang } from '@/types/doc-paths'@@ -20,7 +19,7 @@ import {} from '@langgenius/dify-ui/drawer'import { IconButton } from '@langgenius/dify-ui/icon-button'import { useMediaQuery } from '@langgenius/dify-ui/use-media-query'-import { Suspense, useId, useRef, useState } from 'react'+import { Suspense, useId, useState } from 'react'import { useTranslation } from 'react-i18next'import { UpdateSettingDialog } from '@/app/components/header/account-setting/update-setting-dialog'import {@@ -82,7 +81,7 @@ const DescriptionWithLearnMore = ({ children, href, label }: DescriptionWithLearreturn (<span className="inline-flex max-w-full min-w-0 items-center gap-0.5">- <span className="min-w-0 break-words whitespace-normal sm:truncate" title={title}>+ <span className="min-w-0 wrap-break-word whitespace-normal sm:truncate" title={title}>{children}</span><Link@@ -133,7 +132,7 @@ export default function IntegrationsPage({}: IntegrationsPageProps) {const { t } = useTranslation(['navigation', 'modelProvider', 'common'])const navigationTitleId = useId()- const isCompact = useMediaQuery('(width < 48rem)', {})+ const isAtLeastMd = useMediaQuery('(width >= 48rem)', {})const docLink = useDocLink()const router = useRouter()const section = useIntegrationSection(routeSection)@@ -150,7 +149,11 @@ export default function IntegrationsPage({showPluginCategorySetting,} = useIntegrationPermissions(section)const [providerSearchText, setProviderSearchText] = useState('')- const navigationDrawerActionsRef = useRef<DrawerActions>(null)+ const [navigationOpenedOn, setNavigationOpenedOn] = useState<{+ section: IntegrationSection+ } | null>(null)+ if (isAtLeastMd && navigationOpenedOn) setNavigationOpenedOn(null)+ const navigationOpen = navigationOpenedOn?.section === sectionconst showInstallAction = canInstallPluginconst reserveInstallActionSlot = showInstallAction || isReferenceSettingLoadingconst showUtilityActions = canDebugger || showPermissionQuickPanel@@ -224,8 +227,8 @@ export default function IntegrationsPage({)}const handleSelectSection = (nextSection: IntegrationSection) => {+ setNavigationOpenedOn(null)if (onSectionChange) {- navigationDrawerActionsRef.current?.close()onSectionChange(nextSection)return}@@ -253,103 +256,105 @@ export default function IntegrationsPage({</>)- const sidebar = (- <div- className={cn(- 'flex shrink-0 flex-col bg-components-panel-bg px-2 py-2 transition-[width]',- isCompact- ? 'h-full w-full items-stretch overflow-y-auto'- : 'w-50 items-end border-e border-divider-burn',- )}- data-step-by-step-tour-target={STEP_BY_STEP_TOUR_TARGETS.integration}- >+ const renderSidebar = (placement: 'inline' | 'drawer') => {+ const inDrawer = placement === 'drawer'+ const titleId = `${navigationTitleId}-${placement}`++ return (<div- className={cn('flex min-h-0 flex-1 flex-col gap-0.5 pb-4', isCompact ? 'w-full' : 'w-46')}+ className={cn(+ 'flex shrink-0 flex-col bg-components-panel-bg px-2 py-2 transition-[width]',+ inDrawer+ ? 'h-full w-full items-stretch overflow-y-auto'+ : 'w-50 items-end border-e border-divider-burn max-md:hidden',+ )}+ data-step-by-step-tour-target={inDrawer ? undefined : STEP_BY_STEP_TOUR_TARGETS.integration}><div- className={cn(- 'flex shrink-0 items-start ps-2.5 pe-0',- reserveInstallActionSlot ? 'h-14 pt-1 pb-7' : 'mb-3 pt-1 pb-0.5',- )}+ className={cn('flex min-h-0 flex-1 flex-col gap-0.5 pb-4', inDrawer ? 'w-full' : 'w-46')}>- <div className="flex h-6 min-w-0 flex-1 items-center justify-center">- <div- id={navigationTitleId}- className="min-w-0 flex-1 title-2xl-semi-bold text-text-primary"- >- {t(($) => $['settings.integrations'], { ns: 'navigation' })}+ <div+ className={cn(+ 'flex shrink-0 items-start ps-2.5 pe-0',+ reserveInstallActionSlot ? 'h-14 pt-1 pb-7' : 'mb-3 pt-1 pb-0.5',+ )}+ >+ <div className="flex h-6 min-w-0 flex-1 items-center justify-center">+ <div id={titleId} className="min-w-0 flex-1 title-2xl-semi-bold text-text-primary">+ {t(($) => $['settings.integrations'], { ns: 'navigation' })}+ </div></div></div>- </div>- {showInstallAction && (- <IntegrationSidebarActions- canManagement={canInstallPlugin}- installContextCategory={getPluginCategoryBySection(section)}- onSwitchToMarketplace={handleSwitchToMarketplace}- />- )}- {!showInstallAction && reserveInstallActionSlot && (- <div aria-hidden="true" className="h-8 w-full shrink-0" />- )}- <nav- aria-labelledby={navigationTitleId}- className={cn('shrink-0 space-y-px', reserveInstallActionSlot ? 'mt-6' : 'py-4')}- >- <IntegrationSidebarNavItem- item={providerItem}- onSelect={onSectionChange ? handleSelectSection : undefined}- section={section}- />- <Collapsible open={isToolsExpanded} onOpenChange={handleToolsOpenChange}>- <CollapsibleTrigger- className={cn(- toolsNavItemClassName,- 'min-h-8 touch-manipulation justify-between border-none bg-transparent select-none data-panel-open:text-components-menu-item-text',- )}- >- {toolsNavItemContent}- </CollapsibleTrigger>- <CollapsiblePanel className="relative space-y-px before:absolute before:inset-s-[17.5px] before:-top-px before:bottom-0 before:w-px before:bg-divider-regular">- {toolItems.map((item) => (- <IntegrationSidebarNavItem- key={item.label}- item={item}- onSelect={onSectionChange ? handleSelectSection : undefined}- section={section}- />- ))}- </CollapsiblePanel>- </Collapsible>- <IntegrationSidebarNavItem- item={dataSourceItem}- onSelect={onSectionChange ? handleSelectSection : undefined}- section={section}- />- {secondaryItems.map((item) => (+ {showInstallAction && (+ <IntegrationSidebarActions+ canManagement={canInstallPlugin}+ installContextCategory={getPluginCategoryBySection(section)}+ onSwitchToMarketplace={handleSwitchToMarketplace}+ />+ )}+ {!showInstallAction && reserveInstallActionSlot && (+ <div aria-hidden="true" className="h-8 w-full shrink-0" />+ )}+ <nav+ aria-labelledby={titleId}+ className={cn('shrink-0 space-y-px', reserveInstallActionSlot ? 'mt-6' : 'py-4')}+ >+ <IntegrationSidebarNavItem+ item={providerItem}+ onSelect={onSectionChange ? handleSelectSection : undefined}+ section={section}+ />+ <Collapsible open={isToolsExpanded} onOpenChange={handleToolsOpenChange}>+ <CollapsibleTrigger+ className={cn(+ toolsNavItemClassName,+ 'min-h-8 touch-manipulation justify-between border-none bg-transparent select-none data-panel-open:text-components-menu-item-text',+ )}+ >+ {toolsNavItemContent}+ </CollapsibleTrigger>+ <CollapsiblePanel className="relative space-y-px before:absolute before:inset-s-[17.5px] before:-top-px before:bottom-0 before:w-px before:bg-divider-regular">+ {toolItems.map((item) => (+ <IntegrationSidebarNavItem+ key={item.label}+ item={item}+ onSelect={onSectionChange ? handleSelectSection : undefined}+ section={section}+ />+ ))}+ </CollapsiblePanel>+ </Collapsible>+ <IntegrationSidebarNavItem+ item={dataSourceItem}+ onSelect={onSectionChange ? handleSelectSection : undefined}+ section={section}+ />+ {secondaryItems.map((item) => (+ <IntegrationSidebarNavItem+ key={item.label}+ item={item}+ onSelect={onSectionChange ? handleSelectSection : undefined}+ section={section}+ />+ ))}<IntegrationSidebarNavItem- key={item.label}- item={item}+ item={customEndpointItem}onSelect={onSectionChange ? handleSelectSection : undefined}section={section}/>- ))}- <IntegrationSidebarNavItem- item={customEndpointItem}- onSelect={onSectionChange ? handleSelectSection : undefined}- section={section}+ </nav>+ </div>+ {showUtilityActions && (+ <IntegrationSidebarUtilityActions+ canDebugger={canDebugger}+ permission={permission}+ showPermissionQuickPanel={showPermissionQuickPanel}+ onPermissionChange={handlePermissionChange}/>- </nav>+ )}</div>- {showUtilityActions && (- <IntegrationSidebarUtilityActions- canDebugger={canDebugger}- permission={permission}- showPermissionQuickPanel={showPermissionQuickPanel}- onPermissionChange={handlePermissionChange}- />- )}- </div>- )+ )+ }return (<div@@ -359,41 +364,44 @@ export default function IntegrationsPage({{syncDocumentTitle && (<IntegrationsDocumentTitle title={`${sectionTitle} · ${integrationsTitle}`} />)}- {isCompact ? (- <div className="shrink-0 border-b border-divider-burn px-2 pb-2">- <Drawer swipeDirection="left" actionsRef={navigationDrawerActionsRef}>- <DrawerTrigger render={<Button variant="secondary" className="max-w-full" />}>- <span aria-hidden="true" className="i-ri-menu-line size-4 shrink-0" />- <span className="truncate">- {integrationsTitle}: {sectionTitle}- </span>- </DrawerTrigger>- <DrawerPortal>- <DrawerBackdrop className="fixed" />- <DrawerViewport>- <DrawerPopup className="data-[swipe-direction=left]:w-80 data-[swipe-direction=left]:max-w-full">- <div className="flex shrink-0 items-center justify-between gap-2 px-3 py-2">- <DrawerTitle className="system-md-semibold">{integrationsTitle}</DrawerTitle>- <DrawerClose- render={- <IconButton- aria-label={t(($) => $['operation.close'], { ns: 'common' })}- size="lg"- >- <span aria-hidden="true" className="i-ri-close-line size-4" />- </IconButton>- }- />- </div>- <DrawerContent className="min-h-0 flex-1 p-0 pb-0">{sidebar}</DrawerContent>- </DrawerPopup>- </DrawerViewport>- </DrawerPortal>- </Drawer>- </div>- ) : (- sidebar- )}+ <div className="shrink-0 border-b border-divider-burn px-2 pb-2 md:hidden">+ <Drawer+ swipeDirection="left"+ open={navigationOpen}+ onOpenChange={(open) => setNavigationOpenedOn(open ? { section } : null)}+ >+ <DrawerTrigger render={<Button variant="secondary" className="max-w-full" />}>+ <span aria-hidden="true" className="i-ri-menu-line size-4 shrink-0" />+ <span className="truncate">+ {integrationsTitle}: {sectionTitle}+ </span>+ </DrawerTrigger>+ <DrawerPortal>+ <DrawerBackdrop className="fixed" />+ <DrawerViewport>+ <DrawerPopup className="data-[swipe-direction=left]:w-80 data-[swipe-direction=left]:max-w-full">+ <div className="flex shrink-0 items-center justify-between gap-2 px-3 py-2">+ <DrawerTitle className="system-md-semibold">{integrationsTitle}</DrawerTitle>+ <DrawerClose+ render={+ <IconButton+ aria-label={t(($) => $['operation.close'], { ns: 'common' })}+ size="lg"+ >+ <span aria-hidden="true" className="i-ri-close-line size-4" />+ </IconButton>+ }+ />+ </div>+ <DrawerContent className="min-h-0 flex-1 p-0 pb-0">+ {renderSidebar('drawer')}+ </DrawerContent>+ </DrawerPopup>+ </DrawerViewport>+ </DrawerPortal>+ </Drawer>+ </div>+ {renderSidebar('inline')}<section className="flex min-w-0 flex-1 flex-col overflow-hidden max-md:overflow-visible">{useFillLayout ? (<div className="flex min-h-0 flex-1 flex-col overflow-hidden max-md:overflow-visible">diff --git a/web/app/components/main-nav/__tests__/layout.spec.tsx b/web/app/components/main-nav/__tests__/layout.spec.tsxindex 9dcffd3cd47..d9bf3b37da2 100644--- a/web/app/components/main-nav/__tests__/layout.spec.tsx+++ b/web/app/components/main-nav/__tests__/layout.spec.tsx@@ -60,6 +60,10 @@ vi.mock('../index', () => ({),}))+vi.mock('../mobile-nav', () => ({+ MainNavMobileBar: () => <header data-testid="main-nav-mobile-bar" />,+}))+vi.mock('@/app/components/app-sidebar/dataset-detail-sidebar', () => ({DatasetDetailSidebar: () => <aside aria-label="Knowledge sidebar">Knowledge sidebar</aside>,}))@@ -181,6 +185,8 @@ describe('MainNavLayout', () => {const detailSidebar = screen.getByRole('complementary', { name: 'Detail sidebar' })expect(screen.queryByTestId('main-nav')).not.toBeInTheDocument()++ expect(screen.queryByTestId('main-nav-mobile-bar')).not.toBeInTheDocument()expect(screen.getAllByRole('main')).toHaveLength(1)expect(main).toHaveAttribute('id', 'main-content')expect(main).toHaveTextContent('dataset detail')@@ -203,6 +209,8 @@ describe('MainNavLayout', () => {)expect(screen.queryByTestId('main-nav')).not.toBeInTheDocument()++ expect(screen.queryByTestId('main-nav-mobile-bar')).not.toBeInTheDocument()expect(screen.queryByRole('complementary', { name: 'Legacy dataset sidebar' }),).not.toBeInTheDocument()@@ -220,6 +228,8 @@ describe('MainNavLayout', () => {)expect(screen.queryByTestId('main-nav')).not.toBeInTheDocument()++ expect(screen.queryByTestId('main-nav-mobile-bar')).not.toBeInTheDocument()expect(screen.getByRole('main')).toHaveTextContent('skill detail')})@@ -233,6 +243,8 @@ describe('MainNavLayout', () => {)expect(screen.getByTestId('main-nav')).toBeInTheDocument()++ expect(screen.getByTestId('main-nav-mobile-bar')).toBeInTheDocument()})it.each([@@ -254,6 +266,7 @@ describe('MainNavLayout', () => {expect(screen.getByRole('complementary', { name: 'Knowledge sidebar' })).toBeInTheDocument()expect(screen.queryByTestId('main-nav')).not.toBeInTheDocument()+ expect(screen.queryByTestId('main-nav-mobile-bar')).not.toBeInTheDocument()expect(screen.getByRole('main')).toHaveTextContent('document upload')},)@@ -276,6 +289,8 @@ describe('MainNavLayout', () => {)expect(screen.getByTestId('main-nav')).toBeInTheDocument()++ expect(screen.getByTestId('main-nav-mobile-bar')).toBeInTheDocument()expect(screen.queryByRole('complementary', { name: 'Detail sidebar' })).not.toBeInTheDocument()})@@ -302,6 +317,7 @@ describe('MainNavLayout', () => {</MainNavLayout>,)expect(screen.getByTestId('main-nav')).toBeInTheDocument()+ expect(screen.getByTestId('main-nav-mobile-bar')).toBeInTheDocument()expect(screen.queryByRole('complementary', { name: 'Detail sidebar' }),).not.toBeInTheDocument()diff --git a/web/app/components/main-nav/__tests__/mobile-nav.spec.tsx b/web/app/components/main-nav/__tests__/mobile-nav.spec.tsxnew file mode 100644index 00000000000..1e5b44c7c19--- /dev/null+++ b/web/app/components/main-nav/__tests__/mobile-nav.spec.tsx@@ -0,0 +1,89 @@+import { render, screen, waitFor, within } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { MainNavMobileBar } from '../mobile-nav'++const state = vi.hoisted(() => ({ atLeastMd: false, pathname: '/apps' }))++vi.mock('@langgenius/dify-ui/use-media-query', () => ({+ useMediaQuery: (query: string) => query === '(width >= 48rem)' && state.atLeastMd,+}))++vi.mock('@/next/navigation', () => ({+ usePathname: () => state.pathname,+}))++vi.mock('../index', () => ({+ MainNavLogo: () => <a href="/">Dify</a>,+ MainNavPanel: () => (+ <nav aria-label="Primary">+ {/* Client-side links cancel the native navigation, like next/link does. */}+ <a href="/datasets" onClick={(event) => event.preventDefault()}>+ Knowledge+ </a>+ <a href="https://docs.dify.ai" target="_blank" rel="noreferrer">+ Docs+ </a>+ <button type="button">Search</button>+ </nav>+ ),+ MainNavFooter: () => null,+}))++const menuName = 'common.navigation.primary'++beforeEach(() => {+ state.atLeastMd = false+ state.pathname = '/apps'+})++async function openMenu() {+ const user = userEvent.setup()+ const view = render(<MainNavMobileBar />)+ await user.click(screen.getByRole('button', { name: menuName }))+ const drawer = await screen.findByRole('dialog', { name: menuName })+ return { drawer, user, view }+}++async function expectClosed() {+ await waitFor(() =>+ expect(screen.queryByRole('dialog', { name: menuName })).not.toBeInTheDocument(),+ )+}++it('closes after following a client-side link', async () => {+ const { drawer, user } = await openMenu()++ await user.click(within(drawer).getByRole('link', { name: 'Knowledge' }))++ await expectClosed()+})++it('stays open for new-tab links, modified clicks, and non-link controls', async () => {+ const { drawer, user } = await openMenu()++ await user.click(within(drawer).getByRole('link', { name: 'Docs' }))+ await user.keyboard('{Meta>}')+ await user.click(within(drawer).getByRole('link', { name: 'Knowledge' }))+ await user.keyboard('{/Meta}')+ await user.click(within(drawer).getByRole('button', { name: 'Search' }))++ expect(screen.getByRole('dialog', { name: menuName })).toBeInTheDocument()+})++it('closes when the route changes without a link click', async () => {+ const { view } = await openMenu()++ state.pathname = '/datasets'+ view.rerender(<MainNavMobileBar />)++ await expectClosed()+})++it('closes when the viewport widens to the desktop layout', async () => {+ const { view } = await openMenu()++ state.atLeastMd = true+ view.rerender(<MainNavMobileBar />)++ await expectClosed()+})diff --git a/web/app/components/main-nav/index.tsx b/web/app/components/main-nav/index.tsxindex f41d01385d7..b4118e912c9 100644--- a/web/app/components/main-nav/index.tsx+++ b/web/app/components/main-nav/index.tsx@@ -1,5 +1,6 @@'use client'+import type { Ref } from 'react'import type { MainNavItem, MainNavProps } from './types'import { cn } from '@langgenius/dify-ui/cn'import { useQuery, useSuspenseQuery } from '@tanstack/react-query'@@ -32,12 +33,34 @@ import { isMainNavRouteVisible, MAIN_NAV_ROUTES } from './routes'const WebAppsSection = lazy(() => import('./components/web-apps-section'))-export function MainNav({ className, initialPlatform }: MainNavProps) {+export function MainNavLogo() {+ const { data: branding } = useSuspenseQuery({+ ...systemFeaturesQueryOptions(),+ select: (data) => data.branding,+ })+ const appTitle =+ branding.enabled && branding.application_title ? branding.application_title : 'Dify'++ 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}+ >+ {branding.enabled && branding.workspace_logo ? (+ <img src={branding.workspace_logo} className="block h-5.5 w-auto object-contain" alt="" />+ ) : (+ <DifyLogo alt="" />+ )}+ </Link>+ )+}++export function MainNavPanel({ initialPlatform }: Pick<MainNavProps, 'initialPlatform'>) {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() !== nullconst { data: currentEnv } = useSuspenseQuery({...userProfileQueryOptions(),@@ -52,7 +75,6 @@ export function MainNav({ className, initialPlatform }: MainNavProps) {}),)const showEnvTag = currentEnv === 'TESTING' || currentEnv === 'DEVELOPMENT'- const helpMenuTriggerRef = useRef<HTMLButtonElement>(null)const navItems = useMemo<MainNavItem[]>(() =>@@ -94,30 +116,69 @@ export function MainNav({ className, initialPlatform }: MainNavProps) {],)- const renderLogo = () => {- const appTitle =- systemFeatures.branding.enabled && systemFeatures.branding.application_title- ? systemFeatures.branding.application_title- : 'Dify'-- 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}+ return (+ <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">+ <MainNavLogo />+ <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">- {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>- )- }+ {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>+ )+}++export function MainNavFooter({+ helpMenuTriggerRef,+}: {+ helpMenuTriggerRef?: Ref<HTMLButtonElement>+}) {+ return (+ <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>+ )+}++export function MainNav({ className, initialPlatform }: MainNavProps) {+ const { data: brandingEnabled } = useSuspenseQuery({+ ...systemFeaturesQueryOptions(),+ select: (data) => data.branding.enabled,+ })+ const helpMenuTriggerRef = useRef<HTMLButtonElement>(null)return (<aside@@ -126,55 +187,13 @@ export function MainNav({ className, initialPlatform }: MainNavProps) {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>+ <MainNavPanel initialPlatform={initialPlatform} /><div className="isolate w-60 shrink-0"><StepByStepTourMount- recoveryAnchorRef={systemFeatures.branding.enabled ? undefined : helpMenuTriggerRef}+ recoveryAnchorRef={brandingEnabled ? 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>+ <MainNavFooter helpMenuTriggerRef={helpMenuTriggerRef} /></div></aside>)diff --git a/web/app/components/main-nav/layout.tsx b/web/app/components/main-nav/layout.tsxindex 8c0b824f2a1..67aac28e197 100644--- a/web/app/components/main-nav/layout.tsx+++ b/web/app/components/main-nav/layout.tsx@@ -14,6 +14,7 @@ import { isCurrentWorkspaceDatasetOperatorAtom } from '@/context/workspace-stateimport { isAgentV2Enabled } from '@/features/agent-v2/feature-flag'import { usePathname } from '@/next/navigation'import { MainNav } from '.'+import { MainNavMobileBar } from './mobile-nav'import { shouldHideMainNavigation, shouldUseDetailSidebar } from './routes'import { MAIN_CONTENT_ID, SkipLink } from './skip-link'@@ -40,15 +41,23 @@ const MainNavLayout = ({agentV2Enabled: isAgentV2Enabled(),isCurrentWorkspaceDatasetOperator,})+ const showMainNav = !hideMainNavigation && !useDetailSidebarreturn (- <div className="flex h-0 min-h-0 min-w-0 grow overflow-hidden bg-background-body">+ <div+ className={cn(+ 'flex h-0 min-h-0 min-w-0 grow overflow-hidden bg-background-body',+ showMainNav && 'max-md:flex-col',+ )}+ ><SkipLink>{t(($) => $['navigation.skipToMain'])}</SkipLink>{appId && <AppDetailPrefetch appId={appId} />}- {hideMainNavigation ? null : useDetailSidebar ? (- detailSidebar- ) : (- <MainNav initialPlatform={initialPlatform} />+ {useDetailSidebar && !hideMainNavigation && detailSidebar}+ {showMainNav && (+ <>+ <MainNavMobileBar initialPlatform={initialPlatform} />+ <MainNav className="max-md:hidden" initialPlatform={initialPlatform} />+ </>)}<mainid={MAIN_CONTENT_ID}diff --git a/web/app/components/main-nav/mobile-nav.tsx b/web/app/components/main-nav/mobile-nav.tsxnew file mode 100644index 00000000000..3b696a79399--- /dev/null+++ b/web/app/components/main-nav/mobile-nav.tsx@@ -0,0 +1,73 @@+'use client'++import type { MouseEvent } from 'react'+import type { MainNavProps } from './types'+import {+ Drawer,+ DrawerBackdrop,+ DrawerContent,+ DrawerPopup,+ DrawerPortal,+ DrawerTrigger,+ DrawerViewport,+} from '@langgenius/dify-ui/drawer'+import { IconButton } from '@langgenius/dify-ui/icon-button'+import { useMediaQuery } from '@langgenius/dify-ui/use-media-query'+import { useState } from 'react'+import { useTranslation } from 'react-i18next'+import { usePathname } from '@/next/navigation'+import { MainNavFooter, MainNavLogo, MainNavPanel } from '.'++function isPlainLinkClick(event: MouseEvent) {+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return false+ return (+ event.target instanceof Element &&+ event.target.closest('a[href]:not([target="_blank"])') !== null+ )+}++export function MainNavMobileBar({ initialPlatform }: Pick<MainNavProps, 'initialPlatform'>) {+ const { t } = useTranslation(['common'])+ const pathname = usePathname()+ const [openedOn, setOpenedOn] = useState<{ pathname: string } | null>(null)+ const isAtLeastMd = useMediaQuery('(width >= 48rem)', {})+ if (isAtLeastMd && openedOn) setOpenedOn(null)+ const open = openedOn?.pathname === pathname+ const setOpen = (nextOpen: boolean) => setOpenedOn(nextOpen ? { pathname } : null)++ const menuLabel = t(($) => $['navigation.primary'], { ns: 'common' })++ return (+ <header className="flex shrink-0 items-center justify-between bg-background-body ps-4 pe-2 pt-3 pb-2 md:hidden">+ <MainNavLogo />+ <Drawer swipeDirection="left" open={open} onOpenChange={setOpen}>+ <DrawerTrigger+ render={+ <IconButton aria-label={menuLabel} size="lg">+ <span aria-hidden="true" className="i-ri-menu-line size-4" />+ </IconButton>+ }+ />+ <DrawerPortal>+ <DrawerBackdrop className="fixed" />+ <DrawerViewport>+ <DrawerPopup+ aria-label={menuLabel}+ className="bg-background-body data-[swipe-direction=left]:w-60 data-[swipe-direction=left]:border-y-0"+ >+ <DrawerContent+ className="flex flex-col p-0"+ onClick={(event) => {+ if (isPlainLinkClick(event)) setOpen(false)+ }}+ >+ <MainNavPanel initialPlatform={initialPlatform} />+ <MainNavFooter />+ </DrawerContent>+ </DrawerPopup>+ </DrawerViewport>+ </DrawerPortal>+ </Drawer>+ </header>+ )+}diff --git a/web/features/agent-v2/agent-detail/detail-sidebar.tsx b/web/features/agent-v2/agent-detail/detail-sidebar.tsxindex 75cba1d2d54..e8503441223 100644--- a/web/features/agent-v2/agent-detail/detail-sidebar.tsx+++ b/web/features/agent-v2/agent-detail/detail-sidebar.tsx@@ -1,15 +1,11 @@'use client'-import { useMediaQuery } from '@langgenius/dify-ui/use-media-query'import { DetailSidebarFrame } from '@/app/components/detail-sidebar'import { AgentDetailSection, AgentDetailTop } from './navigation'export function AgentDetailSidebar() {- const isBelowMd = useMediaQuery('(width < 48rem)', {})-return (<DetailSidebarFrame- compact={isBelowMd}renderTop={({ expand, onToggle }) => <AgentDetailTop expand={expand} onToggle={onToggle} />}renderSection={({ expand }) => <AgentDetailSection expand={expand} />}/>