Skip to content
Snippets Groups Projects
Commit a528f152 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Merge branch 'config-form-validation' into 'master'

Check created worker configuration against existing ones in creation form

Closes #859

See merge request !1137
parents 2e8d7263 3b803a86
No related branches found
No related tags found
1 merge request!1137Check created worker configuration against existing ones in creation form
......@@ -36,7 +36,7 @@
</template>
<script>
import { isPlainObject, isEmpty } from 'lodash'
import { isPlainObject, isEmpty, isEqual } from 'lodash'
import { errorParser } from '~/js/helpers'
import { mapMutations, mapState } from 'vuex'
......@@ -71,14 +71,33 @@ export default {
}
return null
},
validConfig () {
/*
* JSON parsing errors are caught and ignored here as the purpose of validConfig is
* that preexisting only checks valid JSON configurations against existing JSON
* configurations; JSON errors are handled by configError.
*/
try {
const config = JSON.parse(this.workerConfig.configuration.trim())
return config
} catch (e) {
return null
}
},
preexisting () {
return Object.values(this.workerConfigurations[this.workerId]).some(
({ name, configuration }) => name === this.workerConfig.name.trim() || isEqual(configuration, this.validConfig)
)
},
allowCreate () {
return !this.loading && !this.configError && this.workerConfig.name.trim() && this.configInput && this.configInput.trim()
return !this.loading && !this.configError && this.workerConfig.name.trim() && this.configInput && this.configInput.trim() && !this.preexisting
},
disabledTitle () {
const name = this.workerConfig.name.trim()
if (!name && !this.configInput.trim()) return 'Please fill out the creation form'
else if (this.configError | !this.configInput.trim()) return 'Please enter a valid JSON configuration'
else if (!name) return 'Please name your configuration'
else if (this.preexisting) return 'A configuration with this name and/or JSON content already exists for this worker'
else return ''
}
},
......
......@@ -146,6 +146,7 @@ export default {
async saveConfiguration () {
if (this.loading) return
if (this.selectedConfiguration === this.configurationId) {
if (this.configCreate) this.configCreate = false
this.configModal = false
return
}
......@@ -166,6 +167,7 @@ export default {
this.$store.commit('notifications/notify', { type: 'success', text: 'Configuration removed from worker run.' })
}
this.configModal = false
if (this.configCreate) this.configCreate = false
} catch (err) {
this.$store.commit('notifications/notify', { type: 'error', text: errorParser(err) }, { root: true })
} finally {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment