Skip to content

Commit e6dd96a

Browse files
committed
Convert enums to TypeScript
1 parent 345c6d9 commit e6dd96a

36 files changed

+242
-315
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"apexcharts": "3.41.0",
3636
"axios": "1.6.8",
3737
"dedent": "1.5.3",
38-
"enumify": "2.0.0",
3938
"graphiql": "3.2.2",
4039
"graphql": "16.8.1",
4140
"graphql-tag": "2.12.6",

src/components/cylc/SVGTask.vue

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

256256
<script>
257-
import TaskState from '@/model/TaskState.model'
257+
import { TaskState } from '@/model/TaskState.model'
258258
259259
export default {
260260
name: 'SVGTask',
@@ -279,7 +279,7 @@ export default {
279279
methods: {
280280
getRunningStyle () {
281281
if (
282-
this.task.state === TaskState.RUNNING.name &&
282+
this.task.state === TaskState.RUNNING &&
283283
this.startTime &&
284284
this.task.task?.meanElapsedTime
285285
) {

src/components/cylc/cylcObject/Menu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ import {
133133
mdiPencil
134134
} from '@mdi/js'
135135
import { mapGetters, mapState } from 'vuex'
136-
import WorkflowState from '@/model/WorkflowState.model'
136+
import { WorkflowState } from '@/model/WorkflowState.model'
137137
import { VDialogTransition } from 'vuetify/components/transitions'
138138
139139
export default {
@@ -257,7 +257,7 @@ export default {
257257
const nodeReturned = this.getNodes('workflow', [this.node.tokens.workflowID])
258258
status = nodeReturned.length
259259
? nodeReturned[0].node.status
260-
: WorkflowState.RUNNING.name
260+
: WorkflowState.RUNNING
261261
}
262262
return !mutation._validStates.includes(status)
263263
},

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/workflow/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
@@ -315,25 +315,21 @@ export default {
315315
return this.cylcTree.$index[this.workflowId]
316316
},
317317
isRunning () {
318-
return (
319-
this.currentWorkflow &&
320-
(
321-
this.currentWorkflow.node.status === WorkflowState.RUNNING.name ||
322-
this.currentWorkflow.node.status === WorkflowState.PAUSED.name ||
323-
this.currentWorkflow.node.status === WorkflowState.STOPPING.name
324-
)
325-
)
318+
return [
319+
WorkflowState.RUNNING,
320+
WorkflowState.PAUSED,
321+
WorkflowState.STOPPING
322+
].includes(this.currentWorkflow?.node.status)
326323
},
327324
isPaused () {
328325
return (
329-
this.currentWorkflow &&
330-
this.currentWorkflow.node.status === WorkflowState.PAUSED.name
326+
this.currentWorkflow?.node.status === WorkflowState.PAUSED
331327
)
332328
},
333329
isStopped () {
334330
return (
335331
!this.currentWorkflow ||
336-
this.currentWorkflow.node.status === WorkflowState.STOPPED.name
332+
this.currentWorkflow.node.status === WorkflowState.STOPPED
337333
)
338334
},
339335
statusMsg () {
@@ -356,7 +352,7 @@ export default {
356352
// the play/pause button
357353
!this.isStopped &&
358354
!this.expecting.stop &&
359-
this.currentWorkflow.node.status !== WorkflowState.STOPPING.name &&
355+
this.currentWorkflow.node.status !== WorkflowState.STOPPING &&
360356
(
361357
this.expecting.paused === null ||
362358
this.expecting.paused === this.isPaused
@@ -428,7 +424,7 @@ export default {
428424
this.currentWorkflow.id
429425
).then(response => {
430426
if (response.status === mutationStatus.SUCCEEDED) {
431-
this.expecting.stop = WorkflowState.STOPPING
427+
this.expecting.stop = WorkflowState.STOPPING // Huh?
432428
}
433429
})
434430
},

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)