import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { getInitiativeExecutionGraphState } from '../api/executionPlan.js' import { LoadingState } from './LoadingState.jsx' import { ErrorState } from './ErrorState.jsx' import { EmptyState } from './EmptyState.jsx' import { StatusBadge } from './StatusBadge.jsx' import { ExecutionFlowBadge } from './ExecutionFlowBadge.jsx' import { buildCriticalPathSteps, findNextReadyOnCriticalPath, summarizeCriticalPath, } from '../utils/executionGraph.js' import { actionPath, scopedPath } from '../utils/routes.js' export function CriticalPathPanel({ initiativeId, actions = [], embedded = true, }) { const [graphState, setGraphState] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { if (!initiativeId) { setGraphState(null) setLoading(false) return undefined } let cancelled = false setLoading(true) setError(null) getInitiativeExecutionGraphState(initiativeId) .then((data) => { if (!cancelled) setGraphState(data) }) .catch((err) => { if (!cancelled) setError(err.message) }) .finally(() => { if (!cancelled) setLoading(false) }) return () => { cancelled = true } }, [initiativeId]) const steps = buildCriticalPathSteps(graphState, actions) const summary = summarizeCriticalPath(graphState, actions) const nextReady = findNextReadyOnCriticalPath(graphState, actions) const body = ( <> {loading && } {!loading && error && ( window.location.reload()} /> )} {!loading && !error && steps.length === 0 && ( )} {!loading && !error && steps.length > 0 && ( <>

{summary.message}

{nextReady && (
Nächster Schritt {nextReady.action.title}

Kritischer Pfad — ausführungsbereit, keine blockierenden Vorgänger.

Arbeitspaket öffnen
)}
    {steps.map((step) => (
  1. {step.index}
    {step.title}

    {step.reason}

  2. ))}

Graph unter{' '} Plan → Zielzustände {' '}pflegen.

)} ) if (embedded) { return (

Kritischer Pfad

Längster Abhängigkeitspfad aus dem Execution Graph — Steuerungsantwort für lineare Vorhaben (A2).

{body}
) } return body }