Skip to content

Commit 3d64d28

Browse files
authored
Disable Edit Runtime in mutation menu when workflow is stopped/stopping (cylc#1789)
Plus tidy
1 parent fc58b4e commit 3d64d28

File tree

4 files changed

+42
-40
lines changed

4 files changed

+42
-40
lines changed

src/components/cylc/gscan/GScan.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
118118
<script>
119119
import { mdiFilter, mdiFolderRefresh } from '@mdi/js'
120120
import { TaskStateNames } from '@/model/TaskState.model'
121-
import { WorkflowState } from '@/model/WorkflowState.model'
121+
import { WorkflowStateNames } from '@/model/WorkflowState.model'
122122
import Tree from '@/components/cylc/tree/Tree.vue'
123123
import { filterByName, filterByState } from '@/components/cylc/gscan/filters'
124124
import { sortedWorkflowTree } from '@/components/cylc/gscan/sort.js'
@@ -227,7 +227,7 @@ export default {
227227
* @type {{ [name: string]: string[] }}
228228
*/
229229
allStates: {
230-
'workflow state': WorkflowState.enumValues.map(x => x.name),
230+
'workflow state': WorkflowStateNames,
231231
'task state': TaskStateNames,
232232
},
233233
}

src/model/WorkflowState.model.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ export const WorkflowStateOrder = new Map([
5959
[undefined, 9]
6060
])
6161

62+
/** @type {string[]} */
63+
export const WorkflowStateNames = WorkflowState.enumValues.map(({ name }) => name)
64+
6265
export default WorkflowState

src/utils/aotf.js

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
import { Alert } from '@/model/Alert.model'
5151
import { store } from '@/store/index'
5252
import { Tokens } from '@/utils/uid'
53-
import { WorkflowState } from '@/model/WorkflowState.model'
53+
import { WorkflowState, WorkflowStateNames } from '@/model/WorkflowState.model'
5454

5555
/** @typedef {import('@apollo/client').ApolloClient} ApolloClient */
5656
/** @typedef {import('graphql').IntrospectionInputType} IntrospectionInputType */
@@ -88,6 +88,7 @@ import { WorkflowState } from '@/model/WorkflowState.model'
8888
* @property {string=} _help
8989
* @property {string=} _appliesTo - type of cylc object this mutation applies to (if cannot determine from args)
9090
* @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
9192
*/
9293

9394
/**
@@ -118,27 +119,30 @@ import { WorkflowState } from '@/model/WorkflowState.model'
118119

119120
/**
120121
* 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+
}
142146
}
143147

144148
/**
@@ -298,14 +302,16 @@ export const dummyMutations = [
298302
This only applies for the cycle point of the chosen task/family instance.`,
299303
args: [],
300304
_appliesTo: [cylcObjects.Namespace, cylcObjects.CyclePoint],
301-
_requiresInfo: true
305+
_requiresInfo: true,
306+
_validStates: [WorkflowState.RUNNING.name, WorkflowState.PAUSED.name],
302307
},
303308
{
304309
name: 'log',
305310
description: 'View the logs.',
306311
args: [],
307312
_appliesTo: [cylcObjects.Workflow, cylcObjects.Namespace, cylcObjects.Job],
308-
_requiresInfo: false
313+
_requiresInfo: false,
314+
_validStates: WorkflowStateNames,
309315
},
310316
]
311317

@@ -429,10 +435,10 @@ export function extractFields (type, fields, types) {
429435
export function processMutations (mutations, types) {
430436
for (const mutation of mutations) {
431437
mutation._title = camelToWords(mutation.name)
432-
mutation._icon = mutationIcons[mutation.name] || mutationIcons['']
438+
mutation._icon = getMutationIcon(mutation.name)
433439
mutation._shortDescription = getMutationShortDesc(mutation.description)
434440
mutation._help = getMutationExtendedDesc(mutation.description)
435-
mutation._validStates = getStates(mutation.description)
441+
mutation._validStates ??= getStates(mutation.description)
436442
processArguments(mutation, types)
437443
}
438444
}
@@ -441,25 +447,18 @@ export function processMutations (mutations, types) {
441447
*
442448
* @export
443449
* @param {string=} text - Full mutation description.
444-
* @return {Array<String>}
450+
* @return {string[]}
445451
*/
446452
export function getStates (text) {
447-
const defaultStates = [
448-
WorkflowState.RUNNING.name,
449-
WorkflowState.PAUSED.name,
450-
WorkflowState.STOPPING.name,
451-
WorkflowState.STOPPED.name
452-
]
453453
if (!text) {
454-
return defaultStates
454+
return WorkflowStateNames
455455
}
456-
const re = /Valid\sfor:\s(.*)\sworkflows./
457456
// default to all workflow states
458-
const validStates = text.match(re)
457+
const validStates = text.match(/Valid\sfor:\s(.*)\sworkflows./)
459458
if (validStates) {
460459
return validStates[1].replace(/\s/g, '').split(',')
461460
}
462-
return defaultStates
461+
return WorkflowStateNames
463462
}
464463

465464
/**

tests/unit/utils/aotf.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('aotf (Api On The Fly)', () => {
7474
const output = {
7575
...input,
7676
_title: 'Foo Bar',
77-
_icon: aotf.mutationIcons[''],
77+
_icon: aotf.getMutationIcon(),
7878
_shortDescription: 'Short description.',
7979
_help: 'Long\ndescription.\nValid for: stopped, paused workflows.',
8080
_validStates: ['stopped', 'paused']

0 commit comments

Comments
 (0)