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', } 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}

    {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 if (!toItemId) return await onAdd({ to_item_id: toItemId, dependency_type: dependencyType, }) 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.

    )}
    ) }