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.

🐛 fix(task): keep the Archive button usable once a task stops running (#22321)

Rdmclin20b38bd63db1e
diff --git a/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.test.tsx b/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.test.tsx
index 0872cc8a67e..78f1d5f4e57 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 { fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
import type { ReactNode } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -14,6 +14,10 @@ interface MenuItem {
}
const mocks = vi.hoisted(() => ({
+ /** Subscribers of the mocked task store, so a state change re-renders like zustand. */
+ storeListeners: new Set<() => void>(),
+ storeVersion: 0,
+ toastInfo: vi.fn(),
activeWorkspaceId: 'ws-1' as string | undefined,
archiveTask: vi.fn(),
confirmModal: vi.fn(),
@@ -58,7 +62,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() },
+ toast: { error: vi.fn(), info: mocks.toastInfo, success: vi.fn() },
}),
];
const merged: Record<string, unknown> = { ...actual };
@@ -121,15 +125,31 @@ vi.mock('@/hooks/useAppOrigin', () => ({
useAppOrigin: () => 'https://example.com',
}));
-vi.mock('@/store/task', () => ({
- useTaskStore: (selector: (state: Record<string, unknown>) => unknown) =>
- selector({
- ...mocks.taskState,
- archiveTask: mocks.archiveTask,
- deleteTask: mocks.deleteTask,
- updateTaskVisibility: mocks.updateTaskVisibility,
- }),
-}));
+vi.mock('@/store/task', async () => {
+ const { useSyncExternalStore } = await import('react');
+ const subscribe = (listener: () => void) => {
+ mocks.storeListeners.add(listener);
+ return () => mocks.storeListeners.delete(listener);
+ };
+ return {
+ useTaskStore: (selector: (state: Record<string, unknown>) => unknown) => {
+ useSyncExternalStore(subscribe, () => mocks.storeVersion);
+ return selector({
+ ...mocks.taskState,
+ archiveTask: mocks.archiveTask,
+ deleteTask: mocks.deleteTask,
+ updateTaskVisibility: mocks.updateTaskVisibility,
+ });
+ },
+ };
+});
+
+const setTaskDetailMap = (map: typeof mocks.taskState.taskDetailMap) =>
+ act(() => {
+ mocks.taskState.taskDetailMap = map;
+ mocks.storeVersion += 1;
+ mocks.storeListeners.forEach((listener) => listener());
+ });
describe('TaskDetailHeaderActions', () => {
beforeEach(() => {
@@ -296,17 +316,36 @@ describe('TaskDetailHeaderActions', () => {
await waitFor(() => expect(mocks.archiveTask).toHaveBeenCalledWith('T-1', false));
});
- it('keeps a blocked button focusable with its reason and makes clicks a no-op', () => {
+ // ActionIcon styles `[aria-disabled="true"]` with `pointer-events: none`, which
+ // swallows the hover that shows the reason and, when left behind, every click.
+ it('keeps a blocked button hoverable and answers a click with the reason', () => {
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.toHaveAttribute('aria-disabled');
expect(button).not.toBeDisabled();
expect(button).toHaveAttribute('aria-description', 'taskList.contextMenu.archiveBlocked');
+ expect(button).toHaveStyle({ cursor: 'not-allowed' });
fireEvent.click(button);
expect(mocks.archiveTask).not.toHaveBeenCalled();
+ expect(mocks.toastInfo).toHaveBeenCalledWith('taskList.contextMenu.archiveBlocked');
+ });
+
+ // Locks the behavior, not the production trigger: happy-dom ignores
+ // `pointer-events`, and the stale attribute never reproduced here.
+ it('lets the same mounted button archive once the running task completes', async () => {
+ mocks.taskState.taskDetailMap = { 'T-1': { status: 'running', visibility: 'private' } };
+ render(<TaskDetailHeaderActions />);
+
+ setTaskDetailMap({ 'T-1': { status: 'completed', visibility: 'private' } });
+
+ const button = screen.getByRole('button', { name: 'taskList.contextMenu.archive' });
+ expect(button).not.toHaveAttribute('aria-disabled');
+ expect(button).not.toHaveAttribute('aria-description');
+ fireEvent.click(button);
+
+ await waitFor(() => expect(mocks.archiveTask).toHaveBeenCalledWith('T-1', true));
});
});
diff --git a/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.tsx b/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.tsx
index c3573d26e10..abd12055953 100644
--- a/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/TaskDetailHeaderActions.tsx
@@ -77,7 +77,12 @@ const TaskDetailHeaderActions = memo(() => {
}, [canEditTask, taskId, t, deleteTask, navigate]);
const toggleArchive = useCallback(async () => {
- if (!canArchive || !taskId) return;
+ if (!taskId) return;
+ if (!canArchive) {
+ // Touch users get no hover tooltip, so a blocked click says why.
+ if (archiveDeniedKey) toast.info(t(archiveDeniedKey));
+ return;
+ }
try {
await archiveTask(taskId, !isArchived);
} catch (error) {
@@ -91,18 +96,7 @@ const TaskDetailHeaderActions = memo(() => {
: 'taskList.contextMenu.archiveSuccess',
),
);
- }, [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],
- );
+ }, [archiveDeniedKey, archiveTask, canArchive, isArchived, t, taskId]);
const triggerPublish = useCallback(() => {
if (!canEditTask) return;
@@ -284,14 +278,15 @@ const TaskDetailHeaderActions = memo(() => {
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. */}
+ {/* A blocked archive stays enabled so hover and keyboard users can read why;
+ a click only repeats the reason. Never mark it `aria-disabled`: ActionIcon styles that
+ with `pointer-events: none`, which hides the reason and, when the attribute
+ outlives the block, leaves the button dead until a refresh. */}
<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}