feat(roadmaps): Steckbrett-Board mit SVG-Kanten, Detail-Panel und Abschluss-Automatik

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Fable 5 committed 2026-07-22 19:59:37 +00:00
1 parent d7f9cf75a3
commit 3cc6ab3343
6 files changed
+656 -2

No files matched your search

+166
View File
@@ -0,0 +1,166 @@
import { useEffect, useState } from 'react'
import { IconTrash, IconX } from '@tabler/icons-react'
import { Card, Button, Field } from '../ui'
import { useEmployees } from '../../hooks/useEmployees'
import { NODE_KIND, NODE_STATUS, NODE_STATUS_LABELS } from '../../lib/roadmaps'
const STATUS_ORDER = [NODE_STATUS.OPEN, NODE_STATUS.IN_PROGRESS, NODE_STATUS.DONE]
/**
* Seitliches Detail-Panel fuer den ausgewaehlten Knoten:
* Titel, Status, Zustaendiger, Deadline, Notizen, eingehende Verbindungen.
*/
export default function NodeDetailPanel({
node,
nodes,
readOnly,
onClose,
onSave,
onSetStatus,
onDelete,
onDisconnect,
}) {
const { employees } = useEmployees()
const [form, setForm] = useState({ title: '', assignedTo: '', deadline: '', notes: '' })
const [saving, setSaving] = useState(false)
const [error, setError] = useState('')
useEffect(() => {
setForm({
title: node.title || '',
assignedTo: node.assignedTo || '',
deadline: node.deadline || '',
notes: node.notes || '',
})
setError('')
}, [node.$id]) // eslint-disable-line react-hooks/exhaustive-deps
const isStart = node.kind === NODE_KIND.START
const incoming = (node.sourceIds || [])
.map((id) => nodes.find((n) => n.$id === id))
.filter(Boolean)
const handleSave = async () => {
if (!form.title.trim()) {
setError('Titel darf nicht leer sein.')
return
}
setSaving(true)
setError('')
const employee = employees.find((e) => e.userId === form.assignedTo)
const result = await onSave(node, {
title: form.title.trim(),
assignedTo: form.assignedTo,
assignedName: employee?.displayName || '',
deadline: form.deadline,
notes: form.notes,
})
setSaving(false)
if (!result.success) setError(result.error)
}
return (
<Card
title={isStart ? 'Start-Knoten' : node.kind === NODE_KIND.GOAL ? 'Ziel-Knoten' : 'Schritt'}
actions={<Button variant="ghost" onClick={onClose}><IconX size={16} /></Button>}
>
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
<Field label="Titel">
<input
type="text"
value={form.title}
maxLength={128}
disabled={readOnly}
onChange={(e) => setForm((f) => ({ ...f, title: e.target.value }))}
/>
</Field>
{!isStart && (
<Field label="Status">
<div style={{ display: 'flex', gap: 6 }}>
{STATUS_ORDER.map((status) => (
<Button
key={status}
variant={node.status === status ? 'primary' : 'default'}
disabled={readOnly}
onClick={() => onSetStatus(node, status)}
>
{NODE_STATUS_LABELS[status]}
</Button>
))}
</div>
</Field>
)}
{!isStart && (
<Field label="Zustaendig">
<select
value={form.assignedTo}
disabled={readOnly}
onChange={(e) => setForm((f) => ({ ...f, assignedTo: e.target.value }))}
>
<option value="">Niemand</option>
{employees.map((e) => (
<option key={e.userId} value={e.userId}>{e.displayName}</option>
))}
</select>
</Field>
)}
{!isStart && (
<Field label="Deadline">
<input
type="date"
value={form.deadline}
disabled={readOnly}
onChange={(e) => setForm((f) => ({ ...f, deadline: e.target.value }))}
/>
</Field>
)}
<Field label="Notizen">
<textarea
rows={4}
value={form.notes}
maxLength={2000}
disabled={readOnly}
placeholder="Details, Anforderungen, Links…"
onChange={(e) => setForm((f) => ({ ...f, notes: e.target.value }))}
/>
</Field>
{incoming.length > 0 && (
<Field label="Eingehende Verbindungen">
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
{incoming.map((source) => (
<div key={source.$id} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 13 }}>
<span className="muted">{source.title}</span>
{!readOnly && (
<Button variant="ghost" title="Verbindung loesen" onClick={() => onDisconnect(source.$id, node)}>
<IconX size={14} />
</Button>
)}
</div>
))}
</div>
</Field>
)}
{error && <p style={{ color: 'var(--danger, #ef4444)', fontSize: 13 }}>{error}</p>}
{!readOnly && (
<div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 8 }}>
{!isStart ? (
<Button variant="ghost" onClick={() => onDelete(node)} title="Knoten loeschen">
<IconTrash size={15} /> Loeschen
</Button>
) : <span />}
<Button variant="primary" onClick={handleSave} disabled={saving}>
{saving ? 'Speichere…' : 'Speichern'}
</Button>
</div>
)}
</div>
</Card>
)
}
+168
View File
@@ -0,0 +1,168 @@
import { useLayoutEffect, useRef, useState, useCallback } from 'react'
import { IconPlus } from '@tabler/icons-react'
import RoadmapNodeCard from './RoadmapNodeCard'
import { NODE_KIND } from '../../lib/roadmaps'
const COLUMN_WIDTH = 230
const COLUMN_GAP = 48
/**
* Steckbrett: Spalten von links (Start) nach rechts (Ziele), Knoten vertikal
* gestapelt, Kanten als SVG-Overlay. Verbinden per Klick-Modus:
* Connect-Handle am Quellknoten -> gueltige Ziele (Spalte weiter rechts) anklicken.
*/
export default function RoadmapBoard({
roadmap,
nodes,
selectedNode,
readOnly,
onSelectNode,
onAddNode,
onConnect,
}) {
const containerRef = useRef(null)
const nodeRefs = useRef({})
const [edges, setEdges] = useState([])
const [connectSource, setConnectSource] = useState(null)
const columnCount = Math.max(roadmap.columnCount || 3, 2)
const columns = Array.from({ length: columnCount }, (_, c) =>
nodes.filter((n) => n.column === c).sort((a, b) => (a.row || 0) - (b.row || 0))
)
const setNodeRef = useCallback((id) => (el) => {
if (el) nodeRefs.current[id] = el
else delete nodeRefs.current[id]
}, [])
// Kanten-Geometrie nach jedem Layout neu berechnen (Anker relativ zum Board)
useLayoutEffect(() => {
const container = containerRef.current
if (!container) return
const compute = () => {
const base = container.getBoundingClientRect()
const next = []
for (const node of nodes) {
for (const sourceId of node.sourceIds || []) {
const sourceEl = nodeRefs.current[sourceId]
const targetEl = nodeRefs.current[node.$id]
if (!sourceEl || !targetEl) continue
const s = sourceEl.getBoundingClientRect()
const t = targetEl.getBoundingClientRect()
next.push({
id: `${sourceId}-${node.$id}`,
x1: s.right - base.left,
y1: s.top + s.height / 2 - base.top,
x2: t.left - base.left,
y2: t.top + t.height / 2 - base.top,
})
}
}
setEdges(next)
}
compute()
const observer = new ResizeObserver(compute)
observer.observe(container)
return () => observer.disconnect()
}, [nodes, columnCount])
const handleStartConnect = (node) => setConnectSource(node)
const handleSelect = async (node) => {
if (connectSource) {
if (node.column > connectSource.column) {
await onConnect(connectSource, node)
}
setConnectSource(null)
return
}
onSelectNode(node)
}
const columnLabel = (c) => {
if (c === 0) return 'Start'
if (c === columnCount - 1) return 'Ziele'
return `Phase ${c}`
}
return (
<div style={{ overflowX: 'auto', paddingBottom: 8 }}>
{connectSource && (
<div
className="muted"
style={{ fontSize: 13, marginBottom: 8, display: 'flex', alignItems: 'center', gap: 10 }}
>
Verbinden von <strong>{connectSource.title}</strong>: Zielknoten rechts davon anklicken.
<button type="button" className="ui-btn" onClick={() => setConnectSource(null)}>Abbrechen</button>
</div>
)}
<div
ref={containerRef}
style={{
position: 'relative',
display: 'grid',
gridTemplateColumns: `repeat(${columnCount}, ${COLUMN_WIDTH}px)`,
gap: `16px ${COLUMN_GAP}px`,
alignItems: 'start',
minWidth: columnCount * (COLUMN_WIDTH + COLUMN_GAP),
padding: '8px 4px',
}}
>
<svg
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', pointerEvents: 'none', zIndex: 0 }}
>
<defs>
<marker id="roadmap-arrow" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto">
<path d="M0,0 L8,4 L0,8 Z" fill="var(--text-muted, #94a3b8)" />
</marker>
</defs>
{edges.map((e) => {
const dx = Math.max((e.x2 - e.x1) / 2, 24)
return (
<path
key={e.id}
d={`M ${e.x1} ${e.y1} C ${e.x1 + dx} ${e.y1}, ${e.x2 - dx} ${e.y2}, ${e.x2} ${e.y2}`}
fill="none"
stroke="var(--text-muted, #94a3b8)"
strokeWidth="1.5"
markerEnd="url(#roadmap-arrow)"
opacity="0.7"
/>
)
})}
</svg>
{columns.map((columnNodes, c) => (
<div key={c} style={{ display: 'flex', flexDirection: 'column', gap: 14, zIndex: 1 }}>
<div className="faint" style={{ fontSize: 11, fontWeight: 700, textTransform: 'uppercase', letterSpacing: 0.5 }}>
{columnLabel(c)}
</div>
{columnNodes.map((node) => (
<RoadmapNodeCard
key={node.$id}
node={node}
selected={selectedNode?.$id === node.$id}
readOnly={readOnly}
connectSource={connectSource}
isValidTarget={Boolean(connectSource) && node.column > connectSource.column}
onSelect={handleSelect}
onStartConnect={handleStartConnect}
nodeRef={setNodeRef(node.$id)}
/>
))}
{!readOnly && c > 0 && (
<button
type="button"
className="ui-btn"
style={{ borderStyle: 'dashed', fontSize: 12 }}
onClick={() => onAddNode(c, c === columnCount - 1 ? NODE_KIND.GOAL : NODE_KIND.STEP, columnNodes.length)}
>
<IconPlus size={14} /> {c === columnCount - 1 ? 'Ziel' : 'Schritt'}
</button>
)}
</div>
))}
</div>
</div>
)
}
+101
View File
@@ -0,0 +1,101 @@
import { IconFlag, IconPlayerPlay, IconLink } from '@tabler/icons-react'
import { NODE_KIND, NODE_STATUS, isNodeOverdue } from '../../lib/roadmaps'
const STATUS_COLORS = {
[NODE_STATUS.OPEN]: 'var(--text-muted, #94a3b8)',
[NODE_STATUS.IN_PROGRESS]: '#fbbf24',
[NODE_STATUS.DONE]: '#34d399',
}
/**
* Knoten-Kachel im Steckbrett.
* connectMode: Board wartet auf Zielauswahl; isValidTarget markiert erlaubte Ziele.
*/
export default function RoadmapNodeCard({
node,
selected,
readOnly,
connectSource,
isValidTarget,
onSelect,
onStartConnect,
nodeRef,
}) {
const overdue = isNodeOverdue(node)
const isStart = node.kind === NODE_KIND.START
const isGoal = node.kind === NODE_KIND.GOAL
const connecting = Boolean(connectSource)
const isConnectSource = connectSource?.$id === node.$id
const borderColor = isConnectSource
? 'var(--accent, #3b82f6)'
: connecting && isValidTarget
? '#34d399'
: selected
? 'var(--accent, #3b82f6)'
: overdue
? 'var(--danger, #ef4444)'
: 'var(--border)'
return (
<div
ref={nodeRef}
onClick={() => onSelect(node)}
style={{
position: 'relative',
background: isGoal ? 'rgba(59,130,246,0.10)' : 'var(--surface-2, rgba(45,55,72,0.65))',
border: `2px solid ${borderColor}`,
borderRadius: 10,
padding: '10px 12px',
cursor: 'pointer',
opacity: connecting && !isValidTarget && !isConnectSource ? 0.45 : 1,
transition: 'border-color 0.15s ease, opacity 0.15s ease',
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
{isStart && <IconPlayerPlay size={15} style={{ flexShrink: 0 }} />}
{isGoal && <IconFlag size={15} style={{ flexShrink: 0, color: '#93c5fd' }} />}
{!isStart && (
<span
title={`Status: ${node.status || 'open'}`}
style={{
width: 10, height: 10, borderRadius: 5, flexShrink: 0,
background: STATUS_COLORS[node.status] || STATUS_COLORS.open,
}}
/>
)}
<span style={{ fontWeight: 600, fontSize: 13, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{node.title}
</span>
</div>
{(node.assignedName || node.deadline) && (
<div style={{ display: 'flex', gap: 8, marginTop: 6, fontSize: 11 }} className="faint">
{node.assignedName && <span>{node.assignedName}</span>}
{node.deadline && (
<span style={overdue ? { color: 'var(--danger, #ef4444)', fontWeight: 700 } : undefined}>
bis {node.deadline.split('-').reverse().join('.')}
</span>
)}
</div>
)}
{!readOnly && !isGoal && !connecting && (
<button
type="button"
title="Verbindung von hier starten"
onClick={(e) => { e.stopPropagation(); onStartConnect(node) }}
style={{
position: 'absolute', right: -11, top: '50%', transform: 'translateY(-50%)',
width: 22, height: 22, borderRadius: 11,
border: '1px solid var(--border)', background: 'var(--surface, #1e293b)',
color: 'var(--text-muted)', display: 'flex', alignItems: 'center',
justifyContent: 'center', cursor: 'crosshair', padding: 0,
}}
>
<IconLink size={12} />
</button>
)}
</div>
)
}