import { Link } from 'react-router-dom' import { gatePath } from '../utils/routes.js' import { gateTitleById } from './GateSelect.jsx' const DEPENDENCY_TYPE_LABELS = { requires: 'Voraussetzung', blocks: 'Blockiert', related: 'Bezug', parallel_group: 'Parallelgruppe', optional_branch: 'Optional', } const OUTGOING_PHRASES = { requires: 'benötigt', blocks: 'blockiert', related: 'Bezug zu', } const INCOMING_PHRASES = { requires: 'Voraussetzung für', blocks: 'Wird blockiert von', related: 'Bezug von', } function groupDependencies(itemId, dependencies) { /** @type {{ outgoing: typeof dependencies, incoming: typeof dependencies }} */ const groups = { outgoing: [], incoming: [] } for (const dep of dependencies) { if (dep.from_item_id === itemId) groups.outgoing.push(dep) else if (dep.to_item_id === itemId) groups.incoming.push(dep) } return groups } function DependencyRow({ dep, itemId, siblingItems, direction, canManage, busy, onDelete }) { const otherId = direction === 'outgoing' ? dep.to_item_id : dep.from_item_id const otherTitle = gateTitleById(siblingItems, otherId) || otherId const phrase = direction === 'outgoing' ? OUTGOING_PHRASES[dep.dependency_type] || dep.dependency_type : INCOMING_PHRASES[dep.dependency_type] || dep.dependency_type return (
  • {direction === 'outgoing' ? ( <> Dieses Gate {phrase}{' '} {otherTitle} ) : ( <> {phrase}{' '} {otherTitle} )}

    {DEPENDENCY_TYPE_LABELS[dep.dependency_type] || dep.dependency_type} {dep.group_key ? ` · Gruppe ${dep.group_key}` : ''}

    {canManage && (
    )}
  • ) } export function GateDependenciesSection({ itemId, siblingItems = [], dependencies = [], canManage, busy, onAdd, onDelete, }) { const candidates = siblingItems.filter((item) => item.id !== itemId) const { outgoing, incoming } = groupDependencies(itemId, dependencies) const hasAny = outgoing.length > 0 || incoming.length > 0 async function handleAddSubmit(event) { event.preventDefault() const form = event.target const toItemId = form.to_item_id.value const dependencyType = form.dependency_type.value const groupKey = form.group_key?.value?.trim() if (!toItemId) return const body = { to_item_id: toItemId, dependency_type: dependencyType, } if (dependencyType === 'parallel_group') { if (!groupKey) return body.group_key = groupKey } await onAdd(body) form.reset() } return (

    Abhängigkeiten

    Kanten für den Gate-Graph — ausgehende Abhängigkeiten kannst du hier anlegen und entfernen.

    {!hasAny && (

    Noch keine Kanten — im Graph erscheinen Gates sonst nach Reihenfolge.

    )} {outgoing.length > 0 && ( <>

    Ausgehend

    )} {incoming.length > 0 && ( <>

    Eingehend

    )} {canManage && candidates.length > 0 && (

    Kante hinzufügen

    Dieses Gate …

    )} {canManage && candidates.length === 0 && (

    Mindestens ein weiteres Gate im Vorhaben nötig, um Kanten zu definieren.

    )}
    ) }