Skip to content

Commit 3c0d793

Browse files
committed
Simplify the WorkflowStateSummary component, replace methods by computed, use more props
1 parent 250e402 commit 3c0d793

File tree

2 files changed

+56
-31
lines changed

2 files changed

+56
-31
lines changed

src/components/cylc/gscan/GScan.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
146146
class="text-right c-gscan-workflow-states"
147147
>
148148
<WorkflowStateSummary
149-
:node="scope.node"
149+
:node-id="scope.node.id"
150+
:latest-state-tasks="scope.node.node.latestStateTasks"
151+
:state-totals="scope.node.node.stateTotals"
150152
/>
151153
</v-flex>
152154
</v-layout>

src/components/cylc/gscan/WorkflowStateSummary.vue

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
5757
import Job from '@/components/cylc/Job'
5858
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+
5971
export 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

Comments
 (0)