export function countTaskRowsByStatus()

in src/components/Timeline/taskdataUtils.ts [17:52]


export function countTaskRowsByStatus(rows: RowDataModel): RowCounts {
  const counts = {
    all: 0,
    completed: 0,
    running: 0,
    failed: 0,
    pending: 0,
    unknown: 0,
  };
  const keys: Array<keyof typeof counts> = Object.keys(counts) as Array<keyof typeof counts>;

  // Iterate steps
  for (const stepName of Object.keys(rows)) {
    // ...Wihtout steps that start with underscore because user is not interested on them
    if (!stepName.startsWith('_')) {
      const stepRow = rows[stepName];
      // Iterate all task rows on step
      for (const taskId of Object.keys(stepRow.data)) {
        const taskRow = stepRow.data[taskId];

        if (taskRow.length > 0) {
          const task = taskRow[taskRow.length - 1];
          // Every task adds one to all count
          counts.all++;
          // Increment specific count
          const status = task.status as keyof typeof counts;
          if (keys.indexOf(status) > -1) {
            counts[status]++;
          }
        }
      }
    }
  }

  return counts;
}