(nodeId: string)
| 15 | // canvas node (WaitNode) and the params panel (WaitParamRow). Keeps the two |
| 16 | // renderings in sync — they differ only in markup/sizing, not in logic. |
| 17 | export function useWaitButton(nodeId: string): WaitButtonModel { |
| 18 | const waitState = useWorkflowRunStore((s) => s.waitStates[nodeId]) |
| 19 | const runningBranchId = useWorkflowRunStore((s) => s.runningBranchId) |
| 20 | const status = useWorkflowRunStore((s) => s.runState.status) |
| 21 | const continueRun = useWorkflowRunStore((s) => s.continueRun) |
| 22 | |
| 23 | const otherBranchRunning = runningBranchId !== null && runningBranchId !== nodeId |
| 24 | // Pre-phase: shared nodes (e.g. Generate Mesh) still running before any branch hands off. |
| 25 | const inPrePhase = status === 'running' && runningBranchId === null |
| 26 | const isRunning = waitState === 'running' |
| 27 | // A pre-phase failure aborts the run before any handoff (status → 'error' while |
| 28 | // this Wait is still 'pending'): it never became runnable, so no Continue. |
| 29 | const runAborted = status === 'error' && waitState === 'pending' |
| 30 | const canContinue = (waitState === 'pending' || waitState === 'done' || waitState === 'error') && !otherBranchRunning && !inPrePhase && !runAborted |
| 31 | const label: 'Retry' | 'Continue' = waitState === 'done' || waitState === 'error' ? 'Retry' : 'Continue' |
| 32 | |
| 33 | const buttonClass = waitState === 'error' |
| 34 | ? 'bg-red-500/15 border-red-500/30 text-red-400 hover:bg-red-500/25' |
| 35 | : waitState === 'done' |
| 36 | ? 'bg-emerald-500/15 border-emerald-500/30 text-emerald-400 hover:bg-emerald-500/25' |
| 37 | : 'bg-amber-500/15 border-amber-500/30 text-amber-400 hover:bg-amber-500/25' |
| 38 | |
| 39 | const statusText = |
| 40 | waitState === 'blocked' ? 'Waiting for the previous Wait to finish…' : |
| 41 | waitState === 'running' ? 'Branch in progress…' : |
| 42 | waitState === 'done' ? 'Branch finished — Retry to re-run.' : |
| 43 | waitState === 'error' ? 'Branch failed — Retry to re-run.' : |
| 44 | waitState === 'pending' && runAborted ? 'Run failed upstream — fix the error and run again.' : |
| 45 | waitState === 'pending' && inPrePhase ? 'Waiting for upstream nodes…' : |
| 46 | waitState === 'pending' && otherBranchRunning ? 'Another branch is running…' : |
| 47 | waitState === 'pending' ? 'Workflow paused — click Continue to run this branch.' : |
| 48 | 'Pauses the workflow until you click Continue.' |
| 49 | |
| 50 | return { waitState, canContinue, isRunning, label, buttonClass, statusText, onContinue: () => continueRun(nodeId) } |
| 51 | } |
no test coverage detected