🤯 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
🐛 fix(agent-document): let the header toggle collapse the topic panel (#21278)
Rdmclin2ff3dce269b7b
diff --git a/src/features/AgentDocumentPage/Header/index.tsx b/src/features/AgentDocumentPage/Header/index.tsxindex 0bb0fac2b3b..3058f103245 100644--- a/src/features/AgentDocumentPage/Header/index.tsx+++ b/src/features/AgentDocumentPage/Header/index.tsx@@ -26,7 +26,10 @@ interface HeaderProps {itemError?: unknown;onBack: () => void;onDeleted: () => void;+ onToggleTopicPanel?: () => void;title?: string;+ /** Topic panel visibility; omit while the page has no topic panel. */+ topicPanelExpand?: boolean;updatedAt?: Date | string | null;}@@ -40,6 +43,8 @@ const Header = memo<HeaderProps>(onBack,onDeleted,title,+ topicPanelExpand,+ onToggleTopicPanel,updatedAt,}) => {const { t } = useTranslation(['file', 'chat']);@@ -95,7 +100,13 @@ const Header = memo<HeaderProps>(<Flexbox horizontal align={'center'} gap={4}>{documentId && !fileBacked && <AutoSaveHint documentId={documentId} />}{documentId && !fileBacked && <ShareButton documentId={documentId} />}- <ToggleRightPanelButton hideWhenExpanded />+ {topicPanelExpand !== undefined && (+ <ToggleRightPanelButton+ hideWhenExpanded+ expand={topicPanelExpand}+ onToggle={onToggleTopicPanel}+ />+ )}</Flexbox>}/>diff --git a/src/features/AgentDocumentPage/index.test.tsx b/src/features/AgentDocumentPage/index.test.tsxindex f99f1d8ca6a..dd1772a6ae8 100644--- a/src/features/AgentDocumentPage/index.test.tsx+++ b/src/features/AgentDocumentPage/index.test.tsx@@ -1,7 +1,7 @@/*** @vitest-environment happy-dom*/-import { render, screen } from '@testing-library/react';+import { fireEvent, render, screen } from '@testing-library/react';import type { ReactNode } from 'react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -35,8 +35,10 @@ vi.mock('@/features/PageEditor', () => ({}));vi.mock('@/features/RightPanel', () => ({- default: ({ children }: { children?: ReactNode }) => (- <aside data-testid="right-panel">{children}</aside>+ default: ({ children, expand }: { children?: ReactNode; expand?: boolean }) => (+ <aside data-expand={String(expand)} data-testid="right-panel">+ {children}+ </aside>),}));@@ -47,7 +49,15 @@ const headerProps = vi.hoisted(() => ({vi.mock('./Header', () => ({default: (props: Record<string, unknown>) => {headerProps.current = props;- return <div data-document-id={props.documentId as string | undefined} data-testid="header" />;+ return (+ <div data-document-id={props.documentId as string | undefined} data-testid="header">+ <button+ data-testid="toggle-topic-panel"+ type="button"+ onClick={props.onToggleTopicPanel as () => void}+ />+ </div>+ );},}));@@ -98,7 +108,15 @@ const panelProps = vi.hoisted(() => ({vi.mock('@/features/FloatingChatPanel', () => ({default: (props: Record<string, unknown>) => {panelProps.current = props;- return <div data-testid="floating-chat-panel" />;+ return (+ <div data-testid="floating-chat-panel">+ <button+ data-testid="collapse-topic-panel"+ type="button"+ onClick={props.onCollapse as () => void}+ />+ </div>+ );},}));@@ -226,4 +244,30 @@ describe('AgentDocumentPage', () => {documentId: 'docs_abc',});});++ /** @example The topic panel starts collapsed; the header opens it and the panel toolbar closes it. */+ it('opens the topic panel from the header and collapses it from the panel toolbar', () => {+ // ROOT CAUSE:+ // The panel was pinned open with `expand` while the header toggle read and wrote+ // the global `showRightPanel`, so a click only hid the button itself. The page now+ // owns one visibility state: the header toggle opens it, the panel toolbar closes it.+ render(<AgentDocumentPage documentId="docs_abc" />);++ expect(screen.getByTestId('right-panel').dataset.expand).toBe('false');+ expect(headerProps.current?.topicPanelExpand).toBe(false);++ fireEvent.click(screen.getByTestId('toggle-topic-panel'));+ expect(screen.getByTestId('right-panel').dataset.expand).toBe('true');+ expect(headerProps.current?.topicPanelExpand).toBe(true);++ fireEvent.click(screen.getByTestId('collapse-topic-panel'));+ expect(screen.getByTestId('right-panel').dataset.expand).toBe('false');+ expect(headerProps.current?.topicPanelExpand).toBe(false);+ });++ it('hides the topic panel toggle while the page has no topic panel', () => {+ docChatTopicState.current = { error: undefined, isLoading: true, topicId: undefined };+ render(<AgentDocumentPage documentId="docs_abc" />);+ expect(headerProps.current?.topicPanelExpand).toBeUndefined();+ });});diff --git a/src/features/AgentDocumentPage/index.tsx b/src/features/AgentDocumentPage/index.tsxindex 4d46388fe67..c8e8f91d470 100644--- a/src/features/AgentDocumentPage/index.tsx+++ b/src/features/AgentDocumentPage/index.tsx@@ -2,7 +2,7 @@import { EditorProvider } from '@lobehub/editor/react';import { Flexbox } from '@lobehub/ui';-import { memo, useCallback, useEffect, useMemo } from 'react';+import { memo, useCallback, useEffect, useMemo, useState } from 'react';import { useParams } from 'react-router';import AsyncError from '@/components/AsyncError';@@ -74,6 +74,14 @@ const AgentDocumentPage = memo<AgentDocumentPageProps>(({ documentId }) => {[chatAgentId, docChatTopicId, documentId],);+ // The topic panel owns its own visibility instead of the global+ // `showRightPanel`: it starts collapsed on every document. The header button+ // opens it, and the panel toolbar collapses it, mirroring the task Copilot.+ const [topicPanelExpand, setTopicPanelExpand] = useState(false);+ const toggleTopicPanel = useCallback(() => setTopicPanelExpand((expand) => !expand), []);+ const collapseTopicPanel = useCallback(() => setTopicPanelExpand(false), []);+ const hasTopicPanel = !!chatAgentId && !!docChatTopicId;+const backToChat = useCallback(() => navigate(agentId ? `/agent/${agentId}` : '/agent'),[agentId, navigate],@@ -113,9 +121,11 @@ const AgentDocumentPage = memo<AgentDocumentPageProps>(({ documentId }) => {fileBacked={isFile}itemError={itemError}title={title}+ topicPanelExpand={hasTopicPanel ? topicPanelExpand : undefined}updatedAt={item?.updatedAt}onBack={backToChat}onDeleted={backToDocs}+ onToggleTopicPanel={toggleTopicPanel}/>),[@@ -128,6 +138,9 @@ const AgentDocumentPage = memo<AgentDocumentPageProps>(({ documentId }) => {itemError,isFile,title,+ hasTopicPanel,+ topicPanelExpand,+ toggleTopicPanel,],);@@ -175,8 +188,14 @@ const AgentDocumentPage = memo<AgentDocumentPageProps>(({ documentId }) => {/>)}</Flexbox>- {chatAgentId && docChatTopicId && (- <RightPanel expand defaultWidth={400} maxWidth={720} minWidth={320}>+ {hasTopicPanel && (+ <RightPanel+ defaultWidth={400}+ expand={topicPanelExpand}+ maxWidth={720}+ minWidth={320}+ onExpandChange={setTopicPanelExpand}+ ><Flexbox flex={1} height={'100%'} justify={'flex-end'} style={{ minHeight: 0 }}><FloatingChatPanelagentDocumentId={item?.id}@@ -185,6 +204,7 @@ const AgentDocumentPage = memo<AgentDocumentPageProps>(({ documentId }) => {key={`${chatAgentId}:${docChatTopicId}:${documentId}`}mode="embedded"topicId={docChatTopicId}+ onCollapse={collapseTopicPanel}/></Flexbox></RightPanel>diff --git a/src/features/FloatingChatPanel/index.tsx b/src/features/FloatingChatPanel/index.tsxindex 242e6939107..a3c2fd2e823 100644--- a/src/features/FloatingChatPanel/index.tsx+++ b/src/features/FloatingChatPanel/index.tsx@@ -107,6 +107,8 @@ export interface FloatingChatPanelProps {maxHeight?: number;minHeight?: number;mode?: 'embedded' | 'overlay';+ /** Embedded mode only: collapse the hosting side panel from the toolbar. */+ onCollapse?: () => void;onOpenChange?: (open: boolean) => void;onSnapPointChange?: (point: number) => void;open?: boolean;@@ -142,6 +144,7 @@ const FloatingChatPanel = memo<FloatingChatPanelProps>(hooks,defaultOpen = false,mode = 'overlay',+ onCollapse,width = '100%',@@ -270,7 +273,11 @@ const FloatingChatPanel = memo<FloatingChatPanelProps>({isEmbedded ? (<><PageAgentPanelOverrideProvider defaultExpand>- <CopilotToolbar topicId={activeTopicId} onTopicChange={setEmbeddedTopicId} />+ <CopilotToolbar+ topicId={activeTopicId}+ onCollapse={onCollapse}+ onTopicChange={setEmbeddedTopicId}+ /></PageAgentPanelOverrideProvider><ChatBody /><InputRow isCollapsed={false} showExpandBar={false} onExpand={expand} />diff --git a/src/features/PageEditor/Copilot/Toolbar.tsx b/src/features/PageEditor/Copilot/Toolbar.tsxindex 49339cc2cc6..c181f759690 100644--- a/src/features/PageEditor/Copilot/Toolbar.tsx+++ b/src/features/PageEditor/Copilot/Toolbar.tsx@@ -14,11 +14,13 @@ import { usePageAgentPanelControl, usePageAgentPanelOverride } from '../RightPanimport TopicItem from './TopicSelector/TopicItem';interface CopilotToolbarProps {+ /** Collapse the hosting panel; when set, the close button calls this instead of the page-agent panel. */+ onCollapse?: () => void;onTopicChange?: (topicId: string | null) => void;topicId?: string | null;}-const CopilotToolbar = memo<CopilotToolbarProps>(({ onTopicChange, topicId }) => {+const CopilotToolbar = memo<CopilotToolbarProps>(({ onCollapse, onTopicChange, topicId }) => {const { t } = useTranslation('topic');const [topicPopoverOpen, setTopicPopoverOpen] = useState(false);const agentId = useConversationStore(conversationSelectors.agentId);@@ -112,11 +114,11 @@ const CopilotToolbar = memo<CopilotToolbarProps>(({ onTopicChange, topicId }) =>/></Popover>)}- {!hasOverride && (+ {(onCollapse || !hasOverride) && (<ActionIconicon={PanelRightCloseIcon}size={DESKTOP_HEADER_ICON_SMALL_SIZE}- onClick={() => togglePageAgentPanel()}+ onClick={() => (onCollapse ? onCollapse() : togglePageAgentPanel())}/>)}</>