moves the data validation for fields to compliance page before transitioning to dataset data types

This commit is contained in:
Seyi Adebajo 2017-08-30 18:41:23 -07:00
parent c5336bf09d
commit df38c6d04d

View File

@ -694,6 +694,7 @@ export default Component.extend({
* @return {any | Promise<any>} * @return {any | Promise<any>}
*/ */
validateFields() { validateFields() {
const notify = get(this, 'notifications.notify');
const complianceEntities = get(this, policyComplianceEntitiesKey); const complianceEntities = get(this, policyComplianceEntitiesKey);
const idFieldsHaveValidLogicalType = this.checkEachEntityByLogicalType( const idFieldsHaveValidLogicalType = this.checkEachEntityByLogicalType(
complianceEntities.filter(({ identifierType }) => fieldIdentifierTypeIds.includes(identifierType)), complianceEntities.filter(({ identifierType }) => fieldIdentifierTypeIds.includes(identifierType)),
@ -703,12 +704,12 @@ export default Component.extend({
const schemaFieldLengthGreaterThanComplianceEntities = this.isSchemaFieldLengthGreaterThanComplianceEntities(); const schemaFieldLengthGreaterThanComplianceEntities = this.isSchemaFieldLengthGreaterThanComplianceEntities();
if (!fieldIdentifiersAreUnique || !schemaFieldLengthGreaterThanComplianceEntities) { if (!fieldIdentifiersAreUnique || !schemaFieldLengthGreaterThanComplianceEntities) {
get(this, 'notifications').notify('error', { content: complianceDataException }); notify('error', { content: complianceDataException });
return Promise.reject(new Error(complianceDataException)); return Promise.reject(new Error(complianceDataException));
} }
if (!idFieldsHaveValidLogicalType) { 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() { async onEditDatasetClassification() {
const isConfirmed = await this.confirmUnformattedFields(); 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, // If user provides confirmation for unformatted fields or there are none,
// then validate fields against expectations // then validate fields against expectations
// otherwise inform user of validation exception // otherwise inform user of validation exception
@ -942,15 +957,8 @@ export default Component.extend({
const isSaving = true; const isSaving = true;
const onSave = get(this, 'onSave'); const onSave = get(this, 'onSave');
setSaveFlag(isSaving); setSaveFlag(isSaving);
await this.validateFields();
return await this.whenRequestCompletes(onSave(), { isSaving }); 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 { } finally {
setSaveFlag(); setSaveFlag();
} }