adds error messages display for JSON parse and some issues with matching compliance metadata schema

This commit is contained in:
Seyi Adebajo 2018-06-17 03:51:10 -07:00
parent 84ccd903d2
commit 55cd632f2d
5 changed files with 47 additions and 10 deletions

View File

@ -124,6 +124,13 @@ export default class DatasetCompliance extends Component {
*/
isManualApplyDisabled: boolean = false;
/**
* String representation of a parse error that may have occurred when validating manually entered compliance entities
* @type {string}
* @memberof DatasetCompliance
*/
manualParseError: string = '';
/**
* Flag indicating the current compliance policy edit-view mode
* @type {boolean}
@ -994,13 +1001,13 @@ export default class DatasetCompliance extends Component {
};
const isValid = validateMetadataObject(metadataObject, complianceEntitiesTaxonomy);
set(this, 'isManualApplyDisabled', !isValid);
setProperties(this, { isManualApplyDisabled: !isValid, manualParseError: '' });
if (isValid) {
set(this, 'manuallyEnteredComplianceEntities', metadataObject);
}
} catch {
set(this, 'isManualApplyDisabled', true);
} catch (e) {
setProperties(this, { isManualApplyDisabled: true, manualParseError: e.message });
}
},

View File

@ -93,6 +93,14 @@ $navbar-transition-speed: $banner-animation-speed;
&__content {
white-space: nowrap;
vertical-align: top;
&__error-messages {
display: inline-flex;
align-items: center;
color: get-color(red5);
margin-left: item-spacing(2);
padding-right: item-spacing(2);
}
}
&__item + &__item {

View File

@ -321,6 +321,10 @@
width: 100%;
overflow: hidden;
}
&__manual-entry-errors {
margin-left: item-spacing(2);
}
}
.dataset-compliance-editor {

View File

@ -89,6 +89,16 @@
Cancel
</button>
{{/track-ui-event}}
{{#if (and isInitialEditStep (and manualParseError (not showGuidedComplianceEditMode)))}}
<div class="action-bar__content__error-messages">
{{fa-icon "times-circle-o"}}
<span class="dataset-compliance-fields__manual-entry-errors">
{{manualParseError}}
</span>
</div>
{{/if}}
</div>
{{/if}}

View File

@ -3,6 +3,7 @@ import { DatasetClassifiers } from 'wherehows-web/constants';
import { arrayEvery, arrayMap, arrayReduce } from 'wherehows-web/utils/array';
import { IObject } from 'wherehows-web/typings/generic';
import { isObject } from 'wherehows-web/utils/object';
import { difference } from 'lodash';
/**
* Defines the interface for an IDL that specifies the data types for properties on
@ -146,14 +147,21 @@ const keyValueHasMatch = (object: IObject<any>) => (metadataType: IMetadataType)
* @param {IObject<any>} object
* @param {Array<IMetadataType>} typeMaps
* @return {boolean}
* @throws {Error} if object keys do not match type @names
*/
const keysMatchNames = (object: IObject<any>, typeMaps: Array<IMetadataType>): boolean =>
Object.keys(object)
.sort()
.toString() ===
arrayMap((typeMap: IMetadataType) => typeMap['@name'])(typeMaps)
.sort()
.toString();
const keysMatchNames = (object: IObject<any>, typeMaps: Array<IMetadataType>): boolean => {
const objectKeys = Object.keys(object).sort();
const typeKeys = arrayMap((typeMap: IMetadataType) => typeMap['@name'])(typeMaps).sort();
const objectKeysSerialized = objectKeys.toString();
const typeKeysSerialized = typeKeys.toString();
const match = objectKeysSerialized === typeKeysSerialized;
if (!match) {
throw new Error(`Extra attributes found: ${difference(objectKeys, typeKeys).join(', ')}`);
}
return match;
};
/**
* Checks each key on an object matches the expected types in the typeMap