AP1.5d: Rekursive Tasks im Plan-Knoten Arbeit.
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Failing after 1m57s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Failing after 1m57s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
parent_task_id mit Validierung und Roll-up; aufklappbarer Task-Baum unter Arbeitspaketen im Plan-Modus (max. 3 UI-Ebenen). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a6fc86025c
commit
ba28a86fe5
13 files changed
+909
-54
No files matched your search
@@ -0,0 +1,194 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import {
|
||||
createActionTask,
|
||||
deleteTask,
|
||||
listActionTasks,
|
||||
updateTask,
|
||||
} from '../api/tasks.js'
|
||||
import { buildTasksByParent } from '../utils/taskTree.js'
|
||||
import { Modal } from './Modal.jsx'
|
||||
import { TaskForm, TaskTreeNodes } from './TaskForm.jsx'
|
||||
|
||||
export function ActionTaskPanel({
|
||||
actionId,
|
||||
roadmapItems,
|
||||
canManage,
|
||||
expanded,
|
||||
onToggle,
|
||||
openTaskCount,
|
||||
}) {
|
||||
const [tasks, setTasks] = useState([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [modal, setModal] = useState(null)
|
||||
const [reloadKey, setReloadKey] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (!expanded || !actionId) return undefined
|
||||
let cancelled = false
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
listActionTasks(actionId)
|
||||
.then((data) => {
|
||||
if (!cancelled) setTasks(data)
|
||||
})
|
||||
.catch((err) => {
|
||||
if (!cancelled) setError(err.message)
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setLoading(false)
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [expanded, actionId, reloadKey])
|
||||
|
||||
const tasksByParent = useMemo(() => buildTasksByParent(tasks), [tasks])
|
||||
|
||||
async function reload() {
|
||||
setReloadKey((value) => value + 1)
|
||||
}
|
||||
|
||||
async function handleCreate(payload) {
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
try {
|
||||
await createActionTask(actionId, payload)
|
||||
setModal(null)
|
||||
await reload()
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleUpdate(taskId, payload) {
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
try {
|
||||
await updateTask(taskId, payload)
|
||||
setModal(null)
|
||||
await reload()
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleStatus(taskId, status) {
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
try {
|
||||
await updateTask(taskId, { status })
|
||||
await reload()
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(taskId) {
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
try {
|
||||
await deleteTask(taskId)
|
||||
await reload()
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const taskLabel = openTaskCount != null ? ` (${openTaskCount} offen)` : ''
|
||||
|
||||
return (
|
||||
<div className="action-task-panel">
|
||||
<button
|
||||
type="button"
|
||||
className="action-task-panel__toggle"
|
||||
onClick={onToggle}
|
||||
aria-expanded={expanded}
|
||||
>
|
||||
{expanded ? '▾' : '▸'} Aufgaben{taskLabel}
|
||||
</button>
|
||||
|
||||
{expanded && (
|
||||
<div className="action-task-panel__body">
|
||||
{error && <p className="error">{error}</p>}
|
||||
{loading && <p className="muted">Aufgaben werden geladen …</p>}
|
||||
{!loading && tasks.length === 0 && (
|
||||
<p className="muted">Noch keine Aufgaben für dieses Arbeitspaket.</p>
|
||||
)}
|
||||
{!loading && tasks.length > 0 && (
|
||||
<TaskTreeNodes
|
||||
tasksByParent={tasksByParent}
|
||||
roadmapItems={roadmapItems}
|
||||
canManage={canManage}
|
||||
busy={busy}
|
||||
onEdit={(task) => setModal({ mode: 'edit', task, key: task.id })}
|
||||
onAddSubtask={(task) =>
|
||||
setModal({
|
||||
mode: 'create',
|
||||
parentTaskId: task.id,
|
||||
parentLabel: task.title,
|
||||
key: `sub-${task.id}`,
|
||||
})
|
||||
}
|
||||
onStatusChange={handleStatus}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
)}
|
||||
{canManage && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary btn-sm action-task-panel__add"
|
||||
disabled={busy}
|
||||
onClick={() => setModal({ mode: 'create', key: 'root' })}
|
||||
>
|
||||
Aufgabe hinzufügen
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Modal
|
||||
open={Boolean(modal)}
|
||||
title={
|
||||
modal?.mode === 'edit'
|
||||
? 'Aufgabe bearbeiten'
|
||||
: modal?.parentLabel
|
||||
? 'Unteraufgabe anlegen'
|
||||
: 'Aufgabe anlegen'
|
||||
}
|
||||
onClose={() => setModal(null)}
|
||||
>
|
||||
{modal?.mode === 'edit' ? (
|
||||
<TaskForm
|
||||
initial={modal.task}
|
||||
roadmapItems={roadmapItems}
|
||||
onSubmit={(payload) => handleUpdate(modal.task.id, payload)}
|
||||
onCancel={() => setModal(null)}
|
||||
busy={busy}
|
||||
/>
|
||||
) : (
|
||||
modal && (
|
||||
<TaskForm
|
||||
parentTaskId={modal.parentTaskId}
|
||||
parentLabel={modal.parentLabel}
|
||||
roadmapItems={roadmapItems}
|
||||
onSubmit={handleCreate}
|
||||
onCancel={() => setModal(null)}
|
||||
busy={busy}
|
||||
submitLabel="Anlegen"
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { StatusBadge } from './StatusBadge.jsx'
|
||||
import { PriorityBadge } from './PriorityBadge.jsx'
|
||||
import { Modal } from './Modal.jsx'
|
||||
import { ActionForm } from './ActionForm.jsx'
|
||||
import { ActionTaskPanel } from './ActionTaskPanel.jsx'
|
||||
import { gateTitleById } from './GateSelect.jsx'
|
||||
import { buildProjectPath, collectProjectSubtreeIds } from '../utils/projectTree.js'
|
||||
import { actionPath } from '../utils/routes.js'
|
||||
@@ -32,6 +33,7 @@ export function PlanActionsSection({
|
||||
busy,
|
||||
}) {
|
||||
const [showCreate, setShowCreate] = useState(false)
|
||||
const [expandedActions, setExpandedActions] = useState(() => new Set())
|
||||
|
||||
const visibleActions = useMemo(() => {
|
||||
let list = hideDone
|
||||
@@ -60,14 +62,22 @@ export function PlanActionsSection({
|
||||
setShowCreate(false)
|
||||
}
|
||||
|
||||
function toggleActionTasks(actionId) {
|
||||
setExpandedActions((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(actionId)) next.delete(actionId)
|
||||
else next.add(actionId)
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card plan-actions-section">
|
||||
<div className="section-header">
|
||||
<div>
|
||||
<h2>Arbeit</h2>
|
||||
<p className="section-lead muted">
|
||||
Committete Arbeitspakete im Plan-Kontext — Detail und Ausführung über die
|
||||
Objektseite.
|
||||
Committete Arbeitspakete und zugehörige Aufgaben — Ausführung über die Objektseite.
|
||||
</p>
|
||||
</div>
|
||||
<div className="section-actions">
|
||||
@@ -104,29 +114,38 @@ export function PlanActionsSection({
|
||||
<ul className="item-list plan-actions-list">
|
||||
{visibleActions.map((action) => (
|
||||
<li key={action.id} className="list-item card-list-item plan-actions-list__item">
|
||||
<div className="list-item-main">
|
||||
<Link to={actionPath(action.id)} className="plan-actions-list__title">
|
||||
<strong>{action.title}</strong>
|
||||
</Link>
|
||||
<p className="list-item-sub muted">
|
||||
{formatProjectContext(projects, action.project_id)}
|
||||
</p>
|
||||
{action.roadmap_item_id && (
|
||||
<div className="plan-actions-list__header">
|
||||
<div className="list-item-main">
|
||||
<Link to={actionPath(action.id)} className="plan-actions-list__title">
|
||||
<strong>{action.title}</strong>
|
||||
</Link>
|
||||
<p className="list-item-sub muted">
|
||||
Gate: {gateTitleById(roadmapItems, action.roadmap_item_id)}
|
||||
{formatProjectContext(projects, action.project_id)}
|
||||
</p>
|
||||
)}
|
||||
{action.description && (
|
||||
<p className="list-item-desc">{action.description}</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="list-item-meta action-controls">
|
||||
<StatusBadge kind="action" status={action.status} />
|
||||
<PriorityBadge priority={action.priority} />
|
||||
<Link to={actionPath(action.id)} className="btn btn-secondary btn-sm">
|
||||
Öffnen
|
||||
</Link>
|
||||
{action.roadmap_item_id && (
|
||||
<p className="list-item-sub muted">
|
||||
Gate: {gateTitleById(roadmapItems, action.roadmap_item_id)}
|
||||
</p>
|
||||
)}
|
||||
{action.description && (
|
||||
<p className="list-item-desc">{action.description}</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="list-item-meta action-controls">
|
||||
<StatusBadge kind="action" status={action.status} />
|
||||
<PriorityBadge priority={action.priority} />
|
||||
<Link to={actionPath(action.id)} className="btn btn-secondary btn-sm">
|
||||
Öffnen
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<ActionTaskPanel
|
||||
actionId={action.id}
|
||||
roadmapItems={roadmapItems}
|
||||
canManage={canManage}
|
||||
expanded={expandedActions.has(action.id)}
|
||||
onToggle={() => toggleActionTasks(action.id)}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
import { TASK_STATUSES, TASK_STATUS_LABELS } from '../constants/status.js'
|
||||
import { gateTitleById } from './GateSelect.jsx'
|
||||
import { MAX_TASK_UI_DEPTH } from '../utils/taskTree.js'
|
||||
|
||||
export function TaskForm({
|
||||
initial = {},
|
||||
parentTaskId = null,
|
||||
parentLabel = null,
|
||||
roadmapItems = [],
|
||||
onSubmit,
|
||||
onCancel,
|
||||
busy = false,
|
||||
submitLabel = 'Speichern',
|
||||
}) {
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
const form = e.target
|
||||
await onSubmit({
|
||||
title: form.title.value.trim(),
|
||||
description: form.description.value,
|
||||
status: form.status?.value || initial.status || 'open',
|
||||
roadmap_item_id: form.roadmap_item_id?.value || undefined,
|
||||
parent_task_id: parentTaskId || undefined,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="form workspace-form" onSubmit={handleSubmit}>
|
||||
{parentLabel && (
|
||||
<p className="muted task-form__parent-hint">Unteraufgabe von: {parentLabel}</p>
|
||||
)}
|
||||
<label>
|
||||
Titel
|
||||
<input
|
||||
name="title"
|
||||
defaultValue={initial.title || ''}
|
||||
required
|
||||
maxLength={255}
|
||||
autoFocus
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Beschreibung
|
||||
<textarea name="description" rows={3} defaultValue={initial.description || ''} />
|
||||
</label>
|
||||
{roadmapItems.length > 0 && (
|
||||
<label>
|
||||
Gate (optional)
|
||||
<select name="roadmap_item_id" defaultValue={initial.roadmap_item_id || ''}>
|
||||
<option value="">— keins —</option>
|
||||
{roadmapItems.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.title}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{initial.id && (
|
||||
<label>
|
||||
Status
|
||||
<select name="status" defaultValue={initial.status || 'open'}>
|
||||
{TASK_STATUSES.map((status) => (
|
||||
<option key={status} value={status}>
|
||||
{TASK_STATUS_LABELS[status]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy}>
|
||||
{busy ? 'Speichern …' : submitLabel}
|
||||
</button>
|
||||
{onCancel && (
|
||||
<button type="button" className="btn btn-secondary" onClick={onCancel} disabled={busy}>
|
||||
Abbrechen
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
export function TaskTreeNodes({
|
||||
tasksByParent,
|
||||
parentId = '',
|
||||
depth = 1,
|
||||
roadmapItems,
|
||||
canManage,
|
||||
busy,
|
||||
onEdit,
|
||||
onAddSubtask,
|
||||
onStatusChange,
|
||||
onDelete,
|
||||
}) {
|
||||
const nodes = tasksByParent.get(parentId || '') || []
|
||||
if (!nodes.length) return null
|
||||
|
||||
return (
|
||||
<ul className={`task-tree task-tree--depth-${depth}`}>
|
||||
{nodes.map((task) => (
|
||||
<li key={task.id} className="task-tree__item">
|
||||
<div className="task-tree__row">
|
||||
<div className="task-tree__main">
|
||||
<strong>{task.title}</strong>
|
||||
{task.roadmap_item_id && (
|
||||
<span className="muted task-tree__gate">
|
||||
Gate: {gateTitleById(roadmapItems, task.roadmap_item_id)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="task-tree__actions action-controls">
|
||||
{canManage ? (
|
||||
<>
|
||||
<select
|
||||
className="inline-select"
|
||||
value={task.status}
|
||||
disabled={busy}
|
||||
onChange={(e) => onStatusChange(task.id, e.target.value)}
|
||||
aria-label="Task-Status"
|
||||
>
|
||||
{TASK_STATUSES.map((status) => (
|
||||
<option key={status} value={status}>
|
||||
{TASK_STATUS_LABELS[status]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{depth < MAX_TASK_UI_DEPTH && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary btn-sm"
|
||||
disabled={busy}
|
||||
onClick={() => onAddSubtask(task)}
|
||||
>
|
||||
+ Unteraufgabe
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary btn-sm"
|
||||
disabled={busy}
|
||||
onClick={() => onEdit(task)}
|
||||
>
|
||||
Bearbeiten
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary btn-sm"
|
||||
disabled={busy}
|
||||
onClick={() => onDelete(task.id)}
|
||||
>
|
||||
Entfernen
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<span>{TASK_STATUS_LABELS[task.status] || task.status}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{depth < MAX_TASK_UI_DEPTH && (
|
||||
<TaskTreeNodes
|
||||
tasksByParent={tasksByParent}
|
||||
parentId={task.id}
|
||||
depth={depth + 1}
|
||||
roadmapItems={roadmapItems}
|
||||
canManage={canManage}
|
||||
busy={busy}
|
||||
onEdit={onEdit}
|
||||
onAddSubtask={onAddSubtask}
|
||||
onStatusChange={onStatusChange}
|
||||
onDelete={onDelete}
|
||||
/>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
@@ -430,3 +430,68 @@
|
||||
.plan-actions-section__scope-hint {
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.plan-actions-list__header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.action-task-panel {
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--jk-border-subtle, #e5e7eb);
|
||||
}
|
||||
|
||||
.action-task-panel__toggle {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: var(--jk-primary, #2563eb);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.action-task-panel__body {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.action-task-panel__add {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.task-tree {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.task-tree--depth-2,
|
||||
.task-tree--depth-3 {
|
||||
margin-left: 16px;
|
||||
padding-left: 12px;
|
||||
border-left: 2px solid var(--jk-border-subtle, #e5e7eb);
|
||||
}
|
||||
|
||||
.task-tree__item {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.task-tree__row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.task-tree__gate {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.task-form__parent-hint {
|
||||
margin: 0 0 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/** Task-Baum unter Action (AP1.5d) — UI max. 3 Ebenen. */
|
||||
|
||||
export const MAX_TASK_UI_DEPTH = 3
|
||||
|
||||
/**
|
||||
* @param {Array<{ id: string, parent_task_id?: string | null, sort_order?: number, title?: string }>} tasks
|
||||
* @returns {Map<string, Array<object>>}
|
||||
*/
|
||||
export function buildTasksByParent(tasks) {
|
||||
const byParent = new Map()
|
||||
for (const task of tasks) {
|
||||
const parentKey = task.parent_task_id || ''
|
||||
if (!byParent.has(parentKey)) {
|
||||
byParent.set(parentKey, [])
|
||||
}
|
||||
byParent.get(parentKey).push(task)
|
||||
}
|
||||
for (const list of byParent.values()) {
|
||||
list.sort(
|
||||
(a, b) =>
|
||||
(a.sort_order ?? 0) - (b.sort_order ?? 0) ||
|
||||
(a.title || '').localeCompare(b.title || ''),
|
||||
)
|
||||
}
|
||||
return byParent
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Map<string, Array<object>>} byParent
|
||||
* @param {string | null | undefined} parentId
|
||||
* @param {number} [depth]
|
||||
* @returns {number}
|
||||
*/
|
||||
export function countOpenTasksInSubtree(byParent, parentId = '', depth = 1) {
|
||||
const nodes = byParent.get(parentId || '') || []
|
||||
let count = 0
|
||||
for (const task of nodes) {
|
||||
if (task.status !== 'done' && task.status !== 'discarded') {
|
||||
count += 1
|
||||
}
|
||||
if (depth < MAX_TASK_UI_DEPTH) {
|
||||
count += countOpenTasksInSubtree(byParent, task.id, depth + 1)
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<object>} tasks
|
||||
* @returns {number}
|
||||
*/
|
||||
export function countOpenTasks(tasks) {
|
||||
if (!tasks?.length) return 0
|
||||
const byParent = buildTasksByParent(tasks)
|
||||
return countOpenTasksInSubtree(byParent)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { buildTasksByParent, countOpenTasks } from './taskTree.js'
|
||||
|
||||
describe('taskTree', () => {
|
||||
it('groups tasks by parent and sorts by sort_order', () => {
|
||||
const byParent = buildTasksByParent([
|
||||
{ id: 'b', parent_task_id: 'a', sort_order: 2, title: 'B', status: 'open' },
|
||||
{ id: 'a', parent_task_id: null, sort_order: 1, title: 'A', status: 'open' },
|
||||
{ id: 'c', parent_task_id: 'a', sort_order: 1, title: 'C', status: 'done' },
|
||||
])
|
||||
expect(byParent.get('').map((t) => t.id)).toEqual(['a'])
|
||||
expect(byParent.get('a').map((t) => t.id)).toEqual(['c', 'b'])
|
||||
})
|
||||
|
||||
it('counts open tasks in subtree', () => {
|
||||
const tasks = [
|
||||
{ id: 'a', parent_task_id: null, status: 'open' },
|
||||
{ id: 'b', parent_task_id: 'a', status: 'done' },
|
||||
{ id: 'c', parent_task_id: 'a', status: 'open' },
|
||||
]
|
||||
expect(countOpenTasks(tasks)).toBe(2)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user