@@ -19,9 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
<!-- task summary tooltips -->
20
20
<span >
21
21
<span
22
- v-for =" [state, tasks] in getLatestStateTasks(Object.entries(node.node.latestStateTasks)) "
23
- :key =" `${node.id }-summary-${state}`"
24
- :class =" getTaskStateClasses(node.node.stateTotals, state)"
22
+ v-for =" [state, tasks] in validLatestStateTasks "
23
+ :key =" `${nodeId }-summary-${state}`"
24
+ :class =" getTaskStateClasses(state)"
25
25
>
26
26
<v-tooltip color =" black" top >
27
27
<template v-slot :activator =" { on } " >
@@ -42,7 +42,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
42
42
</template >
43
43
<!-- tooltip text -->
44
44
<span >
45
- <span class =" grey--text" >{{ countTasksInState(node.node, state) }} {{ state }}. Recent {{ state }} tasks:</span >
45
+ <span class =" grey--text" >{{ countTasksInState(state) }} {{ state }}. Recent {{ state }} tasks:</span >
46
46
<br />
47
47
<span v-for =" (task, index) in tasks.slice(0, maximumTasksDisplayed)" :key =" index" >
48
48
{{ task }}<br v-if =" index !== tasks.length -1" />
@@ -56,10 +56,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
56
56
<script >
57
57
import Job from ' @/components/cylc/Job'
58
58
import TaskState from ' @/model/TaskState.model'
59
+
60
+ /**
61
+ * Valid states for a latestStateTasks. See computed variable validLatestStateTasks.
62
+ */
63
+ const VALID_STATES = Object .freeze ([
64
+ TaskState .SUBMITTED .name ,
65
+ TaskState .SUBMIT_FAILED .name ,
66
+ TaskState .RUNNING .name ,
67
+ TaskState .SUCCEEDED .name ,
68
+ TaskState .FAILED .name
69
+ ])
70
+
59
71
export default {
60
72
name: ' WorkflowStateSummary' ,
61
73
props: {
62
- node: {
74
+ nodeId: {
75
+ type: String ,
76
+ required: true
77
+ },
78
+ /**
79
+ * @type {Object}
80
+ */
81
+ latestStateTasks: {
82
+ type: Object ,
83
+ required: true
84
+ },
85
+ stateTotals: {
63
86
type: Object ,
64
87
required: true
65
88
},
@@ -71,39 +94,39 @@ export default {
71
94
components: {
72
95
Job
73
96
},
97
+ computed: {
98
+ // TODO: temporary filter, remove after b0 - https://github.com/cylc/cylc-ui/pull/617#issuecomment-805343847
99
+ /**
100
+ * @return {Object}
101
+ */
102
+ validLatestStateTasks () {
103
+ // Values found in: https://github.com/cylc/cylc-flow/blob/9c542f9f3082d3c3d9839cf4330c41cfb2738ba1/cylc/flow/data_store_mgr.py#L143-L149
104
+ return Object .entries (this .latestStateTasks ).filter (entry => {
105
+ return VALID_STATES .includes (entry[0 ])
106
+ })
107
+ }
108
+ },
74
109
methods: {
75
110
/**
76
111
* Get number of tasks we have in a given state. The states are retrieved
77
112
* from `latestStateTasks`, and the number of tasks in each state is from
78
113
* the `stateTotals`. (`latestStateTasks` includes old tasks).
79
114
*
80
- * @param {Object} stateTotals - the workflow object retrieved from GraphQL
81
- * @param {string} state - a workflow state
82
- * @returns {number|*} - the number of tasks in the given state
115
+ * @param {String} state - a workflow state
116
+ * @returns {Number} - the number of tasks in the given state
83
117
*/
84
- countTasksInState (stateTotals , state ) {
85
- if (Object .hasOwnProperty .call (stateTotals, state)) {
86
- return stateTotals[state]
87
- }
88
- return 0
89
- },
90
- getTaskStateClasses (stateTotals , state ) {
91
- const tasksInState = this .countTasksInState (stateTotals, state)
92
- return tasksInState === 0 ? [' empty-state' ] : []
118
+ countTasksInState (state ) {
119
+ return this .stateTotals [state] || 0
93
120
},
94
- // TODO: temporary filter, remove after b0 - https://github.com/cylc/cylc-ui/pull/617#issuecomment-805343847
95
- getLatestStateTasks (latestStateTasks ) {
96
- // Values found in: https://github.com/cylc/cylc-flow/blob/9c542f9f3082d3c3d9839cf4330c41cfb2738ba1/cylc/flow/data_store_mgr.py#L143-L149
97
- const validValues = [
98
- TaskState .SUBMITTED .name ,
99
- TaskState .SUBMIT_FAILED .name ,
100
- TaskState .RUNNING .name ,
101
- TaskState .SUCCEEDED .name ,
102
- TaskState .FAILED .name
103
- ]
104
- return latestStateTasks .filter (entry => {
105
- return validValues .includes (entry[0 ])
106
- })
121
+ /**
122
+ * Defines the CSS class for a state. Useful for handling empty states, when
123
+ * we need to compensate for no children HTML elements.
124
+ *
125
+ * @param {String} state - a workflow state
126
+ * @return {Array<String>} - a list of CSS classes (can be empty).
127
+ */
128
+ getTaskStateClasses (state ) {
129
+ return this .countTasksInState (state) === 0 ? [' empty-state' ] : []
107
130
}
108
131
}
109
132
}
0 commit comments