Skip to content

Commit

Permalink
Refactor form submission to conform Edit-Runtime with other mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Nov 21, 2022
1 parent 118c678 commit 089fdc4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
24 changes: 8 additions & 16 deletions src/components/cylc/Mutation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
v-bind="{
mutation,
types,
callbackSubmit: call,
initialData
}"
ref="form"
Expand Down Expand Up @@ -104,7 +103,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<v-btn
text
:color="isValid ? 'primary' : 'error'"
@click="$refs.form.submit()"
@click="submit"
v-bind="attrs"
v-on="on"
data-cy="submit"
Expand Down Expand Up @@ -132,27 +131,24 @@ import EditRuntimeForm from '@/components/graphqlFormGenerator/EditRuntimeForm.v
import Markdown from '@/components/Markdown'
import Task from '@/components/cylc/Task.vue'
import {
mutate,
getMutationShortDesc,
getMutationExtendedDesc
} from '@/utils/aotf'
// enumeration for the mutation status, maps onto Cylc Task status
const status = {
const status = Object.freeze({
waiting: 'waiting',
submitted: 'submitted',
succeeded: 'succeeded',
failed: 'failed',
submitFailed: 'submit-failed'
}
Object.freeze(status)
})
// initial state defined here so we can easily reset the component data
const initialState = {
const initialState = Object.freeze({
response: '',
status: status.waiting
}
Object.freeze(initialState)
})
export default {
name: 'mutation',
Expand Down Expand Up @@ -209,14 +205,10 @@ export default {
methods: {
/* Execute the GraphQL mutation */
async call (args) {
submit () {
this.status = status.submitted
mutate(
this.mutation,
args,
this.$workflowService.apolloClient
).then(response => {
this.status = response.status.name.replace('_', '-')
this.$refs.form.submit().then(({ status }) => {
this.status = status.name.replace('_', '-')
})
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/graphqlFormGenerator/EditRuntimeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,15 @@ export default {
workflows: [tokens.workflow_id]
}
const mutation = await this.$workflowService.getMutation('broadcast')
await mutate(
const response = await mutate(
mutation,
args,
this.$workflowService.apolloClient
)
// Reset after submission (no need to await)
// TODO: remove this if we decide to auto close mutation forms on submission
this.reset()
return response
},
/**
Expand Down
16 changes: 7 additions & 9 deletions src/components/graphqlFormGenerator/FormGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { mdiHelpCircleOutline } from '@mdi/js'
import Markdown from '@/components/Markdown'
import FormInput from '@/components/graphqlFormGenerator/FormInput'
import { getNullValue } from '@/utils/aotf'
import { getNullValue, mutate } from '@/utils/aotf'
export default {
name: 'form-generator',
Expand All @@ -92,10 +92,6 @@ export default {
},
initialData: {
type: Object
},
callbackSubmit: {
// called when the user submits the form
type: Function
}
},
Expand Down Expand Up @@ -162,10 +158,12 @@ export default {
this.model = model
},
submit () {
if (this.callbackSubmit) {
this.callbackSubmit(this.model)
}
async submit () {
return await mutate(
this.mutation,
this.model,
this.$workflowService.apolloClient
)
}
}
}
Expand Down

0 comments on commit 089fdc4

Please sign in to comment.