← Files ItalicARCHIVED FILE

ui/workflow-summary.js

1.42 KB · Nov 25, 2026 · 00:20 UTC

↓ Download file

/**
 * The line the Library shows under a recording whose workflows ran, from its
 * workflow mark ({status, interrupted?, workflows?}): "Ran Email myself, Add
 * to Reminders", "Email myself failed · Ran Add to Reminders". Problems come
 * first, so a truncated line keeps them. iPhone, Mac and web word the same
 * cases (test-fixtures/recording-workflow-summaries.json).
 */
export function workflowSegments(mark) {
  const workflows = Array.isArray(mark?.workflows) ? mark.workflows : [];
  // A status a newer API adds still reads as ran.
  const outcome = status => status === 'failed' || status === 'interrupted' ? status : 'ran';
  const names = status => workflows.filter(workflow => outcome(workflow.status) === status)
    .map(workflow => String(workflow.name ?? '').trim() || 'Deleted workflow').join(', ');
  const failed = names('failed'), interrupted = names('interrupted'), ran = names('ran');
  const segments = [];
  if (failed) segments.push({text: `${failed} failed`, problem: true});
  if (interrupted) segments.push({text: `${interrupted} interrupted`, problem: true});
  else if (mark?.interrupted) segments.push({text: workflows.length ? 'Interrupted' : 'Workflow interrupted', problem: true});
  if (ran) segments.push({text: `Ran ${ran}`, problem: false});
  if (!segments.length) segments.push(mark?.status === 'failed' ? {text: 'Workflow failed', problem: true} : {text: 'Workflow ran', problem: false});
  return segments;
}

SHA-256: f8b6d012383f9a6d38c0a9e4d2a077708d9bf9be7c33a109a9b53bac15d5df33