Skip to content

🤯 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.

✨ feat: add full-expand toggle to WorkflowCollapse with three-level expansion (#13906)

Inneia98d113a80ee
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.test.tsx b/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.test.tsx
index e5f71eea6fd..efc410ae918 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.test.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.test.tsx
@@ -36,6 +36,9 @@ vi.mock('motion/react', () => ({
div: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
<div {...props}>{children}</div>
),
+ span: ({ children, ...props }: { children?: ReactNode; [key: string]: unknown }) => (
+ <span {...props}>{children}</span>
+ ),
},
}));
@@ -178,4 +181,56 @@ describe('WorkflowCollapse', () => {
expect(screen.getByText('(4s)')).toBeInTheDocument();
});
+
+ it('cycles expand levels via the toggle button', () => {
+ render(<WorkflowCollapse assistantMessageId="msg-1" blocks={makeBlocks()} />);
+
+ const toggleButton = screen.getByRole('button', { name: 'Expand fully' });
+ expect(getExpandedKeys()).toBe('["workflow"]');
+
+ act(() => {
+ toggleButton.click();
+ });
+
+ expect(getExpandedKeys()).toBe('["workflow"]');
+ expect(screen.getByRole('button', { name: 'Collapse' })).toBeInTheDocument();
+
+ act(() => {
+ screen.getByRole('button', { name: 'Collapse' }).click();
+ });
+
+ expect(getExpandedKeys()).toBe('["workflow"]');
+ expect(screen.getByRole('button', { name: 'Expand fully' })).toBeInTheDocument();
+ });
+
+ it('expands to semi when accordion header is clicked from collapsed', () => {
+ render(
+ <WorkflowCollapse
+ assistantMessageId="msg-1"
+ blocks={makeBlocks()}
+ defaultStreamingExpanded={false}
+ />,
+ );
+
+ expect(getExpandedKeys()).toBe('[]');
+ expect(screen.queryByRole('button', { name: 'Expand fully' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Collapse' })).not.toBeInTheDocument();
+ });
+
+ it('collapses to collapsed when accordion header is clicked from full', () => {
+ const { rerender } = render(
+ <WorkflowCollapse assistantMessageId="msg-1" blocks={makeBlocks()} />,
+ );
+
+ act(() => {
+ screen.getByRole('button', { name: 'Expand fully' }).click();
+ });
+
+ expect(screen.getByRole('button', { name: 'Collapse' })).toBeInTheDocument();
+
+ mockIsGenerating = false;
+ rerender(<WorkflowCollapse assistantMessageId="msg-1" blocks={makeBlocks()} />);
+
+ expect(getExpandedKeys()).toBe('["workflow"]');
+ });
});
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.tsx b/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.tsx
index 8a44c9d1a8e..618e2a917a6 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/WorkflowCollapse.tsx
@@ -1,7 +1,7 @@
import { type ChatToolPayloadWithResult } from '@lobechat/types';
import { Accordion, AccordionItem, Block, Flexbox, Icon, Text } from '@lobehub/ui';
import { cssVar } from 'antd-style';
-import { Check, HandIcon, X } from 'lucide-react';
+import { Check, HandIcon, Maximize2, Minimize2, X } from 'lucide-react';
import { AnimatePresence, m as motion } from 'motion/react';
import { type Key, memo, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -31,6 +31,12 @@ import {
import type { RenderableAssistantContentBlock } from './types';
import WorkflowExpandedList from './WorkflowExpandedList';
+const WORKFLOW_EXPAND_TOGGLE_ICON_SIZE = 12;
+const WORKFLOW_EXPAND_TOGGLE_TRANSITION = {
+ duration: 0.18,
+ ease: [0.4, 0, 0.2, 1],
+} as const;
+
interface WorkflowCollapseProps {
/** Assistant group message id (for generation state) */
assistantMessageId: string;
@@ -131,7 +137,9 @@ const WorkflowCollapse = memo<WorkflowCollapseProps>(
const durationText = totalWorkflowMs > 0 ? formatReasoningDuration(totalWorkflowMs) : undefined;
const streamingDefaultExpanded = defaultStreamingExpanded || pendingInterventionPresent;
- const [expanded, setExpanded] = useState(() => !allComplete && streamingDefaultExpanded);
+ const [expandLevel, setExpandLevel] = useState<'collapsed' | 'semi' | 'full'>(() =>
+ !allComplete && streamingDefaultExpanded ? 'semi' : 'collapsed',
+ );
const userOpenedRef = useRef(false);
const prevCompleteRef = useRef(allComplete);
@@ -141,22 +149,22 @@ const WorkflowCollapse = memo<WorkflowCollapseProps>(
if (!allComplete && wasComplete) {
userOpenedRef.current = false;
- setExpanded(streamingDefaultExpanded);
+ setExpandLevel(streamingDefaultExpanded ? 'semi' : 'collapsed');
return;
}
if (allComplete && !wasComplete && !userOpenedRef.current && allTools.length > 0) {
- setExpanded(false);
+ setExpandLevel('collapsed');
}
}, [allComplete, allTools.length, streamingDefaultExpanded]);
const streaming = !allComplete;
const forceExpanded = streaming && pendingInterventionPresent;
- const isExpanded = forceExpanded || expanded;
+ const isExpanded = forceExpanded || expandLevel !== 'collapsed';
useEffect(() => {
if (streaming && pendingInterventionPresent) {
- setExpanded(true);
+ setExpandLevel('semi');
}
}, [pendingInterventionPresent, streaming]);
@@ -250,10 +258,14 @@ const WorkflowCollapse = memo<WorkflowCollapseProps>(
const nowExpanded = keys.includes('workflow');
if (forceExpanded && !nowExpanded) return;
- setExpanded(nowExpanded);
- if (nowExpanded) userOpenedRef.current = true;
+ if (nowExpanded) {
+ setExpandLevel('semi');
+ userOpenedRef.current = true;
+ } else {
+ setExpandLevel('collapsed');
+ }
};
- const constrained = streaming && isExpanded;
+ const constrained = expandLevel === 'semi';
const { ref: scrollRef, handleScroll: handleAutoScroll } = useAutoScroll<HTMLDivElement>({
deps: [allTools.length],
@@ -273,8 +285,26 @@ const WorkflowCollapse = memo<WorkflowCollapseProps>(
<Icon color={cssVar.colorSuccess} icon={Check} />
);
+ const showExpandToggle = expandLevel !== 'collapsed';
+ const expandToggleLabel =
+ expandLevel === 'semi'
+ ? t('workflow.expandFull', { defaultValue: 'Expand fully' })
+ : t('workflow.collapse', { defaultValue: 'Collapse' });
+
+ const expandToggleIcon = expandLevel === 'semi' ? Maximize2 : Minimize2;
+
+ const handleToggleExpand = (e: React.MouseEvent) => {
+ e.stopPropagation();
+ if (expandLevel === 'semi') {
+ setExpandLevel('full');
+ userOpenedRef.current = true;
+ } else {
+ setExpandLevel('semi');
+ }
+ };
+
const title = (
- <Flexbox horizontal align="center" gap={6}>
+ <Flexbox horizontal align="center" gap={6} width="100%">
<Block
horizontal
align="center"
@@ -331,7 +361,13 @@ const WorkflowCollapse = memo<WorkflowCollapseProps>(
)}
</Flexbox>
) : (
- <Flexbox horizontal align="center" gap={6} style={{ minWidth: 0, overflow: 'hidden' }}>
+ <Flexbox
+ horizontal
+ align="center"
+ flex={1}
+ gap={6}
+ style={{ minWidth: 0, overflow: 'hidden' }}
+ >
<Text
type="secondary"
style={{
@@ -350,6 +386,43 @@ const WorkflowCollapse = memo<WorkflowCollapseProps>(
)}
</Flexbox>
)}
+ <AnimatePresence initial={false}>
+ {showExpandToggle && (
+ <motion.div
+ animate={{ opacity: 1, scale: 1, x: 0 }}
+ aria-label={expandToggleLabel}
+ exit={{ opacity: 0, scale: 0.9, x: 4 }}
+ initial={{ opacity: 0, scale: 0.9, x: 4 }}
+ role="button"
+ title={expandToggleLabel}
+ transition={WORKFLOW_EXPAND_TOGGLE_TRANSITION}
+ style={{
+ cursor: 'pointer',
+ flex: 'none',
+ marginInlineStart: 8,
+ padding: 2,
+ }}
+ onClick={handleToggleExpand}
+ >
+ <AnimatePresence initial={false} mode="wait">
+ <motion.span
+ animate={{ opacity: 1, rotate: 0, scale: 1 }}
+ exit={{ opacity: 0, rotate: 60, scale: 0.85 }}
+ initial={{ opacity: 0, rotate: -60, scale: 0.85 }}
+ key={expandLevel}
+ style={{ display: 'flex' }}
+ transition={WORKFLOW_EXPAND_TOGGLE_TRANSITION}
+ >
+ <Icon
+ color={cssVar.colorTextSecondary}
+ icon={expandToggleIcon}
+ size={WORKFLOW_EXPAND_TOGGLE_ICON_SIZE}
+ />
+ </motion.span>
+ </AnimatePresence>
+ </motion.div>
+ )}
+ </AnimatePresence>
</Flexbox>
);