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.

💄 style(task): move archive into a task detail header button (#22110)

Rdmclin2dcea9807a046
diff --git a/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.test.tsx b/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.test.tsx
index 478fc09d907..30410d69f9a 100644
--- a/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.test.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.test.tsx
@@ -1,7 +1,7 @@
/**
* @vitest-environment happy-dom
*/
-import { render } from '@testing-library/react';
+import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import type { ReactNode } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -15,6 +15,7 @@ interface MenuItem {
const mocks = vi.hoisted(() => ({
activeWorkspaceId: 'ws-1' as string | undefined,
+ archiveTask: vi.fn(),
confirmModal: vi.fn(),
currentUserId: 'user-1' as string | undefined,
deleteTask: vi.fn(),
@@ -26,7 +27,15 @@ const mocks = vi.hoisted(() => ({
activeTaskId: 'T-1' as string | undefined,
taskDetailMap: {
'T-1': { visibility: 'private' as 'private' | 'public' },
- } as Record<string, { createdByUserId?: string | null; visibility?: 'private' | 'public' }>,
+ } as Record<
+ string,
+ {
+ archivedAt?: string | null;
+ createdByUserId?: string | null;
+ status?: string;
+ visibility?: 'private' | 'public';
+ }
+ >,
},
transferItems: [
{ key: 'transfer-task', label: 'Move to…' },
@@ -49,6 +58,7 @@ vi.mock('@lobehub/ui', async (importOriginal) => {
async (importOriginal) => ({
...(await importOriginal<object>()),
confirmModal: (opts: unknown) => mocks.confirmModal(opts),
+ toast: { error: vi.fn(), success: vi.fn() },
}),
];
const merged: Record<string, unknown> = { ...actual };
@@ -115,6 +125,7 @@ vi.mock('@/store/task', () => ({
useTaskStore: (selector: (state: Record<string, unknown>) => unknown) =>
selector({
...mocks.taskState,
+ archiveTask: mocks.archiveTask,
deleteTask: mocks.deleteTask,
updateTaskVisibility: mocks.updateTaskVisibility,
}),
@@ -246,4 +257,63 @@ describe('TaskDetailHeaderActions', () => {
expect(opts.title).toBe('taskDetail.publishToWorkspace.confirmTitle');
expect(opts.okText).toBe('taskDetail.publishToWorkspace.confirmOk');
});
+
+ it('moves archive out of the menu into a header button left of the menu', () => {
+ render(<TaskDetailHeaderActions />);
+
+ expect(mocks.dropdownItems.map((item) => item?.key)).not.toContain('archive');
+ const button = screen.getByRole('button', { name: 'taskList.contextMenu.archive' });
+ const moreButton = screen.getAllByRole('button').at(-1);
+ expect(button).not.toBe(moreButton);
+ expect(
+ button.compareDocumentPosition(moreButton!) & Node.DOCUMENT_POSITION_FOLLOWING,
+ ).toBeTruthy();
+ });
+
+ it('keeps a single divider between groups once archive leaves the menu', () => {
+ render(<TaskDetailHeaderActions />);
+
+ const kinds = mocks.dropdownItems.map((item) => item?.key ?? item?.type);
+ expect(kinds.slice(-2)).toEqual(['divider', 'delete']);
+ kinds.forEach((kind, index) => {
+ if (kind === 'divider') expect(kinds[index + 1]).not.toBe('divider');
+ });
+ });
+
+ it('archives the task from the header button', async () => {
+ render(<TaskDetailHeaderActions />);
+
+ expect(
+ screen.getByRole('button', { name: 'taskList.contextMenu.archive' }),
+ ).not.toHaveAttribute('aria-disabled');
+
+ fireEvent.click(screen.getByRole('button', { name: 'taskList.contextMenu.archive' }));
+
+ await waitFor(() => expect(mocks.archiveTask).toHaveBeenCalledWith('T-1', true));
+ });
+
+ it('restores an archived task from the same button', async () => {
+ mocks.taskState.taskDetailMap = {
+ 'T-1': { archivedAt: '2026-11-01T00:00:00.000Z', visibility: 'private' },
+ };
+ render(<TaskDetailHeaderActions />);
+
+ fireEvent.click(screen.getByRole('button', { name: 'taskList.contextMenu.unarchive' }));
+
+ await waitFor(() => expect(mocks.archiveTask).toHaveBeenCalledWith('T-1', false));
+ });
+
+ it('keeps a blocked button focusable with its reason and makes clicks a no-op', () => {
+ mocks.taskState.taskDetailMap = { 'T-1': { status: 'running', visibility: 'private' } };
+ render(<TaskDetailHeaderActions />);
+
+ const button = screen.getByRole('button', { name: 'taskList.contextMenu.archive' });
+ // aria-disabled but not natively disabled, so keyboard users can focus it and read the reason.
+ expect(button).toHaveAttribute('aria-disabled', 'true');
+ expect(button).not.toBeDisabled();
+ expect(button).toHaveAttribute('aria-description', 'taskList.contextMenu.archiveBlocked');
+ fireEvent.click(button);
+
+ expect(mocks.archiveTask).not.toHaveBeenCalled();
+ });
});
diff --git a/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.tsx b/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.tsx
index 22d4b9b9ba5..c3573d26e10 100644
--- a/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.tsx
@@ -1,6 +1,7 @@
import {
ActionIcon,
confirmModal,
+ cssVar,
type DropdownItem,
DropdownMenu,
Icon,
@@ -22,6 +23,7 @@ import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';
import { useTaskTransferMenuItem } from '@/business/client/hooks/useTaskTransferMenuItem';
+import { DESKTOP_HEADER_ICON_SMALL_SIZE } from '@/const/layoutTokens';
import { FavoriteButton, useFavoriteMenuItem } from '@/features/Favorites';
import VisibilityConfirmContent from '@/features/VisibilityConfirmContent';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
@@ -91,6 +93,17 @@ const TaskDetailHeaderActions = memo(() => {
);
}, [archiveTask, canArchive, isArchived, t, taskId]);
+ // ActionIcon overwrites an `aria-disabled` prop with its own `disabled` state,
+ // so the blocked state is set on the element directly.
+ const archiveButtonRef = useCallback(
+ (node: HTMLButtonElement | null) => {
+ if (!node) return;
+ if (canArchive) node.removeAttribute('aria-disabled');
+ else node.setAttribute('aria-disabled', 'true');
+ },
+ [canArchive],
+ );
+
const triggerPublish = useCallback(() => {
if (!canEditTask) return;
if (!taskId) return;
@@ -184,15 +197,6 @@ const TaskDetailHeaderActions = memo(() => {
},
{ type: 'divider' },
...(favoriteMenuItem ? [favoriteMenuItem, { type: 'divider' as const }] : []),
- {
- desc: archiveDeniedKey && t(archiveDeniedKey),
- disabled: !canArchive,
- icon: <Icon icon={isArchived ? ArchiveRestoreIcon : ArchiveIcon} />,
- key: 'archive',
- label: t(isArchived ? 'taskList.contextMenu.unarchive' : 'taskList.contextMenu.archive'),
- onClick: toggleArchive,
- },
- { type: 'divider' },
{
danger: true,
disabled: !canEditTask,
@@ -264,10 +268,6 @@ const TaskDetailHeaderActions = memo(() => {
takesOver,
t,
triggerDelete,
- toggleArchive,
- isArchived,
- archiveDeniedKey,
- canArchive,
triggerPublish,
triggerMakePrivate,
canEditTask,
@@ -276,9 +276,28 @@ const TaskDetailHeaderActions = memo(() => {
if (!taskId) return null;
+ const archiveLabel = t(
+ isArchived ? 'taskList.contextMenu.unarchive' : 'taskList.contextMenu.archive',
+ );
+ const archiveDeniedReason = archiveDeniedKey ? t(archiveDeniedKey) : undefined;
+
return (
<>
{favoriteTarget && <FavoriteButton {...favoriteTarget} />}
+ {/* A blocked archive is aria-disabled but not natively disabled, so hover
+ and keyboard users can still read why; toggleArchive no-ops. */}
+ <ActionIcon
+ aria-description={archiveDeniedReason}
+ aria-label={archiveLabel}
+ color={canArchive ? undefined : cssVar.colorTextDisabled}
+ icon={isArchived ? ArchiveRestoreIcon : ArchiveIcon}
+ ref={archiveButtonRef}
+ size={DESKTOP_HEADER_ICON_SMALL_SIZE}
+ style={canArchive ? undefined : { cursor: 'not-allowed' }}
+ title={archiveDeniedReason ?? archiveLabel}
+ tooltipProps={{ placement: 'bottom' }}
+ onClick={() => void toggleArchive()}
+ />
<DropdownMenu items={menuItems}>
<ActionIcon icon={MoreHorizontal} size={'small'} />
</DropdownMenu>