AP1.12c: Reorder für Projekte und Backlog per sort_order.
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Failing after 1m46s
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

Migration 015 für Backlog sort_order; DnD auf Desktop, Pfeile auf Mobile; PATCH-Batches für Geschwister.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-07-09 11:35:08 +02:00
1 parent e50c04c96f
commit a99d4a8974
15 files changed
+709 -130

No files matched your search

+153 -50
View File
@@ -1,10 +1,13 @@
import { useState } from 'react'
import { useMemo, useState } from 'react'
import { StatusBadge } from './StatusBadge.jsx'
import { PriorityBadge } from './PriorityBadge.jsx'
import { EmptyState } from './EmptyState.jsx'
import { Modal } from './Modal.jsx'
import { BacklogItemForm } from './BacklogItemForm.jsx'
import { ReorderControls } from './ReorderControls.jsx'
import { gateTitleById } from './GateSelect.jsx'
import { computeDropPatches, computeMovePatches, sortByOrder } from '../utils/reorder.js'
import { useMinWidth } from '../hooks/useMinWidth.js'
export function BacklogSection({
items,
@@ -12,11 +15,21 @@ export function BacklogSection({
canManage,
onCreate,
onUpdate,
onReorder,
onConvert,
onDelete,
busy,
}) {
const [modalMode, setModalMode] = useState(null)
const [dragItemId, setDragItemId] = useState('')
const [dropTargetId, setDropTargetId] = useState('')
const isDesktop = useMinWidth(1024)
const canReorder = canManage && typeof onReorder === 'function'
const sortedItems = useMemo(
() => sortByOrder(items.filter((item) => item.status !== 'converted')),
[items],
)
function closeModal() {
setModalMode(null)
@@ -46,13 +59,58 @@ export function BacklogSection({
if (ok !== false) closeModal()
}
async function applyPatches(patches) {
if (!patches.length) return
await onReorder(patches)
}
async function handleMove(itemId, direction) {
const patches = computeMovePatches(sortedItems, itemId, direction)
await applyPatches(patches)
}
function handleDragStart(event, itemId) {
if (!canReorder || !isDesktop) return
setDragItemId(itemId)
event.dataTransfer.effectAllowed = 'move'
event.dataTransfer.setData('text/plain', itemId)
}
function handleDragEnd() {
setDragItemId('')
setDropTargetId('')
}
function handleDragOver(event, itemId) {
if (!canReorder || !isDesktop || !dragItemId) return
event.preventDefault()
event.dataTransfer.dropEffect = 'move'
setDropTargetId(itemId)
}
async function handleDrop(event, targetId) {
event.preventDefault()
if (!canReorder || !isDesktop || !dragItemId) {
handleDragEnd()
return
}
const patches = computeDropPatches(sortedItems, dragItemId, targetId)
handleDragEnd()
await applyPatches(patches)
}
const modalTitle =
modalMode?.kind === 'create' ? 'Backlog-Item anlegen' : 'Backlog-Item bearbeiten'
return (
<section className="card">
<section className="card backlog-section">
<div className="section-header">
<h2>Backlog</h2>
<div>
<h2>Backlog</h2>
<p className="section-lead muted">
Reihenfolge per Drag &amp; Drop (Desktop) oder ↑/↓ (Mobile).
</p>
</div>
{canManage && (
<button
type="button"
@@ -66,60 +124,105 @@ export function BacklogSection({
{items.length === 0 && <EmptyState message="Backlog ist leer." />}
<ul className="item-list">
{items.map((item) => (
<li key={item.id} className="list-item card-list-item">
<button
type="button"
className="list-item-main list-item-main--clickable"
onClick={() => canManage && setModalMode({ kind: 'edit', item })}
disabled={!canManage}
<ul className="item-list backlog-reorder-list">
{sortedItems.map((item, index) => {
const isDragging = dragItemId === item.id
const isDropTarget = dropTargetId === item.id && dragItemId && dragItemId !== item.id
const reorderable = canReorder && item.status !== 'converted'
return (
<li
key={item.id}
className={
'list-item card-list-item backlog-reorder-item' +
(isDragging ? ' backlog-reorder-item--dragging' : '') +
(isDropTarget ? ' backlog-reorder-item--drop-target' : '') +
(reorderable && isDesktop ? ' backlog-reorder-item--draggable' : '')
}
draggable={reorderable && isDesktop}
onDragStart={(event) => handleDragStart(event, item.id)}
onDragEnd={handleDragEnd}
onDragOver={(event) => handleDragOver(event, item.id)}
onDrop={(event) => handleDrop(event, item.id)}
>
<strong>{item.title}</strong>
{item.description && (
<p className="list-item-desc">{item.description}</p>
{reorderable && isDesktop && (
<span className="backlog-reorder-item__drag-hint" aria-hidden="true">
⋮⋮
</span>
)}
{item.roadmap_item_id && (
<p className="list-item-sub muted">
Gate: {gateTitleById(roadmapItems, item.roadmap_item_id) || item.roadmap_item_id}
</p>
)}
</button>
<div className="list-item-meta action-controls">
<StatusBadge kind="backlog" status={item.status} />
<PriorityBadge priority={item.priority} />
{canManage && item.status !== 'converted' && (
<>
{item.status === 'accepted' && (
<button
type="button"
className="list-item-main list-item-main--clickable"
onClick={() => canManage && setModalMode({ kind: 'edit', item })}
disabled={!canManage}
>
<strong>{item.title}</strong>
{item.description && (
<p className="list-item-desc">{item.description}</p>
)}
{item.roadmap_item_id && (
<p className="list-item-sub muted">
Gate:{' '}
{gateTitleById(roadmapItems, item.roadmap_item_id) || item.roadmap_item_id}
</p>
)}
</button>
<div className="list-item-meta action-controls">
{reorderable && !isDesktop && (
<ReorderControls
itemId={item.id}
canMoveUp={index > 0}
canMoveDown={index < sortedItems.length - 1}
onMove={(direction) => handleMove(item.id, direction)}
busy={busy}
/>
)}
<StatusBadge kind="backlog" status={item.status} />
<PriorityBadge priority={item.priority} />
{canManage && item.status !== 'converted' && (
<>
{item.status === 'accepted' && (
<button
type="button"
className="btn btn-primary btn-sm"
onClick={() => onConvert(item.id)}
disabled={busy}
>
In Maßnahme umwandeln
</button>
)}
<button
type="button"
className="btn btn-primary btn-sm"
onClick={() => onConvert(item.id)}
className="btn btn-secondary btn-sm"
onClick={() => setModalMode({ kind: 'edit', item })}
disabled={busy}
>
In Maßnahme umwandeln
Bearbeiten
</button>
)}
<button
type="button"
className="btn btn-secondary btn-sm"
onClick={() => setModalMode({ kind: 'edit', item })}
disabled={busy}
>
Bearbeiten
</button>
<button
type="button"
className="btn btn-secondary btn-sm"
onClick={() => onDelete(item.id)}
>
Löschen
</button>
</>
)}
</div>
</li>
))}
<button
type="button"
className="btn btn-secondary btn-sm"
onClick={() => onDelete(item.id)}
>
Löschen
</button>
</>
)}
</div>
</li>
)
})}
{items
.filter((item) => item.status === 'converted')
.map((item) => (
<li key={item.id} className="list-item card-list-item backlog-reorder-item--converted">
<div className="list-item-main">
<strong>{item.title}</strong>
<p className="list-item-sub muted">Konvertiert — nicht mehr sortierbar</p>
</div>
<StatusBadge kind="backlog" status={item.status} />
</li>
))}
</ul>
<Modal open={Boolean(modalMode)} title={modalTitle} onClose={closeModal}>
+188 -73
View File
@@ -4,10 +4,13 @@ import { EmptyState } from './EmptyState.jsx'
import { StatusBadge } from './StatusBadge.jsx'
import { Modal } from './Modal.jsx'
import { ProjectForm } from './ProjectForm.jsx'
import { ReorderControls } from './ReorderControls.jsx'
import {
buildProjectsByParent,
containerKindLabel,
} from '../utils/projectTree.js'
import { computeDropPatches, computeMovePatches, sortByOrder } from '../utils/reorder.js'
import { useMinWidth } from '../hooks/useMinWidth.js'
import { gateTitleById } from './GateSelect.jsx'
import { projectPath } from '../utils/routes.js'
@@ -18,6 +21,15 @@ function ProjectTreeNodes({
selectedProjectId,
onSelectProject,
canManage,
canReorder,
isDesktop,
dragProjectId,
dropTargetId,
onDragStart,
onDragEnd,
onDragOver,
onDrop,
onMove,
onEdit,
onDelete,
busy,
@@ -29,80 +41,120 @@ function ProjectTreeNodes({
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${selectedProjectId === project.id ? ' project-tree-item--selected' : ''}`}
>
<div className="list-item-main project-tree-item-main">
<Link
to={projectPath(project.id)}
className="project-tree-title-link"
>
<strong>{project.title}</strong>
</Link>
{project.container_kind && (
<span className="project-kind-badge muted">
{containerKindLabel(project.container_kind)}
</span>
)}
{project.roadmap_item_id && (
<span className="project-kind-badge muted">
Gate: {gateTitleById(roadmapItems, project.roadmap_item_id)}
{nodes.map((project, index) => {
const isDragging = dragProjectId === project.id
const isDropTarget = dropTargetId === project.id && dragProjectId && dragProjectId !== project.id
return (
<li key={project.id} className="project-tree-branch">
<div
className={
'list-item card-list-item project-tree-item' +
(selectedProjectId === project.id ? ' project-tree-item--selected' : '') +
(isDragging ? ' project-tree-item--dragging' : '') +
(isDropTarget ? ' project-tree-item--drop-target' : '') +
(canReorder && isDesktop ? ' project-tree-item--draggable' : '')
}
draggable={canReorder && isDesktop}
onDragStart={(event) => onDragStart(event, project.id, parentId || '')}
onDragEnd={onDragEnd}
onDragOver={(event) => onDragOver(event, project.id)}
onDrop={(event) => onDrop(event, project.id, parentId || '')}
>
{canReorder && isDesktop && (
<span className="project-tree-item__drag-hint" aria-hidden="true">
⋮⋮
</span>
)}
<div className="list-item-main project-tree-item-main">
<Link
to={projectPath(project.id)}
className="project-tree-title-link"
draggable={false}
>
<strong>{project.title}</strong>
</Link>
{project.container_kind && (
<span className="project-kind-badge muted">
{containerKindLabel(project.container_kind)}
</span>
)}
{project.roadmap_item_id && (
<span className="project-kind-badge muted">
Gate: {gateTitleById(roadmapItems, project.roadmap_item_id)}
</span>
)}
</div>
<div className="list-item-meta action-controls project-tree-item-actions">
{canReorder && !isDesktop && (
<ReorderControls
itemId={project.id}
canMoveUp={index > 0}
canMoveDown={index < nodes.length - 1}
onMove={(direction) => onMove(project.id, parentId || '', direction)}
busy={busy}
/>
)}
<StatusBadge kind="project" status={project.status} />
<button
type="button"
className={`btn btn-secondary btn-sm${selectedProjectId === project.id ? ' btn-primary' : ''}`}
title="Arbeitspakete filtern"
onClick={() =>
onSelectProject(selectedProjectId === project.id ? '' : project.id)
}
>
{selectedProjectId === project.id ? 'Filter aktiv' : 'Filtern'}
</button>
{canManage && (
<>
<button
type="button"
className="btn btn-secondary btn-sm"
disabled={busy}
onClick={() => onEdit(project)}
>
Bearbeiten
</button>
<button
type="button"
className="btn btn-secondary btn-sm"
disabled={busy}
onClick={() => {
if (window.confirm(`Projekt „${project.title}“ wirklich löschen?`)) {
onDelete(project.id)
}
}}
>
Löschen
</button>
</>
)}
</div>
</div>
<div className="list-item-meta action-controls project-tree-item-actions">
<StatusBadge kind="project" status={project.status} />
<button
type="button"
className={`btn btn-secondary btn-sm${selectedProjectId === project.id ? ' btn-primary' : ''}`}
title="Arbeitspakete filtern"
onClick={() =>
onSelectProject(selectedProjectId === project.id ? '' : project.id)
}
>
{selectedProjectId === project.id ? 'Filter aktiv' : 'Filtern'}
</button>
{canManage && (
<>
<button
type="button"
className="btn btn-secondary btn-sm"
disabled={busy}
onClick={() => onEdit(project)}
>
Bearbeiten
</button>
<button
type="button"
className="btn btn-secondary btn-sm"
disabled={busy}
onClick={() => {
if (window.confirm(`Projekt „${project.title}“ wirklich löschen?`)) {
onDelete(project.id)
}
}}
>
Löschen
</button>
</>
)}
</div>
</div>
<ProjectTreeNodes
projects={projects}
roadmapItems={roadmapItems}
parentId={project.id}
selectedProjectId={selectedProjectId}
onSelectProject={onSelectProject}
canManage={canManage}
onEdit={onEdit}
onDelete={onDelete}
busy={busy}
/>
</li>
))}
<ProjectTreeNodes
projects={projects}
roadmapItems={roadmapItems}
parentId={project.id}
selectedProjectId={selectedProjectId}
onSelectProject={onSelectProject}
canManage={canManage}
canReorder={canReorder}
isDesktop={isDesktop}
dragProjectId={dragProjectId}
dropTargetId={dropTargetId}
onDragStart={onDragStart}
onDragEnd={onDragEnd}
onDragOver={onDragOver}
onDrop={onDrop}
onMove={onMove}
onEdit={onEdit}
onDelete={onDelete}
busy={busy}
/>
</li>
)
})}
</ul>
)
}
@@ -116,9 +168,21 @@ export function ProjectsSection({
onCreate,
onUpdate,
onDelete,
onReorder,
busy,
}) {
const [modalMode, setModalMode] = useState(null)
const [dragProjectId, setDragProjectId] = useState('')
const [dragParentId, setDragParentId] = useState('')
const [dropTargetId, setDropTargetId] = useState('')
const isDesktop = useMinWidth(1024)
const canReorder = canManage && typeof onReorder === 'function'
const byParent = useMemo(() => buildProjectsByParent(projects), [projects])
function getSiblings(parentKey) {
return sortByOrder(byParent.get(parentKey || '') || [])
}
function closeModal() {
setModalMode(null)
@@ -135,6 +199,48 @@ export function ProjectsSection({
if (ok) closeModal()
}
async function applyPatches(patches) {
if (!patches.length) return
await onReorder(patches)
}
async function handleMove(projectId, parentKey, direction) {
const patches = computeMovePatches(getSiblings(parentKey), projectId, direction)
await applyPatches(patches)
}
function handleDragStart(event, projectId, parentKey) {
if (!canReorder || !isDesktop) return
setDragProjectId(projectId)
setDragParentId(parentKey)
event.dataTransfer.effectAllowed = 'move'
event.dataTransfer.setData('text/plain', projectId)
}
function handleDragEnd() {
setDragProjectId('')
setDragParentId('')
setDropTargetId('')
}
function handleDragOver(event, projectId) {
if (!canReorder || !isDesktop || !dragProjectId) return
event.preventDefault()
event.dataTransfer.dropEffect = 'move'
setDropTargetId(projectId)
}
async function handleDrop(event, targetId, parentKey) {
event.preventDefault()
if (!canReorder || !isDesktop || !dragProjectId || dragParentId !== parentKey) {
handleDragEnd()
return
}
const patches = computeDropPatches(getSiblings(parentKey), dragProjectId, targetId)
handleDragEnd()
await applyPatches(patches)
}
const modalTitle =
modalMode?.kind === 'create' ? 'Neues Projekt' : 'Projekt bearbeiten'
@@ -144,8 +250,8 @@ export function ProjectsSection({
<div>
<h2>Struktur</h2>
<p className="section-lead muted">
Projekte, Streams und Phasen — Bearbeitung im Modal, Detailseite über den Titel.
Filter schränkt Arbeitspakete ein.
Projekte per Drag &amp; Drop (Desktop) oder ↑/↓ (Mobile) sortieren — Bearbeitung im
Modal.
</p>
</div>
{canManage && (
@@ -183,6 +289,15 @@ export function ProjectsSection({
selectedProjectId={selectedProjectId}
onSelectProject={onSelectProject}
canManage={canManage}
canReorder={canReorder}
isDesktop={isDesktop}
dragProjectId={dragProjectId}
dropTargetId={dropTargetId}
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
onDragOver={handleDragOver}
onDrop={handleDrop}
onMove={handleMove}
onEdit={(project) => setModalMode({ kind: 'edit', project })}
onDelete={onDelete}
busy={busy}
@@ -0,0 +1,32 @@
/**
* ↑/↓ Reorder für Touch / schmale Viewports (AP1.12c).
*
* @param {{ itemId: string, canMoveUp: boolean, canMoveDown: boolean, onMove: (direction: 'up'|'down') => void, busy?: boolean }} props
*/
export function ReorderControls({ itemId, canMoveUp, canMoveDown, onMove, busy = false }) {
return (
<div className="reorder-controls" aria-label="Reihenfolge">
<button
type="button"
className="reorder-controls__btn"
aria-label="Nach oben"
disabled={!canMoveUp || busy}
onClick={() => onMove('up')}
>
↑
</button>
<button
type="button"
className="reorder-controls__btn"
aria-label="Nach unten"
disabled={!canMoveDown || busy}
onClick={() => onMove('down')}
>
↓
</button>
<span className="sr-only" id={`reorder-${itemId}`}>
Reihenfolge ändern
</span>
</div>
)
}