@@ -47,8 +47,7 @@ import {
47
47
mdiStop
48
48
} from '@mdi/js'
49
49
50
- import AlertModel from '@/model/Alert.model'
51
- import TaskState from '@/model/TaskState.model'
50
+ import Alert from '@/model/Alert.model'
52
51
import store from '@/store/index'
53
52
import { Tokens } from '@/utils/uid'
54
53
@@ -108,7 +107,7 @@ import { IntrospectionInputType } from 'graphql'
108
107
109
108
/**
110
109
* @typedef {Object } MutationResponse
111
- * @property {TaskState } status
110
+ * @property {string } status
112
111
* @property {string } message
113
112
*/
114
113
@@ -280,11 +279,9 @@ export const alternateFields = {
280
279
* Maps onto task status.
281
280
*/
282
281
export const mutationStatus = Object . freeze ( {
283
- [ TaskState . WAITING ] : TaskState . WAITING ,
284
- [ TaskState . SUBMITTED ] : TaskState . SUBMITTED ,
285
- [ TaskState . SUCCEEDED ] : TaskState . SUCCEEDED ,
286
- [ TaskState . FAILED ] : TaskState . FAILED ,
287
- [ TaskState . SUBMIT_FAILED ] : TaskState . SUBMIT_FAILED
282
+ FAILED : 'FAILED' ,
283
+ SUCCEEDED : 'SUCCEEDED' ,
284
+ WARN : 'WARN'
288
285
} )
289
286
290
287
/**
@@ -831,6 +828,17 @@ export function getMutationArgsFromTokens (mutation, tokens) {
831
828
return argspec
832
829
}
833
830
831
+ /**
832
+ * @param {string } message
833
+ * @returns {MutationResponse }
834
+ */
835
+ function _mutateSuccess ( message ) {
836
+ return {
837
+ status : mutationStatus . SUCCEEDED ,
838
+ message
839
+ }
840
+ }
841
+
834
842
/**
835
843
* Handle an error in a called mutation.
836
844
*
@@ -848,15 +856,14 @@ async function _mutateError (mutationName, message, response) {
848
856
}
849
857
850
858
// open a user alert
851
- await store . dispatch ( 'setAlert' , new AlertModel (
852
- `command failed: ${ mutationName } - ${ message } ` ,
853
- null ,
854
- 'error' )
859
+ await store . dispatch (
860
+ 'setAlert' ,
861
+ new Alert ( `Command failed: ${ mutationName } - ${ message } ` , 'error' )
855
862
)
856
863
857
864
// format a response
858
865
return {
859
- status : TaskState . SUBMIT_FAILED ,
866
+ status : mutationStatus . FAILED ,
860
867
message
861
868
}
862
869
}
@@ -869,7 +876,7 @@ async function _mutateError (mutationName, message, response) {
869
876
* @param {ApolloClient } apolloClient
870
877
* @param {string= } cylcID
871
878
*
872
- * @returns {Promise<MutationResponse> } {status, msg}
879
+ * @returns {(MutationResponse | Promise<MutationResponse>) } {status, msg}
873
880
*/
874
881
export async function mutate ( mutation , variables , apolloClient , cylcID ) {
875
882
const mutationStr = constructMutation ( mutation )
@@ -898,24 +905,18 @@ export async function mutate (mutation, variables, apolloClient, cylcID) {
898
905
}
899
906
900
907
try {
901
- const result = response . data [ mutation . name ] . result
908
+ const { result } = response . data [ mutation . name ]
902
909
if ( Array . isArray ( result ) && result . length === 2 ) {
903
910
// regular [commandSucceeded, message] format
904
911
if ( result [ 0 ] === true ) {
905
912
// success
906
- return {
907
- status : TaskState . SUBMITTED ,
908
- message : result [ 1 ]
909
- }
913
+ return _mutateSuccess ( result [ 1 ] )
910
914
}
911
915
// failure (Cylc error, e.g. could not find workflow <x>)
912
916
return _mutateError ( mutation . name , result [ 1 ] , response )
913
917
}
914
918
// command in a different format (e.g. info command)
915
- return {
916
- status : TaskState . SUBMITTED ,
917
- message : result
918
- }
919
+ return _mutateSuccess ( result )
919
920
} catch ( error ) {
920
921
return _mutateError ( mutation . name , 'invalid response' , response )
921
922
}
0 commit comments