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(task): add a create entry to list group headers, like board columns (#22136)

Rdmclin27be8e19ff322
diff --git a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
index 347ba448182..9f36893f990 100644
--- a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
+++ b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
@@ -255,6 +255,11 @@ const AgentTasksPage = memo<AgentTasksPageProps>(({ agentId, headerActions, proj
const hasFilter = !!filter;
const rawViewOptions = useGlobalStore(systemStatusSelectors.taskListViewOptions);
const viewOptions = useMemo(() => normalizeTaskListViewOptions(rawViewOptions), [rawViewOptions]);
+ // Group headers of the ordinary list offer the board's column create entry.
+ const groupCreateScope = useMemo(
+ () => (canCreateTask ? { agentId, projectId } : undefined),
+ [agentId, canCreateTask, projectId],
+ );
const useFetchTaskList = useTaskStore((s) => s.useFetchTaskList);
// Keep the sync handle for `error` + `mutate` (the error/Retry state) and the
// `queryKey` the rows are read by. Every scope splits automated work out of the ordinary tab — it is the
@@ -645,6 +650,7 @@ const AgentTasksPage = memo<AgentTasksPageProps>(({ agentId, headerActions, proj
/>
)}
<TaskList
+ createScope={groupCreateScope}
data={isTaskListInit || undefined}
emptyAction={filterEmptyAction}
emptyDescription={filterEmptyDescription}
diff --git a/src/features/AgentTasks/AgentTaskList/TaskList.tsx b/src/features/AgentTasks/AgentTaskList/TaskList.tsx
index 4c2c85e41a8..ca1f232aeb2 100644
--- a/src/features/AgentTasks/AgentTaskList/TaskList.tsx
+++ b/src/features/AgentTasks/AgentTaskList/TaskList.tsx
@@ -4,6 +4,7 @@ import {
AccordionItem,
AccordionRoot,
AccordionTrigger,
+ ActionIcon,
Block,
Center,
cssVar,
@@ -12,7 +13,8 @@ import {
Flexbox,
Text,
} from '@lobehub/ui';
-import { ClipboardCheckIcon } from 'lucide-react';
+import * as stylex from '@stylexjs/stylex';
+import { ClipboardCheckIcon, Plus } from 'lucide-react';
import type { ReactNode } from 'react';
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -25,8 +27,14 @@ import { taskListSelectors } from '@/store/task/selectors';
import { COMPLETE_TASK_LIST_MAX_ITEMS } from '@/store/task/slices/list/action';
import type { TaskListItem } from '@/store/task/slices/list/initialState';
+import { createTaskModal } from '../CreateTaskModal';
import type { TaskItemRouteScope } from '../features/AgentTaskItem';
import AgentTaskItem from '../features/AgentTaskItem';
+import {
+ getKanbanCreateTaskModalProps,
+ getTaskGroupCreateDefaults,
+ getTaskSubGroupCreateDefaults,
+} from './kanbanBoardModel';
import type { TaskGroupBy, TaskGroupMeta, TaskListViewOptions } from './listViewOptions';
import {
buildTaskRows,
@@ -47,7 +55,19 @@ import { flattenTaskListEntries } from './taskListVirtualModel';
import TaskRowIndent from './TaskRowIndent';
import { useClosestScrollParent } from './useClosestScrollParent';
+/** Scope inherited by tasks created from a group header. */
+export interface TaskListCreateScope {
+ agentId?: string;
+ projectId?: string;
+}
+
interface TaskListProps {
+ /**
+ * Offers a create entry on group headers (like the board's column headers),
+ * pinning the group's field on the new task. Omit where creating is not
+ * allowed or the collection cannot guarantee where a new task lands.
+ */
+ createScope?: TaskListCreateScope;
/**
* Settled signal — truthy once the list behind `queryKey` has a value in the
* store, `undefined` while unsettled. Derived from the same entry as the rows,
@@ -100,8 +120,37 @@ const normalizeGroupBy = (value: TaskGroupBy | string | undefined, fallback: Tas
return TASK_GROUP_BY_VALUES.has(value as TaskGroupBy) ? (value as TaskGroupBy) : fallback;
};
-const renderGroupTitle = (group: TaskGroupMeta, count: number, sub?: boolean) => (
- <Flexbox horizontal align={'center'} gap={8} justify={'space-between'}>
+const styles = stylex.create({
+ // A flex box centres the icon instead of a transform on the icon itself,
+ // which its own pressed / focused styles would override.
+ action: {
+ alignItems: 'center',
+ display: 'flex',
+ insetBlock: 0,
+ insetInlineEnd: 10,
+ position: 'absolute',
+ },
+ header: {
+ position: 'relative',
+ },
+});
+
+/** Room kept at the title's end for the create entry, so a sub-group rule stops before it. */
+const CREATE_ENTRY_GUTTER = 28;
+
+const renderGroupTitle = (
+ group: TaskGroupMeta,
+ count: number,
+ sub?: boolean,
+ withCreateEntry?: boolean,
+) => (
+ <Flexbox
+ horizontal
+ align={'center'}
+ gap={8}
+ justify={'space-between'}
+ style={withCreateEntry ? { marginInlineEnd: CREATE_ENTRY_GUTTER } : undefined}
+ >
<TaskGroupLabel group={group} />
<Text fontSize={12} type={'secondary'}>
{count}
@@ -116,26 +165,53 @@ const renderGroupTitle = (group: TaskGroupMeta, count: number, sub?: boolean) =>
* It renders no content: the rows it opens are the sibling virtual items.
*/
const TaskGroupHeader = memo<{
+ createScope?: TaskListCreateScope;
item: Extract<TaskListVirtualItem, { kind: 'group' | 'subGroup' }>;
onToggle: (key: string) => void;
-}>(({ item, onToggle }) => {
+}>(({ createScope, item, onToggle }) => {
+ const { t } = useTranslation('chat');
const sub = item.kind === 'subGroup';
+ const createDefaults = !createScope
+ ? undefined
+ : item.kind === 'subGroup'
+ ? getTaskSubGroupCreateDefaults(item.parentMeta, item.meta)
+ : getTaskGroupCreateDefaults(item.meta);
+ const openCreate = useCallback(() => {
+ if (!createScope || !createDefaults) return;
+ createTaskModal(getKanbanCreateTaskModalProps(createDefaults, createScope));
+ }, [createDefaults, createScope]);
+
return (
<div style={{ paddingTop: item.first ? 0 : sub ? 6 : 16 }}>
- <AccordionRoot
- indicatorPlacement={'end'}
- value={item.collapsed ? [] : [item.key]}
- variant={sub ? 'borderless' : 'filled'}
- onValueChange={() => onToggle(item.key)}
- >
- <AccordionItem value={item.key}>
- <AccordionHeader>
- <AccordionTrigger style={{ paddingBlock: sub ? 6 : 8, paddingInline: 14 }}>
- {renderGroupTitle(item.meta, item.count, sub)}
- </AccordionTrigger>
- </AccordionHeader>
- </AccordionItem>
- </AccordionRoot>
+ <div {...stylex.props(styles.header)}>
+ <AccordionRoot
+ indicatorPlacement={'start'}
+ value={item.collapsed ? [] : [item.key]}
+ variant={sub ? 'borderless' : 'filled'}
+ onValueChange={() => onToggle(item.key)}
+ >
+ <AccordionItem value={item.key}>
+ <AccordionHeader>
+ <AccordionTrigger style={{ paddingBlock: sub ? 6 : 8, paddingInline: 14 }}>
+ {renderGroupTitle(item.meta, item.count, sub, !!createDefaults)}
+ </AccordionTrigger>
+ </AccordionHeader>
+ </AccordionItem>
+ </AccordionRoot>
+ {createDefaults && (
+ // Outside the trigger so clicking it opens the modal without toggling
+ // the group; the collapse indicator sits at the start (like Linear),
+ // so the entry takes the header's far end.
+ <div {...stylex.props(styles.action)}>
+ <ActionIcon
+ icon={Plus}
+ size={'small'}
+ title={t('taskList.kanban.addTask')}
+ onClick={openCreate}
+ />
+ </div>
+ )}
+ </div>
</div>
);
});
@@ -154,6 +230,7 @@ const VIRTUAL_LIST_COMPONENTS: Components<TaskListVirtualItem, TaskListVirtualCo
const TaskList = memo<TaskListProps>((props) => {
const {
+ createScope,
data,
error,
filter,
@@ -320,7 +397,8 @@ const TaskList = memo<TaskListProps>((props) => {
const renderItem = useCallback(
(_index: number, item: TaskListVirtualItem) => {
- if (item.kind !== 'row') return <TaskGroupHeader item={item} onToggle={toggleCollapsed} />;
+ if (item.kind !== 'row')
+ return <TaskGroupHeader createScope={createScope} item={item} onToggle={toggleCollapsed} />;
return (
// Matches the 2px row gap the former Block wrapper gave the list.
<div style={{ paddingBlock: 1, paddingInline: 2 }}>
@@ -347,7 +425,7 @@ const TaskList = memo<TaskListProps>((props) => {
</div>
);
},
- [getSelectionOrder, routeScope, toggleCollapsed],
+ [createScope, getSelectionOrder, routeScope, toggleCollapsed],
);
const skeleton = (
diff --git a/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.test.ts b/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.test.ts
index aba64fae3d4..ec78c365e00 100644
--- a/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.test.ts
+++ b/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.test.ts
@@ -11,9 +11,12 @@ import {
getKanbanColumnHeaderVariant,
getKanbanCreateTaskModalProps,
getKanbanTaskPatch,
+ getTaskGroupCreateDefaults,
+ getTaskSubGroupCreateDefaults,
moveTaskBetweenKanbanGroups,
normalizeKanbanGroupBy,
} from './kanbanBoardModel';
+import type { TaskGroupMeta } from './listViewOptions';
const task = (
id: string,
@@ -348,4 +351,60 @@ describe('kanbanBoardModel', () => {
expect(getKanbanColumnCreateDefaults('member', memberColumn)).toBeUndefined();
});
});
+
+ describe('getTaskGroupCreateDefaults', () => {
+ const meta = (overrides: Partial<TaskGroupMeta>): TaskGroupMeta => ({
+ groupBy: 'status',
+ key: 'k',
+ label: 'l',
+ ...overrides,
+ });
+
+ it('offers creation only on the backlog status group', () => {
+ expect(getTaskGroupCreateDefaults(meta({ status: 'backlog' }))).toEqual({});
+ expect(getTaskGroupCreateDefaults(meta({ status: 'running' }))).toBeUndefined();
+ expect(getTaskGroupCreateDefaults(meta({ status: 'completed' }))).toBeUndefined();
+ });
+
+ it('pins the group priority, including "no priority"', () => {
+ expect(getTaskGroupCreateDefaults(meta({ groupBy: 'priority', priority: 2 }))).toEqual({
+ priority: 2,
+ });
+ expect(getTaskGroupCreateDefaults(meta({ groupBy: 'priority', priority: 0 }))).toEqual({
+ priority: 0,
+ });
+ });
+
+ it('pins the group agent and offers nothing on the unassigned group', () => {
+ expect(
+ getTaskGroupCreateDefaults(meta({ assigneeId: 'agent-1', groupBy: 'assignee' })),
+ ).toEqual({ assigneeAgentId: 'agent-1' });
+ expect(getTaskGroupCreateDefaults(meta({ groupBy: 'assignee' }))).toBeUndefined();
+ });
+
+ it('offers nothing on member, automation and ungrouped lists', () => {
+ expect(
+ getTaskGroupCreateDefaults(meta({ assigneeUserId: 'user-1', groupBy: 'member' })),
+ ).toBeUndefined();
+ expect(
+ getTaskGroupCreateDefaults(meta({ automationMode: 'schedule', groupBy: 'automationMode' })),
+ ).toBeUndefined();
+ expect(getTaskGroupCreateDefaults(meta({ groupBy: 'none' }))).toBeUndefined();
+ expect(getTaskGroupCreateDefaults(undefined)).toBeUndefined();
+ });
+
+ it('combines a sub-group with its parent only when both offer an entry', () => {
+ const backlog = meta({ status: 'backlog' });
+ const high = meta({ groupBy: 'priority', priority: 2 });
+ const agent = meta({ assigneeId: 'agent-1', groupBy: 'assignee' });
+
+ expect(getTaskSubGroupCreateDefaults(backlog, high)).toEqual({ priority: 2 });
+ expect(getTaskSubGroupCreateDefaults(high, agent)).toEqual({
+ assigneeAgentId: 'agent-1',
+ priority: 2,
+ });
+ expect(getTaskSubGroupCreateDefaults(meta({ status: 'running' }), high)).toBeUndefined();
+ expect(getTaskSubGroupCreateDefaults(high, meta({ groupBy: 'assignee' }))).toBeUndefined();
+ });
+ });
});
diff --git a/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.ts b/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.ts
index 5d3ef5339ca..8b3d3071407 100644
--- a/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.ts
+++ b/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.ts
@@ -176,6 +176,44 @@ export interface KanbanColumnCreateDefaults {
priority?: number;
}
+/**
+ * Whether a task group offers a create entry, and what the new task is pinned
+ * to. Shared by board columns and list group headers so both views offer the
+ * entry on the same groups. `undefined` means no entry: a task created there
+ * could not be guaranteed to land in that group.
+ */
+export const getTaskGroupCreateDefaults = (
+ groupMeta: TaskGroupMeta | undefined,
+): KanbanColumnCreateDefaults | undefined => {
+ switch (groupMeta?.groupBy) {
+ // New tasks start in backlog, so only that status group can receive one.
+ case 'status': {
+ return groupMeta.status === 'backlog' ? {} : undefined;
+ }
+ case 'priority': {
+ return { priority: groupMeta.priority ?? 0 };
+ }
+ // The unassigned group has no entry: the modal cannot pin "no agent".
+ case 'assignee': {
+ return groupMeta.assigneeId ? { assigneeAgentId: groupMeta.assigneeId } : undefined;
+ }
+ }
+};
+
+/**
+ * Create defaults of a sub-group: it must satisfy its parent group too, so the
+ * entry exists only when both levels offer one, and their pins are combined.
+ */
+export const getTaskSubGroupCreateDefaults = (
+ parentMeta: TaskGroupMeta | undefined,
+ subMeta: TaskGroupMeta | undefined,
+): KanbanColumnCreateDefaults | undefined => {
+ const parent = getTaskGroupCreateDefaults(parentMeta);
+ const sub = getTaskGroupCreateDefaults(subMeta);
+ if (!parent || !sub) return undefined;
+ return { ...parent, ...sub };
+};
+
/**
* Whether a column offers a create entry, and what the new task is pinned to.
* `undefined` means no entry: a task created there could not be guaranteed to
@@ -185,15 +223,9 @@ export const getKanbanColumnCreateDefaults = (
groupBy: TaskKanbanGroupBy,
column: KanbanColumnDefinition,
): KanbanColumnCreateDefaults | undefined => {
- if (groupBy === 'status' && column.key === 'backlog') return {};
- if (groupBy === 'priority' && column.groupMeta?.groupBy === 'priority') {
- return { priority: column.groupMeta.priority ?? 0 };
- }
- // The unassigned column has no entry: the modal cannot pin "no agent".
- if (groupBy === 'assignee' && column.groupMeta?.groupBy === 'assignee') {
- const { assigneeId } = column.groupMeta;
- return assigneeId ? { assigneeAgentId: assigneeId } : undefined;
- }
+ if (groupBy === 'status') return column.key === 'backlog' ? {} : undefined;
+ if (column.groupMeta?.groupBy !== groupBy) return undefined;
+ return getTaskGroupCreateDefaults(column.groupMeta);
};
/**
diff --git a/src/features/AgentTasks/AgentTaskList/taskListVirtualModel.ts b/src/features/AgentTasks/AgentTaskList/taskListVirtualModel.ts
index e1089d71b2f..9b10fc873a9 100644
--- a/src/features/AgentTasks/AgentTaskList/taskListVirtualModel.ts
+++ b/src/features/AgentTasks/AgentTaskList/taskListVirtualModel.ts
@@ -35,6 +35,8 @@ export type TaskListVirtualItem =
key: string;
kind: 'subGroup';
meta: TaskGroupMeta;
+ /** Meta of the group this sub-group splits; a task created here must fit both. */
+ parentMeta: TaskGroupMeta;
}
| {
key: string;
@@ -105,6 +107,7 @@ export const flattenTaskListEntries = (
key,
kind: 'subGroup',
meta: subGroup.meta,
+ parentMeta: entry.meta,
});
if (!subCollapsed) items.push(...rowItems(subGroup.rows, key, true));
});