@@ -99,11 +99,13 @@ const taskStatesOrdered = [
9999/**
100100 * Get aggregated task state totals for all descendents of a node.
101101 *
102+ * Also get latest state tasks for workflow nodes.
103+ *
102104 * @param {Object} node
103105 * @param {Record<string, number>} stateTotals - Accumulator for state totals.
104- * @param {Record<string, string[]>} latestTasks - Accumulator for latest tasks.
105106 */
106- function getStatesInfo (node , stateTotals = {}, latestTasks = {}) {
107+ function getStatesInfo (node , stateTotals = {}) {
108+ const latestTasks = {}
107109 // if we aren't at the end of the node tree, continue recurse until we hit something other then a workflow part
108110 if (node .type === ' workflow-part' && node .children ) {
109111 // at every branch, recurse all child nodes except stopped workflows
@@ -118,19 +120,19 @@ function getStatesInfo (node, stateTotals = {}, latestTasks = {}) {
118120 // the non-zero state totals from this node with all the others from the tree
119121 for (const state of taskStatesOrdered) {
120122 let nodeTotal = node .node .stateTotals [state]
121- const nodeLatestTasks = Array . from ( node .node .latestStateTasks ? .[state] ?? [])
123+ let nodeLatestTasks = node .node .latestStateTasks ? .[state] ?? []
122124 if (state === TaskState .SUBMITTED .name ) { // include preparing tasks
123125 nodeTotal += node .node .stateTotals .preparing
124- nodeLatestTasks .push (... (node .node .latestStateTasks ? .preparing ?? []))
126+ nodeLatestTasks = [
127+ ... nodeLatestTasks,
128+ ... (node .node .latestStateTasks ? .preparing ?? []),
129+ ].slice (0 , 5 ) // limit to 5 latest (submitted tasks take priority)
125130 }
126131 if (nodeTotal) {
127132 stateTotals[state] = (stateTotals[state] ?? 0 ) + nodeTotal
128133 }
129134 if (nodeLatestTasks .length ) {
130- latestTasks[state] = [
131- ... (latestTasks[state] ?? []),
132- ... nodeLatestTasks,
133- ].sort ().reverse () // cycle point descending order
135+ latestTasks[state] = nodeLatestTasks
134136 }
135137 }
136138 }
0 commit comments