@@ -19,9 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1919 <!-- task summary tooltips -->
2020 <span >
2121 <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)"
2525 >
2626 <v-tooltip color =" black" top >
2727 <template v-slot :activator =" { on } " >
@@ -42,7 +42,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4242 </template >
4343 <!-- tooltip text -->
4444 <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 >
4646 <br />
4747 <span v-for =" (task, index) in tasks.slice(0, maximumTasksDisplayed)" :key =" index" >
4848 {{ task }}<br v-if =" index !== tasks.length -1" />
@@ -56,10 +56,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5656<script >
5757import Job from ' @/components/cylc/Job'
5858import 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+
5971export default {
6072 name: ' WorkflowStateSummary' ,
6173 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: {
6386 type: Object ,
6487 required: true
6588 },
@@ -71,39 +94,39 @@ export default {
7194 components: {
7295 Job
7396 },
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+ },
74109 methods: {
75110 /**
76111 * Get number of tasks we have in a given state. The states are retrieved
77112 * from `latestStateTasks`, and the number of tasks in each state is from
78113 * the `stateTotals`. (`latestStateTasks` includes old tasks).
79114 *
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
83117 */
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
93120 },
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' ] : []
107130 }
108131 }
109132}
0 commit comments