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-board): open the create task modal from Kanban column + (#21020)

Rdmclin27254e730599f
diff --git a/src/features/AgentTasks/AgentTaskList/KanbanColumn.tsx b/src/features/AgentTasks/AgentTaskList/KanbanColumn.tsx
index c6299c5f6e9..de1c2ac78b0 100644
--- a/src/features/AgentTasks/AgentTaskList/KanbanColumn.tsx
+++ b/src/features/AgentTasks/AgentTaskList/KanbanColumn.tsx
@@ -4,16 +4,20 @@ import { type DropdownItem, DropdownMenu, Icon } from '@lobehub/ui';
import { ActionIcon, Skeleton, Text } from '@lobehub/ui/base-ui';
import { createStaticStyles, cx } from 'antd-style';
import { EyeOff, MoreHorizontal, Plus } from 'lucide-react';
-import { memo, useCallback, useMemo, useState } from 'react';
+import { memo, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import type { TaskKanbanGroupBy, TaskListItem } from '@/store/task/slices/list/initialState';
+import { createTaskModal } from '../CreateTaskModal';
import type { TaskItemRouteScope } from '../features/AgentTaskItem';
import AgentTaskItem from '../features/AgentTaskItem';
import TaskStatusIcon from '../features/TaskStatusIcon';
-import { getKanbanColumnHeaderVariant, type KanbanColumnCreateDefaults } from './kanbanBoardModel';
-import KanbanInlineCreate from './KanbanInlineCreate';
+import {
+ getKanbanColumnHeaderVariant,
+ getKanbanCreateTaskModalProps,
+ type KanbanColumnCreateDefaults,
+} from './kanbanBoardModel';
import type { TaskGroupMeta } from './listViewOptions';
import TaskGroupLabel from './TaskGroupLabel';
import TaskItemSkeleton from './TaskItemSkeleton';
@@ -228,10 +232,11 @@ const KanbanColumn = memo<KanbanColumnProps>(
});
const isDragActive = !!active;
- const [creating, setCreating] = useState(false);
- const openCreate = useCallback(() => setCreating(true), []);
- const closeCreate = useCallback(() => setCreating(false), []);
const canCreate = !!createDefaults;
+ const openCreate = useCallback(() => {
+ if (!createDefaults) return;
+ createTaskModal(getKanbanCreateTaskModalProps(createDefaults, { agentId, projectId }));
+ }, [agentId, createDefaults, projectId]);
// Don't highlight if dragging a card that's already in this column
const activeTask = active?.data.current?.task as TaskListItem | undefined;
@@ -308,14 +313,6 @@ const KanbanColumn = memo<KanbanColumnProps>(
</div>
</div>
<div className={styles.body}>
- {creating && createDefaults && (
- <KanbanInlineCreate
- agentId={agentId}
- defaults={createDefaults}
- projectId={projectId}
- onClose={closeCreate}
- />
- )}
{loading ? (
Array.from({ length: 3 }).map((_, index) => (
<div className={cardStyles.card} key={`kanban-skeleton-${columnKey}-${index}`}>
@@ -326,7 +323,7 @@ const KanbanColumn = memo<KanbanColumnProps>(
tasks.map((task) => (
<DraggableTaskCard key={task.identifier} routeScope={routeScope} task={task} />
))
- ) : creating ? null : canCreate ? (
+ ) : canCreate ? (
<div
className={cx(styles.addPill, styles.action, 'kanban-col-action')}
title={t('taskList.kanban.addTask')}
diff --git a/src/features/AgentTasks/AgentTaskList/KanbanInlineCreate.tsx b/src/features/AgentTasks/AgentTaskList/KanbanInlineCreate.tsx
deleted file mode 100644
index 25dfa28a50e..00000000000
--- a/src/features/AgentTasks/AgentTaskList/KanbanInlineCreate.tsx
+++ /dev/null
@@ -1,171 +0,0 @@
-'use client';
-
-import { Flexbox } from '@lobehub/ui';
-import { Button, Text, TextArea, toast } from '@lobehub/ui/base-ui';
-import { createStaticStyles } from 'antd-style';
-import { type KeyboardEvent, memo, useCallback, useState } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';
-import { useTaskStore } from '@/store/task';
-
-import AssigneeAvatar from '../features/AssigneeAvatar';
-import TaskPriorityTag from '../features/TaskPriorityTag';
-import { useAgentDisplayMeta } from '../shared/useAgentDisplayMeta';
-import { useAgentVisibility } from '../shared/useAgentVisibility';
-import type { KanbanColumnCreateDefaults } from './kanbanBoardModel';
-
-const PRIORITY_LABEL_KEYS = ['none', 'urgent', 'high', 'normal', 'low'] as const;
-
-const styles = createStaticStyles(({ css, cssVar }) => ({
- chip: css`
- display: inline-flex;
- gap: 6px;
- align-items: center;
-
- height: 24px;
- padding-inline: 8px;
- border-radius: ${cssVar.borderRadius};
-
- background: ${cssVar.colorFillTertiary};
- `,
- container: css`
- flex: none;
-
- padding: 8px;
- border: 1px solid ${cssVar.colorPrimaryBorder};
- border-radius: ${cssVar.borderRadiusLG};
-
- background: ${cssVar.colorBgElevated};
- box-shadow:
- 0 1px 2px rgb(0 0 0 / 4%),
- 0 2px 6px rgb(0 0 0 / 3%);
- `,
-}));
-
-interface KanbanInlineCreateProps {
- /** Board scope agent, used when the column does not pin one. */
- agentId?: string;
- defaults: KanbanColumnCreateDefaults;
- onClose: () => void;
- projectId?: string;
-}
-
-/**
- * Quick-create composer rendered inside a Kanban column. The column's pinned
- * fields are shown as read-only chips, so the new task lands in this column.
- */
-const KanbanInlineCreate = memo<KanbanInlineCreateProps>(
- ({ agentId, defaults, onClose, projectId }) => {
- const { t } = useTranslation(['chat', 'common']);
- const createTask = useTaskStore((s) => s.createTask);
- const activeWorkspaceId = useActiveWorkspaceId();
-
- const [title, setTitle] = useState('');
- const [submitting, setSubmitting] = useState(false);
-
- const assigneeAgentId = defaults.assigneeAgentId ?? agentId;
- const agentMeta = useAgentDisplayMeta(defaults.assigneeAgentId);
- // A private agent can only run private tasks; otherwise workspace tasks
- // default to workspace-visible, same as the create modal.
- const isPrivateAgent = useAgentVisibility(assigneeAgentId) === 'private';
-
- const handleSubmit = useCallback(async () => {
- const name = title.trim();
- if (!name || submitting) return;
-
- setSubmitting(true);
- try {
- const result = await createTask({
- assigneeAgentId,
- instruction: name,
- name,
- priority: defaults.priority || undefined,
- projectId,
- visibility: activeWorkspaceId ? (isPrivateAgent ? 'private' : 'public') : undefined,
- });
- if (result) onClose();
- } catch {
- toast.error(t('createTask.createFailed'));
- } finally {
- setSubmitting(false);
- }
- }, [
- activeWorkspaceId,
- assigneeAgentId,
- createTask,
- defaults.priority,
- isPrivateAgent,
- onClose,
- projectId,
- submitting,
- t,
- title,
- ]);
-
- const handleKeyDown = useCallback(
- (e: KeyboardEvent<HTMLTextAreaElement>) => {
- if (e.nativeEvent.isComposing) return;
- if (e.key === 'Enter' && !e.shiftKey) {
- e.preventDefault();
- void handleSubmit();
- } else if (e.key === 'Escape') {
- e.preventDefault();
- onClose();
- }
- },
- [handleSubmit, onClose],
- );
-
- return (
- <Flexbox className={styles.container} data-testid={'kanban-inline-create'} gap={8}>
- <TextArea
- autoFocus
- autoSize={{ maxRows: 6, minRows: 1 }}
- disabled={submitting}
- placeholder={t('createTask.titlePlaceholder')}
- value={title}
- variant={'borderless'}
- onChange={(e) => setTitle(e.target.value)}
- onKeyDown={handleKeyDown}
- />
- <Flexbox horizontal align={'center'} gap={6} justify={'space-between'}>
- <Flexbox horizontal align={'center'} gap={4} style={{ minWidth: 0 }}>
- {defaults.priority !== undefined && (
- <span className={styles.chip}>
- <TaskPriorityTag disableDropdown priority={defaults.priority} size={14} />
- <Text fontSize={12}>
- {t(`taskDetail.priority.${PRIORITY_LABEL_KEYS[defaults.priority]}` as never)}
- </Text>
- </span>
- )}
- {defaults.assigneeAgentId && (
- <span className={styles.chip}>
- <AssigneeAvatar agentId={defaults.assigneeAgentId} size={16} />
- <Text ellipsis fontSize={12}>
- {agentMeta?.title}
- </Text>
- </span>
- )}
- </Flexbox>
- <Flexbox horizontal gap={4}>
- <Button size={'small'} type={'text'} onClick={onClose}>
- {t('cancel', { ns: 'common' })}
- </Button>
- <Button
- disabled={!title.trim()}
- loading={submitting}
- size={'small'}
- type={'primary'}
- onClick={() => void handleSubmit()}
- >
- {t('createTask.submit')}
- </Button>
- </Flexbox>
- </Flexbox>
- </Flexbox>
- );
- },
-);
-
-export default KanbanInlineCreate;
diff --git a/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.test.ts b/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.test.ts
index a6ebcb92059..aba64fae3d4 100644
--- a/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.test.ts
+++ b/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.test.ts
@@ -9,6 +9,7 @@ import {
getKanbanAssigneeUpdate,
getKanbanColumnCreateDefaults,
getKanbanColumnHeaderVariant,
+ getKanbanCreateTaskModalProps,
getKanbanTaskPatch,
moveTaskBetweenKanbanGroups,
normalizeKanbanGroupBy,
@@ -274,6 +275,32 @@ describe('kanbanBoardModel', () => {
});
});
+ describe('getKanbanCreateTaskModalProps', () => {
+ it('prefills the column priority in the create task modal', () => {
+ expect(getKanbanCreateTaskModalProps({ priority: 4 }, { projectId: 'project-1' })).toEqual({
+ agentId: undefined,
+ defaultPriority: 4,
+ lockAssignee: false,
+ projectId: 'project-1',
+ showInlineToggle: false,
+ });
+ });
+
+ it('prefills the column assignee over the board agent', () => {
+ expect(
+ getKanbanCreateTaskModalProps({ assigneeAgentId: 'agent-col' }, { agentId: 'agent-board' }),
+ ).toMatchObject({ agentId: 'agent-col', lockAssignee: true });
+ });
+
+ it('falls back to the board agent and locks it on an agent-scoped board', () => {
+ expect(getKanbanCreateTaskModalProps({}, { agentId: 'agent-board' })).toMatchObject({
+ agentId: 'agent-board',
+ defaultPriority: undefined,
+ lockAssignee: true,
+ });
+ });
+ });
+
describe('getKanbanColumnCreateDefaults', () => {
it('pins the column priority on tasks created from a priority column', () => {
const groups = [
diff --git a/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.ts b/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.ts
index 7c63b26926f..5d3ef5339ca 100644
--- a/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.ts
+++ b/src/features/AgentTasks/AgentTaskList/kanbanBoardModel.ts
@@ -6,6 +6,7 @@ import type {
TaskListItem,
} from '@/store/task/slices/list/initialState';
+import type { CreateTaskContentProps } from '../CreateTaskModal/CreateTaskContent';
import type { TaskGroupBy, TaskGroupMeta } from './listViewOptions';
import {
getTaskAssigneeGroupMeta,
@@ -195,6 +196,23 @@ export const getKanbanColumnCreateDefaults = (
}
};
+/**
+ * Props for the create task modal opened from a column. The column's pinned
+ * fields are prefilled, so an untouched modal creates the task in this column.
+ */
+export const getKanbanCreateTaskModalProps = (
+ defaults: KanbanColumnCreateDefaults,
+ scope: { agentId?: string; projectId?: string },
+): CreateTaskContentProps => ({
+ agentId: defaults.assigneeAgentId ?? scope.agentId,
+ defaultPriority: defaults.priority,
+ // An agent-scoped board only holds that agent's tasks.
+ lockAssignee: !!scope.agentId,
+ projectId: scope.projectId,
+ // The board has no inline entry to minimize into.
+ showInlineToggle: false,
+});
+
export const canDropTaskIntoKanbanColumn = (
task: TaskListItem,
groupBy: TaskKanbanGroupBy,
diff --git a/src/features/AgentTasks/CreateTaskModal/CreateTaskContent.tsx b/src/features/AgentTasks/CreateTaskModal/CreateTaskContent.tsx
index 6393e990bda..5b42dcd1488 100644
--- a/src/features/AgentTasks/CreateTaskModal/CreateTaskContent.tsx
+++ b/src/features/AgentTasks/CreateTaskModal/CreateTaskContent.tsx
@@ -38,6 +38,8 @@ import { useTitleEnterToInstruction } from './useTitleEnterToInstruction';
export interface CreateTaskContentProps {
agentId?: string;
+ /** Initial priority, e.g. the Kanban priority column the modal was opened from. */
+ defaultPriority?: number;
/**
* Locks the assignee to `agentId` and hides the agent picker. Used on the
* agent-scoped task list where every task belongs to that agent.
@@ -53,7 +55,14 @@ export interface CreateTaskContentProps {
}
const CreateTaskContent = memo<CreateTaskContentProps>(
- ({ agentId, lockAssignee, onCreated, projectId, showInlineToggle = true }) => {
+ ({
+ agentId,
+ defaultPriority = 0,
+ lockAssignee,
+ onCreated,
+ projectId,
+ showInlineToggle = true,
+ }) => {
const { t } = useTranslation('chat');
const { close } = useModalContext();
const { allowed: canCreateTask, reason } = usePermission('create_content');
@@ -65,7 +74,7 @@ const CreateTaskContent = memo<CreateTaskContentProps>(
const activeWorkspaceId = useActiveWorkspaceId();
const [title, setTitle] = useState('');
- const [priority, setPriority] = useState(0);
+ const [priority, setPriority] = useState(defaultPriority);
const [assigneeAgentId, setAssigneeAgentId] = useState<string | undefined>(agentId);
const [assigneeUserId, setAssigneeUserId] = useState<string | undefined>();
// Where this task will run, if not simply wherever the assignee runs.