🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(agent): move Agent sidebar search to the header in the macOS app and label its actions on hover (#23511)
AmAzing-488273c66a24
diff --git a/src/features/AgentSidebar/Header/Nav.test.tsx b/src/features/AgentSidebar/Header/Nav.test.tsxindex d4f7cf11024..587d9a0dc16 100644--- a/src/features/AgentSidebar/Header/Nav.test.tsx+++ b/src/features/AgentSidebar/Header/Nav.test.tsx@@ -1,6 +1,7 @@/*** @vitest-environment happy-dom*/+import type * as LobeUI from '@lobehub/ui';import { fireEvent, render, screen } from '@testing-library/react';import type { ReactNode } from 'react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -8,6 +9,37 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import Nav from './index';vi.mock('./Agent', () => ({ default: () => null }));+const platformMock = vi.hoisted(() => ({ isMacDesktop: true }));+vi.mock('@/features/NavPanel/ToggleLeftPanelButton', () => ({+ default: () => null,+ get isMacDesktop() {+ return platformMock.isMacDesktop;+ },+}));+vi.mock('@lobehub/ui', async (importOriginal) => {+ const actual = await importOriginal<typeof LobeUI>();+ return {+ ...actual,+ // Real ActionIcon only surfaces `title` through a hover Tooltip, which+ // happy-dom cannot open; a plain button keeps the hover label assertable.+ ActionIcon: ({+ 'aria-label': ariaLabel,+ onClick,+ title,+ }: {+ 'aria-label'?: string;+ 'onClick'?: () => void;+ 'title'?: ReactNode;+ }) => (+ <button+ aria-label={ariaLabel}+ data-hover-title={typeof title === 'string' ? title : undefined}+ type="button"+ onClick={onClick}+ />+ ),+ };+});vi.mock('@/features/NavPanel/backOrigin', () => ({ useBackButtonProps: () => ({}) }));vi.mock('@/features/NavPanel/SideBarHeaderLayout', () => ({default: ({ left, right }: { left: ReactNode; right?: ReactNode }) => (@@ -165,6 +197,7 @@ describe('Agent sidebar header nav', () => {labMock.enableGoals = true;resourceAccessMock.canEditResource = true;resourceAccessMock.isAccessResolved = true;+ platformMock.isMacDesktop = true;useParamsMock.mockReturnValue({ aid: 'agt_eH4zL98zBx5u', topicId: 'tpc_2FCHvjS7d4CA' });});@@ -245,6 +278,54 @@ describe('Agent sidebar header nav', () => {expect(pushMock).toHaveBeenCalledWith('/agent/agt_eH4zL98zBx5u/profile');});+ it('opens search from the header, not from the nav list, in the macOS app', () => {+ usePathnameMock.mockReturnValue('/agent/agt_eH4zL98zBx5u');++ render(<Nav />);+ const searchButton = screen.getByRole('button', { name: 'tab.search' });+ expect(screen.getByRole('banner')).toContainElement(searchButton);+ expect(screen.getAllByRole('button', { name: 'tab.search' })).toHaveLength(1);+ fireEvent.click(searchButton);++ expect(toggleCommandMenuMock).toHaveBeenCalledWith(true);+ });++ // Web, mobile and the Windows app show the panel toggle in the header, which+ // leaves no room for search there.+ it('keeps search as a nav row outside the macOS app', () => {+ platformMock.isMacDesktop = false;+ usePathnameMock.mockReturnValue('/agent/agt_eH4zL98zBx5u');++ render(<Nav />);+ const searchButton = screen.getByRole('button', { name: 'tab.search' });+ expect(screen.getByRole('banner')).not.toContainElement(searchButton);+ expect(screen.getAllByRole('button', { name: 'tab.search' })).toHaveLength(1);+ expect(searchButton).toHaveTextContent('tab.search');+ fireEvent.click(searchButton);++ expect(toggleCommandMenuMock).toHaveBeenCalledWith(true);+ });++ it('keeps header search for members who cannot open the profile', () => {+ permissionMock.edit_own_content = false;+ usePathnameMock.mockReturnValue('/agent/agt_eH4zL98zBx5u');++ render(<Nav />);++ expect(screen.getByRole('banner')).toContainElement(+ screen.getByRole('button', { name: 'tab.search' }),+ );+ expect(screen.queryByRole('button', { name: 'tab.profile' })).toBeNull();+ });++ it.each(['tab.search', 'tab.profile'])('shows the %s label on hover', (label) => {+ usePathnameMock.mockReturnValue('/agent/agt_eH4zL98zBx5u');++ render(<Nav />);++ expect(screen.getByRole('button', { name: label })).toHaveAttribute('data-hover-title', label);+ });+it.each([[false, false],[false, undefined],diff --git a/src/features/AgentSidebar/Header/Nav.tsx b/src/features/AgentSidebar/Header/Nav.tsxindex dba892f9a8f..8ca91e9a796 100644--- a/src/features/AgentSidebar/Header/Nav.tsx+++ b/src/features/AgentSidebar/Header/Nav.tsx@@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next';import urlJoin from 'url-join';import NavItem from '@/features/NavPanel/components/NavItem';+import { isMacDesktop } from '@/features/NavPanel/ToggleLeftPanelButton';import { useSelfLearningSurface } from '@/features/SelfLearning/SurfaceGate/useSelfLearningSurface';import { useActiveLocation } from '@/hooks/useActiveLocation';import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';@@ -75,13 +76,14 @@ const Nav = ({ onOpenProfile, showProfile }: NavProps) => {title={tTopic('actions.addNewTopic')}onClick={handleNewTopic}/>- <NavItem- icon={SearchIcon}- title={t('tab.search')}- onClick={() => {- toggleCommandMenu(true);- }}- />+ {/* The macOS app opens search from the header instead. */}+ {!isMacDesktop && (+ <NavItem+ icon={SearchIcon}+ title={t('tab.search')}+ onClick={() => toggleCommandMenu(true)}+ />+ )}{showProfile && isMobileSurface() && (<NavItemactive={isProfileActive}diff --git a/src/features/AgentSidebar/Header/index.tsx b/src/features/AgentSidebar/Header/index.tsxindex 8d63d73d673..3aa09331a3c 100644--- a/src/features/AgentSidebar/Header/index.tsx+++ b/src/features/AgentSidebar/Header/index.tsx@@ -1,18 +1,20 @@'use client';import { ActionIcon } from '@lobehub/ui';-import { SettingsIcon } from 'lucide-react';+import { SearchIcon, SettingsIcon } from 'lucide-react';import { type PropsWithChildren } from 'react';import { useTranslation } from 'react-i18next';import urlJoin from 'url-join';import { useBackButtonProps } from '@/features/NavPanel/backOrigin';import SideBarHeaderLayout from '@/features/NavPanel/SideBarHeaderLayout';+import { isMacDesktop } from '@/features/NavPanel/ToggleLeftPanelButton';import { useResourceAccess } from '@/features/ResourcePermission/useResourceAccess';import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';import { usePermission } from '@/hooks/usePermission';import { useQueryRoute } from '@/hooks/useQueryRoute';import { useChatStore } from '@/store/chat';+import { useGlobalStore } from '@/store/global';import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';import { useHeaderActionSize } from '@/styles/density';import { isMobileSurface } from '@/utils/mobileSurface';@@ -26,6 +28,7 @@ const HeaderInfo = (_props: PropsWithChildren) => {const { aid: agentId } = useActiveRouteParams();const router = useQueryRoute();const switchTopic = useChatStore((s) => s.switchTopic);+ const toggleCommandMenu = useGlobalStore((s) => s.toggleCommandMenu);const { allowed: canEditContent } = usePermission('edit_own_content');const { canEditResource } = useResourceAccess('agent', agentId);const { isAgentEditable } = useServerConfigStore(featureFlagsSelectors);@@ -44,15 +47,30 @@ const HeaderInfo = (_props: PropsWithChildren) => {<SideBarHeaderLayout{...back}left={<Agent />}+ // Everywhere but the macOS app the header's right side holds the panel+ // toggle, so search stays a nav row there. The macOS app moves that+ // toggle into the titlebar, which leaves room for search here.right={- showProfile && !isMobileSurface() ? (- <ActionIcon- aria-label={t('tab.profile')}- icon={SettingsIcon}- size={headerActionSmallSize}- onClick={openProfile}- />- ) : undefined+ <>+ {isMacDesktop && (+ <ActionIcon+ aria-label={t('tab.search')}+ icon={SearchIcon}+ size={headerActionSmallSize}+ title={t('tab.search')}+ onClick={() => toggleCommandMenu(true)}+ />+ )}+ {showProfile && !isMobileSurface() && (+ <ActionIcon+ aria-label={t('tab.profile')}+ icon={SettingsIcon}+ size={headerActionSmallSize}+ title={t('tab.profile')}+ onClick={openProfile}+ />+ )}+ </>}/><Nav showProfile={showProfile} onOpenProfile={openProfile} />diff --git a/src/features/NavPanel/SideBarHeaderLayout.tsx b/src/features/NavPanel/SideBarHeaderLayout.tsxindex 8ce6e79f517..cbbf93cd242 100644--- a/src/features/NavPanel/SideBarHeaderLayout.tsx+++ b/src/features/NavPanel/SideBarHeaderLayout.tsx@@ -133,7 +133,7 @@ const SideBarHeaderLayout = memo<SideBarHeaderLayoutProps>(style={{ paddingBlockStart: topInset }}>{leftContent}- <Flexbox horizontal align={'center'} gap={2} justify={'flex-end'}>+ <Flexbox horizontal align={'center'} flex={'none'} gap={2} justify={'flex-end'}>{showTogglePanelButton && <ToggleLeftPanelButton />}{right}</Flexbox>