Skip to content

Commit 7bbd5d5

Browse files
committed
Convert enums to TypeScript
1 parent 758f815 commit 7bbd5d5

36 files changed

+242
-315
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"apexcharts": "3.41.0",
3535
"axios": "1.7.2",
3636
"dedent": "1.5.3",
37-
"enumify": "2.0.0",
3837
"graphiql": "3.2.3",
3938
"graphql": "16.8.1",
4039
"graphql-tag": "2.12.6",

src/components/cylc/SVGTask.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
248248

249249
<script setup>
250250
import { computed, inject, ref } from 'vue'
251-
import TaskState from '@/model/TaskState.model'
251+
import { TaskState } from '@/model/TaskState.model'
252252
253253
const props = defineProps({
254254
task: {
@@ -277,7 +277,7 @@ const animResetTime = inject('animResetTime', () => ref(0), true)
277277
278278
const runningStyle = computed(() => {
279279
if (
280-
props.task.state === TaskState.RUNNING.name &&
280+
props.task.state === TaskState.RUNNING &&
281281
props.startTime &&
282282
props.task.task?.meanElapsedTime
283283
) {

src/components/cylc/commandMenu/Menu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ import {
122122
mdiPencil
123123
} from '@mdi/js'
124124
import { mapGetters, mapState } from 'vuex'
125-
import WorkflowState from '@/model/WorkflowState.model'
125+
import { WorkflowState } from '@/model/WorkflowState.model'
126126
import { eventBus } from '@/services/eventBus'
127127
128128
export default {
@@ -233,7 +233,7 @@ export default {
233233
const nodeReturned = this.getNodes('workflow', [this.node.tokens.workflowID])
234234
status = nodeReturned.length
235235
? nodeReturned[0].node.status
236-
: WorkflowState.RUNNING.name
236+
: WorkflowState.RUNNING
237237
}
238238
return !mutation._validStates.includes(status)
239239
},

src/components/cylc/gscan/WorkflowIcon.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2222
</template>
2323

2424
<script>
25-
import WorkflowState from '@/model/WorkflowState.model'
25+
import { WorkflowStateIcons } from '@/model/WorkflowState.model'
2626
import { mdiHelpCircle } from '@mdi/js'
2727
2828
/**
@@ -45,8 +45,7 @@ export default {
4545
* @returns {string} icon
4646
*/
4747
getIcon () {
48-
const state = WorkflowState.enumValues.find(({ name }) => name === this.status)
49-
return state?.icon || mdiHelpCircle
48+
return WorkflowStateIcons.get(this.status) ?? mdiHelpCircle
5049
}
5150
}
5251
}

src/components/cylc/gscan/sort.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import {
1919
sortedIndexBy
2020
} from '@/components/cylc/common/sort'
21-
import { WorkflowState, WorkflowStateOrder } from '@/model/WorkflowState.model'
21+
import { WorkflowState, getWorkflowStateOrder } from '@/model/WorkflowState.model'
2222

2323
/**
2424
* Return an integer suitable for alphabetical sorting of workflow states.
@@ -28,14 +28,14 @@ import { WorkflowState, WorkflowStateOrder } from '@/model/WorkflowState.model'
2828
*/
2929
export function getWorkflowTreeSortValue (node) {
3030
if (node.type === 'workflow') {
31-
return WorkflowStateOrder.get(node.node.status)
31+
return getWorkflowStateOrder(node.node.status)
3232
}
3333
let ret = 9
3434
let temp = 9
3535
let item
3636
const stack = [...node.children]
3737
while (
38-
ret > WorkflowStateOrder.get(WorkflowState.RUNNING.name) &&
38+
ret > getWorkflowStateOrder(WorkflowState.RUNNING) &&
3939
stack.length
4040
) {
4141
// NOTE: if one workflow is running (top sort order) then we don't
@@ -44,7 +44,7 @@ export function getWorkflowTreeSortValue (node) {
4444
if (item.type === 'workflow-part') {
4545
stack.push(...item.children)
4646
} else if (item.type === 'workflow') {
47-
temp = WorkflowStateOrder.get(item.node.status)
47+
temp = getWorkflowStateOrder(item.node.status)
4848
if (temp < ret) {
4949
ret = temp
5050
}

src/components/cylc/tree/GScanTreeItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default {
175175
176176
nodeClass () {
177177
return {
178-
'c-workflow-stopped': this.node.node?.status === WorkflowState.STOPPED.name,
178+
'c-workflow-stopped': this.node.node?.status === WorkflowState.STOPPED,
179179
}
180180
}
181181
},

src/components/cylc/workspace/Toolbar.vue

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ import {
214214
import { startCase } from 'lodash'
215215
import { until } from '@/utils'
216216
import { useToolbar, toolbarHeight } from '@/utils/toolbar'
217-
import WorkflowState from '@/model/WorkflowState.model'
217+
import { WorkflowState } from '@/model/WorkflowState.model'
218218
import graphql from '@/mixins/graphql'
219219
import {
220220
mutationStatus
@@ -321,25 +321,21 @@ export default {
321321
return this.cylcTree.$index[this.workflowId]
322322
},
323323
isRunning () {
324-
return (
325-
this.currentWorkflow &&
326-
(
327-
this.currentWorkflow.node.status === WorkflowState.RUNNING.name ||
328-
this.currentWorkflow.node.status === WorkflowState.PAUSED.name ||
329-
this.currentWorkflow.node.status === WorkflowState.STOPPING.name
330-
)
331-
)
324+
return [
325+
WorkflowState.RUNNING,
326+
WorkflowState.PAUSED,
327+
WorkflowState.STOPPING
328+
].includes(this.currentWorkflow?.node.status)
332329
},
333330
isPaused () {
334331
return (
335-
this.currentWorkflow &&
336-
this.currentWorkflow.node.status === WorkflowState.PAUSED.name
332+
this.currentWorkflow?.node.status === WorkflowState.PAUSED
337333
)
338334
},
339335
isStopped () {
340336
return (
341337
!this.currentWorkflow ||
342-
this.currentWorkflow.node.status === WorkflowState.STOPPED.name
338+
this.currentWorkflow.node.status === WorkflowState.STOPPED
343339
)
344340
},
345341
statusMsg () {
@@ -362,7 +358,7 @@ export default {
362358
// the play/pause button
363359
!this.isStopped &&
364360
!this.expecting.stop &&
365-
this.currentWorkflow.node.status !== WorkflowState.STOPPING.name &&
361+
this.currentWorkflow.node.status !== WorkflowState.STOPPING &&
366362
(
367363
this.expecting.paused === null ||
368364
this.expecting.paused === this.isPaused
@@ -434,7 +430,7 @@ export default {
434430
this.currentWorkflow.id
435431
).then(response => {
436432
if (response.status === mutationStatus.SUCCEEDED) {
437-
this.expecting.stop = WorkflowState.STOPPING
433+
this.expecting.stop = WorkflowState.STOPPING // Huh?
438434
}
439435
})
440436
},

src/mixins/subscription.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
import ViewState from '@/model/ViewState.model'
17+
import { ViewState } from '@/model/ViewState.model'
1818
import { toRaw } from 'vue'
1919
import { mapActions } from 'vuex'
2020

src/model/JobState.model.js renamed to src/model/JobState.model.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,17 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import { Enumify } from 'enumify'
19-
2018
/**
2119
* Cylc valid job states.
2220
*
2321
* @see https://cylc.github.io/cylc-admin/proposal-state-names.html#taskjob-states
2422
*/
25-
class JobState extends Enumify {
26-
static SUBMITTED = new JobState('submitted')
27-
static SUBMIT_FAILED = new JobState('submit-failed')
28-
static RUNNING = new JobState('running')
29-
static SUCCEEDED = new JobState('succeeded')
30-
static FAILED = new JobState('failed')
31-
static _ = this.closeEnum()
32-
33-
/**
34-
* Constructor.
35-
* @param {String} name
36-
*/
37-
constructor (name) {
38-
super()
39-
this.name = name
40-
}
23+
export enum JobState {
24+
SUBMITTED = 'submitted',
25+
SUBMIT_FAILED = 'submit-failed',
26+
RUNNING = 'running',
27+
SUCCEEDED = 'succeeded',
28+
FAILED = 'failed',
4129
}
4230

43-
export const JobStateNames = JobState.enumValues.map(({ name }) => name)
44-
45-
export default JobState
31+
export const JobStateNames: readonly JobState[] = Object.values(JobState)

src/model/Subscription.model.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { toRaw } from 'vue'
19-
import ViewState from '@/model/ViewState.model'
19+
import { ViewState } from '@/model/ViewState.model'
2020
import { Alert } from '@/model/Alert.model'
2121

2222
/**
@@ -77,7 +77,7 @@ class Subscription {
7777
subscriber.setAlert(new Alert(context.message, 'error'))
7878
if (this.debug) {
7979
// eslint-disable-next-line no-console
80-
console.debug(`Subscription error: ${context.message}`, toRaw(viewState), context)
80+
console.debug(`Subscription error: ${context.message}`, ViewState[toRaw(viewState)], context)
8181
}
8282
})
8383
}

0 commit comments

Comments
 (0)