From df38c6d04ddaba6ca70be7e49aa98eecb8edce5e Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Wed, 30 Aug 2017 18:41:23 -0700 Subject: [PATCH] moves the data validation for fields to compliance page before transitioning to dataset data types --- .../app/components/dataset-compliance.js | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/wherehows-web/app/components/dataset-compliance.js b/wherehows-web/app/components/dataset-compliance.js index bf265c5b2f..3d842f2d46 100644 --- a/wherehows-web/app/components/dataset-compliance.js +++ b/wherehows-web/app/components/dataset-compliance.js @@ -694,6 +694,7 @@ export default Component.extend({ * @return {any | Promise} */ validateFields() { + const notify = get(this, 'notifications.notify'); const complianceEntities = get(this, policyComplianceEntitiesKey); const idFieldsHaveValidLogicalType = this.checkEachEntityByLogicalType( complianceEntities.filter(({ identifierType }) => fieldIdentifierTypeIds.includes(identifierType)), @@ -703,12 +704,12 @@ export default Component.extend({ const schemaFieldLengthGreaterThanComplianceEntities = this.isSchemaFieldLengthGreaterThanComplianceEntities(); if (!fieldIdentifiersAreUnique || !schemaFieldLengthGreaterThanComplianceEntities) { - get(this, 'notifications').notify('error', { content: complianceDataException }); + notify('error', { content: complianceDataException }); return Promise.reject(new Error(complianceDataException)); } if (!idFieldsHaveValidLogicalType) { - return Promise.reject(get(this, 'notifications').notify('error', { content: missingTypes })); + return Promise.reject(notify('error', { content: missingTypes })); } }, @@ -782,6 +783,20 @@ export default Component.extend({ async onEditDatasetClassification() { const isConfirmed = await this.confirmUnformattedFields(); + // Ensure that the fields on the policy meet the validation criteria before proceeding + // Otherwise exit early + try { + await this.validateFields(); + } catch (e) { + // Flag this dataset's data as problematic + if (e instanceof Error && e.message === complianceDataException) { + set(this, '_hasBadData', true); + window.scrollTo(0, 0); + } + + return; + } + // If user provides confirmation for unformatted fields or there are none, // then validate fields against expectations // otherwise inform user of validation exception @@ -942,15 +957,8 @@ export default Component.extend({ const isSaving = true; const onSave = get(this, 'onSave'); setSaveFlag(isSaving); - await this.validateFields(); return await this.whenRequestCompletes(onSave(), { isSaving }); - } catch (e) { - // Flag this dataset's data as problematic - if (e instanceof Error && e.message === complianceDataException) { - set(this, '_hasBadData', true); - window.scrollTo(0, 0); - } } finally { setSaveFlag(); }