Skip to content

Commit

Permalink
[BI-677] add validation display to trait edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris T committed Feb 10, 2021
1 parent c5a4cb5 commit 28a1288
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/components/trait/TraitDetailPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -147,14 +146,15 @@
private archivable!: boolean;
@Prop()
private editFormState!: DataFormEventBusHandler
@Prop()
private validationHandler!: ValidationError;

private editTrait: Trait | null = null;
private scalePostfix = new Set<string>().add(DataType.Ordinal).add(DataType.Nominal);

// 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() {
Expand Down
39 changes: 23 additions & 16 deletions src/components/trait/TraitListsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
Expand Down Expand Up @@ -258,6 +259,7 @@ export default class TraitTable extends Vue {
clearSelectedRow() {
this.editTrait = undefined;
this.originalTrait = undefined;
this.editValidationHandler = new ValidationError();
}

async saveTrait() {
Expand All @@ -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.');
Expand All @@ -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();
Expand All @@ -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.');
}
Expand Down

0 comments on commit 28a1288

Please sign in to comment.