From 28a12888780492b86e68adb60f267fb0e2a6ae3c Mon Sep 17 00:00:00 2001 From: Chris T Date: Tue, 2 Feb 2021 12:42:15 -0500 Subject: [PATCH] [BI-677] add validation display to trait edit form --- src/components/trait/TraitDetailPanel.vue | 4 +-- src/components/trait/TraitListsTable.vue | 39 +++++++++++++---------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/components/trait/TraitDetailPanel.vue b/src/components/trait/TraitDetailPanel.vue index b79564a1c..fba94c540 100644 --- a/src/components/trait/TraitDetailPanel.vue +++ b/src/components/trait/TraitDetailPanel.vue @@ -126,7 +126,6 @@ import {ValidationError} from "@/breeding-insight/model/errors/ValidationError"; import BaseTraitForm from "@/components/trait/forms/BaseTraitForm.vue"; import EditDataForm from "@/components/forms/EditDataForm.vue"; - import {TableRow} from "@/breeding-insight/model/view_models/TableRow"; import { DataFormEventBusHandler } from '@/components/forms/DataFormEventBusHandler'; @Component({ @@ -147,6 +146,8 @@ private archivable!: boolean; @Prop() private editFormState!: DataFormEventBusHandler + @Prop() + private validationHandler!: ValidationError; private editTrait: Trait | null = null; private scalePostfix = new Set().add(DataType.Ordinal).add(DataType.Nominal); @@ -154,7 +155,6 @@ // Variables for edit form private methodClassOptions: string[] = Object.values(MethodClass); private scaleClassOptions: string[] = Object.values(DataType); - private validationHandler: ValidationError = new ValidationError(); @Watch('editActive', {immediate: true}) watchEdit() { diff --git a/src/components/trait/TraitListsTable.vue b/src/components/trait/TraitListsTable.vue index d3c309d55..e8516ac8e 100644 --- a/src/components/trait/TraitListsTable.vue +++ b/src/components/trait/TraitListsTable.vue @@ -117,6 +117,7 @@ v-bind:edit-active="traitSidePanelState.editActive" v-bind:editable="true" v-bind:edit-form-state="traitSidePanelState.dataFormState" + v-bind:validation-handler="editValidationHandler" v-on:activate-edit="activateEdit($event)" v-on:deactivate-edit="traitSidePanelState.bus.$emit(traitSidePanelState.closePanelEvent)" v-on:trait-change="editTrait = Trait.assign({...$event})" @@ -258,6 +259,7 @@ export default class TraitTable extends Vue { clearSelectedRow() { this.editTrait = undefined; this.originalTrait = undefined; + this.editValidationHandler = new ValidationError(); } async saveTrait() { @@ -272,21 +274,7 @@ export default class TraitTable extends Vue { } catch (error) { if (error instanceof ValidationError) { this.validationHandler = error; - - // Set up overrides for error messages - let deletions: string[] = []; - //TODO: Move this into the class perhaps - if (!this.newTrait.scale!.dataType) { - // Remove scale name error - deletions.push('scale.scaleName'); - } else if (Scale.dataTypeEquals(this.newTrait.scale!.dataType!, DataType.Numerical)) { - // Rename scale name to unit - this.validationHandler.overrideMessage(0, 'scale.scaleName', 'Missing unit', 400); - } else if (Scale.dataTypeEquals(this.newTrait.scale!.dataType!, DataType.Duration)) { - // Rename scale name to unit of time - this.validationHandler.overrideMessage(0, 'scale.scaleName', 'Missing unit of time', 400); - } - + const deletions: string[] = this.processValidationErrors(this.validationHandler, this.newTrait); this.$emit('show-error-notification', `Error creating trait. ${this.validationHandler.condenseErrorsSingleRow(deletions)}`); } else { this.$emit('show-error-notification', 'Error creating trait.'); @@ -296,6 +284,24 @@ export default class TraitTable extends Vue { } } + processValidationErrors(handler: ValidationError, trait: Trait): string[] { + + // Set up overrides for error messages + let deletions: string[] = []; + //TODO: Move this into the class perhaps + if (!trait.scale!.dataType) { + // Remove scale name error + deletions.push('scale.scaleName'); + } else if (Scale.dataTypeEquals(trait.scale!.dataType!, DataType.Numerical)) { + // Rename scale name to unit + handler.overrideMessage(0, 'scale.scaleName', 'Missing unit', 400); + } else if (Scale.dataTypeEquals(trait.scale!.dataType!, DataType.Duration)) { + // Rename scale name to unit of time + handler.overrideMessage(0, 'scale.scaleName', 'Missing unit of time', 400); + } + return deletions; + } + async updateTrait() { try { this.editValidationHandler = new ValidationError(); @@ -319,7 +325,8 @@ export default class TraitTable extends Vue { } catch (error) { if (error instanceof ValidationError) { this.editValidationHandler = error; - this.$emit('show-error-notification', `Error updating trait. ${this.editValidationHandler.condenseErrorsSingleRow()}`); + const deletions: string[] = this.processValidationErrors(this.editValidationHandler, this.editTrait!); + this.$emit('show-error-notification', `Error updating trait. ${this.editValidationHandler.condenseErrorsSingleRow(deletions)}`); } else { this.$emit('show-error-notification', 'Error updating trait.'); }