ensure that fields that are classified have a value in the field format before propagating changes

This commit is contained in:
Seyi Adebajo 2017-04-02 14:35:51 -07:00 committed by Mars Lan
parent 4d16899f5b
commit 620ed3e162

View File

@ -207,6 +207,14 @@ export default Component.extend({
return sourceClassification.setObjects([...updatedClassification]);
},
/**
* Checks that each field in a given source classification has a value
* for the logicalType
* @param {Array} sourceClassification
*/
ensureFieldsContainLogicalType: (sourceClassification = []) =>
sourceClassification.every(({ logicalType }) => logicalType),
actions: {
/**
* Updates the logical type for a field with the provided identifierField
@ -270,7 +278,19 @@ export default Component.extend({
* @return {Boolean}
*/
saveSecuritySpecification() {
this.whenRequestCompletes(get(this, 'onSave')());
/**
* For Each classifier ensure that the fields on the securitySpec
* contain a valid `logicalType` attribute
* @type {Boolean}
*/
const classedFieldsHaveLogicalType = classifiers.every(classifier =>
this.ensureFieldsContainLogicalType(
getWithDefault(this, `${sourceClassificationKey}.${classifier}`, [])
));
if (classedFieldsHaveLogicalType) {
this.whenRequestCompletes(get(this, 'onSave')());
}
return false;
},