AP1.5c: Rekursive Projects fuer Mega-Programme ohne Stream-Typ.
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Successful in 1m42s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 21s
Test Suite / playwright-smoke (push) Successful in 14s

parent_project_id und container_kind ermoeglichen verschachtelte Projektstruktur; Arbeitspakete bleiben an Blatt-Projekten gebunden.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-07-06 08:38:58 +02:00
1 parent 6eeddfdc76
commit 4ca0a2c460
15 files changed
+947 -91

No files matched your search

+8 -5
View File
@@ -1,6 +1,7 @@
import { ACTION_STATUSES, PRIORITIES } from '../constants/status.js'
import { ACTION_STATUS_LABELS, PRIORITY_LABELS } from '../constants/status.js'
import { ActorSelect } from './ActorSelect.jsx'
import { flattenLeafProjectOptions, getLeafProjects } from '../utils/projectTree.js'
function isoToLocalInput(iso) {
if (!iso) return ''
@@ -38,6 +39,8 @@ export function ActionForm({
}
const defaultActors = initial.assigned_actor_ids || []
const leafProjects = getLeafProjects(projects)
const projectOptions = flattenLeafProjectOptions(projects)
return (
<form className="form workspace-form" onSubmit={handleSubmit}>
@@ -77,14 +80,14 @@ export function ActionForm({
defaultValue={isoToLocalInput(initial.due_at)}
/>
</label>
{projects.length > 0 && (
{leafProjects.length > 0 && (
<label>
Projekt (optional)
Projekt (optional, Blatt-Ebene)
<select name="project_id" defaultValue={initial.project_id || ''}>
<option value="">— keins —</option>
{projects.map((p) => (
<option key={p.id} value={p.id}>
{p.title}
{projectOptions.map(({ project, label }) => (
<option key={project.id} value={project.id}>
{label}
</option>
))}
</select>
+148 -41
View File
@@ -1,6 +1,80 @@
import { useState } from 'react'
import { useMemo, useState } from 'react'
import { EmptyState } from './EmptyState.jsx'
import { StatusBadge } from './StatusBadge.jsx'
import {
buildProjectsByParent,
containerKindLabel,
flattenProjectOptions,
} from '../utils/projectTree.js'
function ProjectTreeNodes({
projects,
parentId,
depth,
selectedProjectId,
onSelectProject,
canManage,
onDelete,
busy,
}) {
const byParent = useMemo(() => buildProjectsByParent(projects), [projects])
const nodes = byParent.get(parentId || '') || []
if (nodes.length === 0) return null
return (
<ul className="project-tree-children">
{nodes.map((project) => (
<li key={project.id} className="project-tree-branch">
<div className="list-item card-list-item project-tree-item">
<div className="list-item-main">
<button
type="button"
className="link-button"
onClick={() =>
onSelectProject(selectedProjectId === project.id ? '' : project.id)
}
>
<strong>{project.title}</strong>
</button>
{project.container_kind && (
<span className="project-kind-badge muted">
{containerKindLabel(project.container_kind)}
</span>
)}
{project.description && (
<p className="list-item-desc muted">{project.description}</p>
)}
</div>
<div className="list-item-meta action-controls">
<StatusBadge kind="initiative" status={project.status} />
{canManage && (
<button
type="button"
className="btn btn-secondary"
disabled={busy}
onClick={() => onDelete(project.id)}
>
Löschen
</button>
)}
</div>
</div>
<ProjectTreeNodes
projects={projects}
parentId={project.id}
depth={depth + 1}
selectedProjectId={selectedProjectId}
onSelectProject={onSelectProject}
canManage={canManage}
onDelete={onDelete}
busy={busy}
/>
</li>
))}
</ul>
)
}
export function ProjectsSection({
projects,
@@ -13,37 +87,65 @@ export function ProjectsSection({
}) {
const [title, setTitle] = useState('')
const [description, setDescription] = useState('')
const [parentProjectId, setParentProjectId] = useState('')
const [containerKind, setContainerKind] = useState('')
const [showForm, setShowForm] = useState(false)
const parentOptions = useMemo(
() => flattenProjectOptions(projects),
[projects]
)
async function handleSubmit(e) {
e.preventDefault()
if (!title.trim()) return
await onCreate({
title: title.trim(),
description: description.trim(),
parent_project_id: parentProjectId || undefined,
container_kind: containerKind || undefined,
})
setTitle('')
setDescription('')
setParentProjectId('')
setContainerKind('')
setShowForm(false)
}
function openFormUnderSelected() {
setParentProjectId(selectedProjectId || '')
setShowForm(true)
}
return (
<section className="card projects-section">
<div className="section-header">
<div>
<h2>Projekte</h2>
<p className="section-lead muted">
Operative Struktur — Arbeitspakete gruppieren. Zielzustände (Gates) sind optional.
Operative Struktur — verschachtelbar für große Vorhaben. Arbeitspakete nur an
Blatt-Projekten. Gates optional.
</p>
</div>
{canManage && (
<button
type="button"
className="btn btn-primary btn-block-mobile"
onClick={() => setShowForm((v) => !v)}
>
{showForm ? 'Abbrechen' : 'Projekt'}
</button>
<div className="section-header-actions">
{selectedProjectId && (
<button
type="button"
className="btn btn-secondary btn-block-mobile"
onClick={openFormUnderSelected}
>
Unterprojekt
</button>
)}
<button
type="button"
className="btn btn-primary btn-block-mobile"
onClick={() => setShowForm((v) => !v)}
>
{showForm ? 'Abbrechen' : 'Projekt'}
</button>
</div>
)}
</div>
@@ -67,6 +169,32 @@ export function ProjectsSection({
rows={2}
/>
</label>
{parentOptions.length > 0 && (
<label>
Unter (optional)
<select
value={parentProjectId}
onChange={(e) => setParentProjectId(e.target.value)}
>
<option value="">— oberste Ebene —</option>
{parentOptions.map(({ project, label }) => (
<option key={project.id} value={project.id}>
{label}
</option>
))}
</select>
</label>
)}
<label>
Art (optional)
<select value={containerKind} onChange={(e) => setContainerKind(e.target.value)}>
<option value="">— Standard —</option>
<option value="project">Projekt</option>
<option value="stream">Stream</option>
<option value="phase">Phase</option>
<option value="release">Release</option>
</select>
</label>
<button type="submit" className="btn btn-primary" disabled={busy}>
Anlegen
</button>
@@ -77,7 +205,7 @@ export function ProjectsSection({
<EmptyState message="Noch keine Projekte — optional. Du kannst auch direkt Arbeitspakete anlegen." />
)}
<ul className="item-list project-filter-list">
<ul className="item-list project-filter-list project-tree-list">
<li className="list-item card-list-item">
<button
type="button"
@@ -87,38 +215,17 @@ export function ProjectsSection({
Alle Arbeitspakete
</button>
</li>
{projects.map((project) => (
<li key={project.id} className="list-item card-list-item">
<div className="list-item-main">
<button
type="button"
className="link-button"
onClick={() =>
onSelectProject(selectedProjectId === project.id ? '' : project.id)
}
>
<strong>{project.title}</strong>
</button>
{project.description && (
<p className="list-item-desc muted">{project.description}</p>
)}
</div>
<div className="list-item-meta action-controls">
<StatusBadge kind="initiative" status={project.status} />
{canManage && (
<button
type="button"
className="btn btn-secondary"
disabled={busy}
onClick={() => onDelete(project.id)}
>
Löschen
</button>
)}
</div>
</li>
))}
</ul>
<ProjectTreeNodes
projects={projects}
parentId=""
depth={1}
selectedProjectId={selectedProjectId}
onSelectProject={onSelectProject}
canManage={canManage}
onDelete={onDelete}
busy={busy}
/>
</section>
)
}
@@ -67,6 +67,7 @@ import { listSteeringMethods, updateInitiativeSteeringMethod } from '../api/stee
import { useCapabilities } from '../hooks/useCapabilities.js'
import { useActors } from '../hooks/useActors.js'
import { useSession } from './SessionContext.jsx'
import { collectProjectSubtreeIds } from '../utils/projectTree.js'
const InitiativeOperationsContext = createContext(null)
@@ -154,17 +155,25 @@ export function InitiativeOperationsProvider({ children }) {
load()
}, [load])
const selectedLeafProjectId = useMemo(() => {
if (!selectedProjectId) return ''
const match = projects.find((p) => p.id === selectedProjectId)
if (match?.is_leaf) return selectedProjectId
return ''
}, [selectedProjectId, projects])
const visibleActions = useMemo(
() => {
let list = hideDone
? actions.filter((a) => a.status !== 'done' && a.status !== 'discarded')
: actions
if (selectedProjectId) {
list = list.filter((a) => a.project_id === selectedProjectId)
const subtreeIds = collectProjectSubtreeIds(projects, selectedProjectId)
list = list.filter((a) => a.project_id && subtreeIds.has(a.project_id))
}
return list
},
[actions, hideDone, selectedProjectId]
[actions, hideDone, selectedProjectId, projects]
)
const actionContextById = useMemo(
@@ -200,7 +209,7 @@ export function InitiativeOperationsProvider({ children }) {
: []
await createInitiativeAction(id, {
...payload,
project_id: payload.project_id || selectedProjectId || undefined,
project_id: payload.project_id || selectedLeafProjectId || undefined,
assigned_actor_ids: assigned,
})
setShowActionForm(false)
+32
View File
@@ -426,6 +426,38 @@
margin-bottom: 1rem;
}
.section-header-actions {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
align-items: center;
}
.project-tree-list {
margin-bottom: 0;
}
.project-tree-children {
list-style: none;
margin: 0;
padding: 0 0 0 0.75rem;
border-left: 2px solid var(--jk-border, #e2e8f0);
}
.project-tree-branch {
list-style: none;
margin: 0.35rem 0 0;
}
.project-tree-item {
margin-left: 0;
}
.project-kind-badge {
font-size: 0.75rem;
margin-left: 0.35rem;
}
.section-header h2 {
margin: 0;
font-size: 1rem;
+80
View File
@@ -0,0 +1,80 @@
/** AP1.5c — Project-Baum Hilfsfunktionen */
const CONTAINER_KIND_LABELS = {
project: 'Projekt',
stream: 'Stream',
phase: 'Phase',
release: 'Release',
}
export function containerKindLabel(kind) {
if (!kind) return null
return CONTAINER_KIND_LABELS[kind] || kind
}
export function buildProjectsByParent(projects) {
const byParent = new Map()
for (const project of projects) {
const key = project.parent_project_id || ''
if (!byParent.has(key)) byParent.set(key, [])
byParent.get(key).push(project)
}
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
}
export function collectProjectSubtreeIds(projects, rootId) {
const byParent = buildProjectsByParent(projects)
const ids = new Set([rootId])
const stack = [rootId]
while (stack.length) {
const current = stack.pop()
for (const child of byParent.get(current) || []) {
if (!ids.has(child.id)) {
ids.add(child.id)
stack.push(child.id)
}
}
}
return ids
}
export function getLeafProjects(projects) {
const parentIds = new Set(
projects.map((p) => p.parent_project_id).filter(Boolean)
)
return projects.filter((p) => !parentIds.has(p.id))
}
export function projectOptionLabel(project, depth = 1) {
const prefix = depth > 1 ? `${'— '.repeat(depth - 1)}` : ''
const kind = containerKindLabel(project.container_kind)
const kindSuffix = kind ? ` (${kind})` : ''
return `${prefix}${project.title}${kindSuffix}`
}
export function flattenLeafProjectOptions(projects, parentId = '', depth = 1) {
const byParent = buildProjectsByParent(projects)
const result = []
for (const project of byParent.get(parentId) || []) {
const children = byParent.get(project.id) || []
if (children.length === 0) {
result.push({ project, depth, label: projectOptionLabel(project, depth) })
} else {
result.push(...flattenLeafProjectOptions(projects, project.id, depth + 1))
}
}
return result
}
export function flattenProjectOptions(projects, parentId = '', depth = 1) {
const byParent = buildProjectsByParent(projects)
const result = []
for (const project of byParent.get(parentId) || []) {
result.push({ project, depth, label: projectOptionLabel(project, depth) })
result.push(...flattenProjectOptions(projects, project.id, depth + 1))
}
return result
}