@@ -50,7 +50,7 @@ import {
50
50
import { Alert } from '@/model/Alert.model'
51
51
import { store } from '@/store/index'
52
52
import { Tokens } from '@/utils/uid'
53
- import { WorkflowState } from '@/model/WorkflowState.model'
53
+ import { WorkflowState , WorkflowStateNames } from '@/model/WorkflowState.model'
54
54
55
55
/** @typedef {import('@apollo/client').ApolloClient } ApolloClient */
56
56
/** @typedef {import('graphql').IntrospectionInputType } IntrospectionInputType */
@@ -88,6 +88,7 @@ import { WorkflowState } from '@/model/WorkflowState.model'
88
88
* @property {string= } _help
89
89
* @property {string= } _appliesTo - type of cylc object this mutation applies to (if cannot determine from args)
90
90
* @property {boolean= } _requiresInfo - whether this mutation needs more info than the cylc object it is operating on (if cannot determine from args)
91
+ * @property {string[]= } _validStates - list of workflow states this mutation is valid for
91
92
*/
92
93
93
94
/**
@@ -118,27 +119,30 @@ import { WorkflowState } from '@/model/WorkflowState.model'
118
119
119
120
/**
120
121
* Associates icons with mutations by name.
121
- * {mutation.name: svgIcon}
122
- */
123
- export const mutationIcons = {
124
- '' : mdiCog , // default fallback
125
- broadcast : mdiBullhorn ,
126
- clean : mdiDelete ,
127
- editRuntime : mdiPlaylistEdit ,
128
- hold : mdiPauseCircleOutline , // to distinguish from pause
129
- kill : mdiCloseCircle ,
130
- log : mdiFileDocumentOutline ,
131
- message : mdiEmail ,
132
- pause : mdiPause ,
133
- play : mdiPlay ,
134
- poll : mdiRefreshCircle ,
135
- release : mdiPlayCircleOutline , // to distinguish from play
136
- reload : mdiReload ,
137
- remove : mdiMinusCircleOutline ,
138
- resume : mdiPlay ,
139
- set : mdiVectorPolylineEdit ,
140
- stop : mdiStop ,
141
- trigger : mdiCursorPointer
122
+ * @param {string } name - mutation name
123
+ * @returns {string } - icon svg path
124
+ */
125
+ export function getMutationIcon ( name ) {
126
+ switch ( name ) {
127
+ case 'broadcast' : return mdiBullhorn
128
+ case 'clean' : return mdiDelete
129
+ case 'editRuntime' : return mdiPlaylistEdit
130
+ case 'hold' : return mdiPauseCircleOutline // to distinguish from pause
131
+ case 'kill' : return mdiCloseCircle
132
+ case 'log' : return mdiFileDocumentOutline
133
+ case 'message' : return mdiEmail
134
+ case 'pause' : return mdiPause
135
+ case 'play' : return mdiPlay
136
+ case 'poll' : return mdiRefreshCircle
137
+ case 'release' : return mdiPlayCircleOutline // to distinguish from play
138
+ case 'reload' : return mdiReload
139
+ case 'remove' : return mdiMinusCircleOutline
140
+ case 'resume' : return mdiPlay
141
+ case 'set' : return mdiVectorPolylineEdit
142
+ case 'stop' : return mdiStop
143
+ case 'trigger' : return mdiCursorPointer
144
+ default : return mdiCog
145
+ }
142
146
}
143
147
144
148
/**
@@ -298,14 +302,16 @@ export const dummyMutations = [
298
302
This only applies for the cycle point of the chosen task/family instance.` ,
299
303
args : [ ] ,
300
304
_appliesTo : [ cylcObjects . Namespace , cylcObjects . CyclePoint ] ,
301
- _requiresInfo : true
305
+ _requiresInfo : true ,
306
+ _validStates : [ WorkflowState . RUNNING . name , WorkflowState . PAUSED . name ] ,
302
307
} ,
303
308
{
304
309
name : 'log' ,
305
310
description : 'View the logs.' ,
306
311
args : [ ] ,
307
312
_appliesTo : [ cylcObjects . Workflow , cylcObjects . Namespace , cylcObjects . Job ] ,
308
- _requiresInfo : false
313
+ _requiresInfo : false ,
314
+ _validStates : WorkflowStateNames ,
309
315
} ,
310
316
]
311
317
@@ -429,10 +435,10 @@ export function extractFields (type, fields, types) {
429
435
export function processMutations ( mutations , types ) {
430
436
for ( const mutation of mutations ) {
431
437
mutation . _title = camelToWords ( mutation . name )
432
- mutation . _icon = mutationIcons [ mutation . name ] || mutationIcons [ '' ]
438
+ mutation . _icon = getMutationIcon ( mutation . name )
433
439
mutation . _shortDescription = getMutationShortDesc ( mutation . description )
434
440
mutation . _help = getMutationExtendedDesc ( mutation . description )
435
- mutation . _validStates = getStates ( mutation . description )
441
+ mutation . _validStates ?? = getStates ( mutation . description )
436
442
processArguments ( mutation , types )
437
443
}
438
444
}
@@ -441,25 +447,18 @@ export function processMutations (mutations, types) {
441
447
*
442
448
* @export
443
449
* @param {string= } text - Full mutation description.
444
- * @return {Array<String> }
450
+ * @return {string[] }
445
451
*/
446
452
export function getStates ( text ) {
447
- const defaultStates = [
448
- WorkflowState . RUNNING . name ,
449
- WorkflowState . PAUSED . name ,
450
- WorkflowState . STOPPING . name ,
451
- WorkflowState . STOPPED . name
452
- ]
453
453
if ( ! text ) {
454
- return defaultStates
454
+ return WorkflowStateNames
455
455
}
456
- const re = / V a l i d \s f o r : \s ( .* ) \s w o r k f l o w s ./
457
456
// default to all workflow states
458
- const validStates = text . match ( re )
457
+ const validStates = text . match ( / V a l i d \s f o r : \s ( . * ) \s w o r k f l o w s . / )
459
458
if ( validStates ) {
460
459
return validStates [ 1 ] . replace ( / \s / g, '' ) . split ( ',' )
461
460
}
462
- return defaultStates
461
+ return WorkflowStateNames
463
462
}
464
463
465
464
/**
0 commit comments