updates the compliance component to retrieve values from complianceDataTypes endpoint. removes used client hard codes

This commit is contained in:
Seyi Adebajo 2017-12-12 17:47:28 -08:00
parent d262468070
commit 5ea622ae8e
6 changed files with 100 additions and 111 deletions

View File

@ -4,20 +4,17 @@ import { computed, get, getProperties, getWithDefault } from '@ember/object';
import {
Classification,
defaultFieldDataTypeClassification,
fieldIdentifierTypeIds,
ComplianceFieldIdValue,
hasPredefinedFieldFormat,
IComplianceField,
IFieldIdentifierOption,
isCustomId,
isMixedId,
logicalTypesForGeneric,
logicalTypesForIds,
SuggestionIntent,
IFieldFormatDropdownOption
SuggestionIntent
} from 'wherehows-web/constants';
import { IComplianceDataType } from 'wherehows-web/typings/api/list/compliance-datatypes';
import { fieldChangeSetRequiresReview } from 'wherehows-web/utils/datasets/compliance-policy';
import { isHighConfidenceSuggestion } from 'wherehows-web/utils/datasets/compliance-suggestions';
import noop from 'wherehows-web/utils/noop';
import { hasEnumerableKeys } from 'wherehows-web/utils/object';
export default class DatasetComplianceRow extends DatasetTableRow {
@ -28,6 +25,12 @@ export default class DatasetComplianceRow extends DatasetTableRow {
*/
field: IComplianceField;
/**
* Reference to the compliance data types
* @type {Array<IComplianceDataType>}
*/
complianceDataTypes: Array<IComplianceDataType>;
/**
* Describes action interface for `onFieldIdentifierTypeChange` action
* @memberof DatasetComplianceRow
@ -38,10 +41,7 @@ export default class DatasetComplianceRow extends DatasetTableRow {
* Describes action interface for `onFieldLogicalTypeChange` action
* @memberof DatasetComplianceRow
*/
onFieldLogicalTypeChange: (
field: IComplianceField,
option: { value: void | IFieldFormatDropdownOption['value'] }
) => void;
onFieldLogicalTypeChange: (field: IComplianceField, value: IComplianceField['logicalType']) => void;
/**
* Describes action interface for `onFieldClassificationChange` action
@ -114,12 +114,11 @@ export default class DatasetComplianceRow extends DatasetTableRow {
/**
* Checks if the field format drop-down should be disabled based on the type of the field
* @type {ComputedProperty<boolean>}
* *WIP
* @type {ComputedProperty<void>}
* @memberof DatasetComplianceRow
*/
isFieldFormatDisabled = computed('field.identifierType', function(this: DatasetComplianceRow): boolean {
return hasPredefinedFieldFormat(get(get(this, 'field'), 'identifierType'));
}).readOnly();
isFieldFormatDisabled = computed('field.identifierType', noop).readOnly();
/**
* Takes a field property and extracts the value on the current policy if a suggestion currently exists for the field
@ -128,12 +127,13 @@ export default class DatasetComplianceRow extends DatasetTableRow {
* @memberof DatasetComplianceRow
*/
getCurrentValueBeforeSuggestion(fieldProp: 'logicalType' | 'identifierType'): string | void {
if (hasEnumerableKeys(get(this, 'prediction'))) {
/**
* Current value on policy prior to the suggested value
* @type {string}
*/
const value = get(get(this, 'field'), fieldProp);
/**
* Current value on policy prior to the suggested value
* @type {string}
*/
const value = get(get(this, 'field'), fieldProp);
if (hasEnumerableKeys(get(this, 'prediction')) && value) {
/**
* Field drop down options
*/
@ -148,7 +148,7 @@ export default class DatasetComplianceRow extends DatasetTableRow {
return {
identifierType: getLabel(complianceFieldIdDropdownOptions),
logicalType: getLabel(get(this, 'fieldFormats'))
logicalType: get(this, 'fieldFormats').find(format => format === value)
}[fieldProp];
}
}
@ -213,22 +213,16 @@ export default class DatasetComplianceRow extends DatasetTableRow {
*/
fieldFormats = computed('field.identifierType', function(
this: DatasetComplianceRow
): Array<IFieldFormatDropdownOption> | undefined {
): IComplianceDataType['supportedFieldFormats'] {
const identifierType: ComplianceFieldIdValue = get(get(this, 'field'), 'identifierType');
const urnFieldFormat: IFieldFormatDropdownOption | void = logicalTypesForIds.findBy('value', 'URN');
const fieldFormats: Array<IFieldFormatDropdownOption> = fieldIdentifierTypeIds.includes(identifierType)
? logicalTypesForIds
: logicalTypesForGeneric;
const complianceDataTypes = get(this, 'complianceDataTypes');
const complianceDataType = complianceDataTypes.findBy('id', identifierType);
if (isMixedId(identifierType)) {
return urnFieldFormat ? [urnFieldFormat] : void 0;
if (complianceDataType && complianceDataType.idType) {
return complianceDataType.supportedFieldFormats;
}
if (isCustomId(identifierType)) {
return;
}
return fieldFormats;
return [];
});
/**
@ -237,19 +231,15 @@ export default class DatasetComplianceRow extends DatasetTableRow {
* @type {(ComputedProperty<IFieldFormatDropdownOption | void>)}
* @memberof DatasetComplianceRow
*/
logicalType = computed('field.logicalType', 'prediction', 'fieldFormats', function(
logicalType = computed('field.logicalType', 'prediction', function(
this: DatasetComplianceRow
): IFieldFormatDropdownOption | void {
let {
): IComplianceField['logicalType'] {
const {
field: { logicalType },
fieldFormats,
prediction: { logicalType: suggestedLogicalType } = { logicalType: void 0 }
} = getProperties(this, ['field', 'fieldFormats', 'prediction']);
prediction: { logicalType: suggestedLogicalType } = { logicalType: null }
} = getProperties(this, ['field', 'prediction']);
suggestedLogicalType && (logicalType = suggestedLogicalType);
// Same object reference for equality comparision
return Array.isArray(fieldFormats) ? fieldFormats.findBy('value', logicalType) : fieldFormats;
return suggestedLogicalType || logicalType;
});
/**
@ -278,7 +268,11 @@ export default class DatasetComplianceRow extends DatasetTableRow {
*/
prediction = computed('field.suggestion', 'field.suggestionAuthority', function(
this: DatasetComplianceRow
): { identifierType: ComplianceFieldIdValue; logicalType: string; confidence: number } | void {
): {
identifierType: ComplianceFieldIdValue;
logicalType: IComplianceField['logicalType'];
confidence: number;
} | void {
const field = getWithDefault(this, 'field', <IComplianceField>{});
// If a suggestionAuthority property exists on the field, then the user has already either accepted or ignored
// the suggestion for this field. It's value should not be taken into account on re-renders
@ -310,13 +304,12 @@ export default class DatasetComplianceRow extends DatasetTableRow {
/**
* Handles the updates when the field logical type changes on this field
* @param {IFieldFormatDropdownOption} option contains the selected dropdown value
* @param {(IComplianceField['logicalType'])} value contains the selected dropdown value
*/
onFieldLogicalTypeChange(this: DatasetComplianceRow, option: IFieldFormatDropdownOption | null) {
const { value } = option || { value: void 0 };
onFieldLogicalTypeChange(this: DatasetComplianceRow, value: IComplianceField['logicalType']) {
const onFieldLogicalTypeChange = get(this, 'onFieldLogicalTypeChange');
if (typeof onFieldLogicalTypeChange === 'function') {
onFieldLogicalTypeChange(get(this, 'field'), { value });
onFieldLogicalTypeChange(get(this, 'field'), value);
}
},
@ -352,7 +345,7 @@ export default class DatasetComplianceRow extends DatasetTableRow {
}
if (logicalType) {
this.actions.onFieldLogicalTypeChange.call(this, { value: logicalType });
this.actions.onFieldLogicalTypeChange.call(this, logicalType);
}
}

View File

@ -5,13 +5,11 @@ import {
DatasetClassifiers,
fieldIdentifierTypes,
getFieldIdentifierOptions,
fieldIdentifierTypeIds,
idLogicalTypes,
nonIdFieldLogicalTypes,
defaultFieldDataTypeClassification,
compliancePolicyStrings,
logicalTypesForIds,
logicalTypesForGeneric,
hasPredefinedFieldFormat,
getDefaultLogicalType,
getComplianceSteps,
@ -53,6 +51,14 @@ const {
invalidPolicyData
} = compliancePolicyStrings;
/**
* Takes a list of compliance data types and maps a list of compliance id's with idType set to true
* @param {Array<IComplianceDataType>} [complianceDataTypes=[]] the list of compliance data types to transform
* @return {Array<ComplianceFieldIdValue>}
*/
const getIdTypeDataTypes = (complianceDataTypes = []) =>
complianceDataTypes.filter(complianceDataType => complianceDataType.idType).mapBy('id');
/**
* List of non Id field data type classifications
* @type {Array}
@ -334,9 +340,6 @@ export default Component.extend({
// Map logicalTypes to options consumable by DOM
idLogicalTypes: logicalTypesForIds,
// Map generic logical type to options consumable in DOM
genericLogicalTypes: logicalTypesForGeneric,
// Map of classifiers options for drop down
classifiers: securityClassificationDropdownOptions,
@ -725,7 +728,9 @@ export default Component.extend({
const notify = get(this, 'notifications.notify');
const complianceEntities = get(this, policyComplianceEntitiesKey);
const idFieldsHaveValidLogicalType = this.checkEachEntityByLogicalType(
complianceEntities.filter(({ identifierType }) => fieldIdentifierTypeIds.includes(identifierType)),
complianceEntities.filter(({ identifierType }) =>
getIdTypeDataTypes(get(this, 'complianceDataTypes')).includes(identifierType)
),
[...genericLogicalTypes, ...idLogicalTypes]
);
const fieldIdentifiersAreUnique = isListUnique(complianceEntities.mapBy('identifierField'));
@ -995,11 +1000,13 @@ export default Component.extend({
* Updates the logical type for the given identifierField
* @param {Object} field
* @prop {String} field.identifierField
* @param {Event} e the DOM change event
* @return {*}
* @param {IComplianceField.logicalType} logicalType
* @return {*|void}
*/
onFieldLogicalTypeChange(field, { value: logicalType } = {}) {
onFieldLogicalTypeChange(field, logicalType) {
const { identifierField } = field;
// default to undefined for falsey values
logicalType || (logicalType = void 0);
// If the identifierField does not current exist, invoke onFieldIdentifierChange to add it on the compliance list
if (!field) {

View File

@ -99,13 +99,13 @@ interface INonIdLogicalTypesSignature {
*/
interface IComplianceField {
identifierType: ComplianceFieldIdValue;
logicalType: string;
logicalType: IdLogicalType | null;
classification: Classification;
privacyPolicyExists: boolean;
isDirty: boolean;
suggestion?: {
identifierType: ComplianceFieldIdValue;
logicalType: string;
logicalType: IComplianceField['logicalType'];
securityClassification: Classification;
confidenceLevel: number;
suggestionsModificationTime: number;

View File

@ -185,14 +185,6 @@ const logicalTypesForIds: Array<IFieldFormatDropdownOption> = logicalTypeValueLa
*/
const logicalTypesForGeneric: Array<IFieldFormatDropdownOption> = logicalTypeValueLabel('generic');
/**
* A list of field identifier types that are Ids i.e member ID, org ID, group ID
* @type {Array<ComplianceFieldIdValue>}
*/
const fieldIdentifierTypeIds: Array<ComplianceFieldIdValue> = Object.values(fieldIdentifierTypes)
.filter(({ isId }) => isId)
.map(({ value }) => value);
/**
* Caches a list of fieldIdentifierTypes values
* @type {Array<ComplianceFieldIdValue>}
@ -203,7 +195,6 @@ export {
defaultFieldDataTypeClassification,
securityClassificationDropdownOptions,
formatAsCapitalizedStringWithSpaces,
fieldIdentifierTypeIds,
fieldIdentifierTypeValues,
isMixedId,
isCustomId,

View File

@ -1,6 +1,5 @@
{{yield (hash
cell=(component 'dataset-table-cell')
isFieldFormatDisabled=isFieldFormatDisabled
identifierType=identifierType
identifierField=identifierField
dataType=dataType

View File

@ -65,19 +65,6 @@
</sup>
</a>
{{/head.column}}
{{#head.column class="nacho-table-cell-wrapped"}}
Field Format
<a
target="_blank"
href="http://go/gdpr-taxonomy#MetadataTaxonomyforDataSets-DatasetLevelTags">
<sup>
More Info
<span class="glyphicon glyphicon-question-sign"
title="More information on Field Format"></span>
</sup>
</a>
{{/head.column}}
{{#head.column class="nacho-table-cell-wrapped dataset-compliance-fields__classification-column"}}
Security Classification
<sup>
@ -96,7 +83,7 @@
<tr>
<th></th>
<th colspan="6">
<th colspan="5">
{{disable-bubble-input
title="Search field names"
placeholder="Search field names"
@ -112,6 +99,7 @@
field=field
isNewComplianceInfo=isNewComplianceInfo
complianceFieldIdDropdownOptions=complianceFieldIdDropdownOptions
complianceDataTypes=complianceDataTypes
class=(if field.suggestion "dataset-compliance-fields__has-suggestions")
onFieldLogicalTypeChange=(action 'onFieldLogicalTypeChange')
onFieldClassificationChange=(action 'onFieldClassificationChange')
@ -160,37 +148,48 @@
{{/row.cell}}
{{#row.cell class="dataset-compliance-fields__tall-cell"}}
{{ember-selector
disabled=(not isEditing)
values=complianceFieldIdDropdownOptions
selected=(readonly row.identifierType)
selectionDidChange=(action row.onFieldIdentifierTypeChange)
}}
<div>
{{ember-selector
disabled=(not isEditing)
values=complianceFieldIdDropdownOptions
selected=(readonly row.identifierType)
selectionDidChange=(action row.onFieldIdentifierTypeChange)
}}
{{#if row.identifierTypeBeforeSuggestion}}
<p class="dataset-compliance-fields__current-value">Current: {{row.identifierTypeBeforeSuggestion}}</p>
{{/if}}
{{#if row.identifierTypeBeforeSuggestion}}
<p class="dataset-compliance-fields__current-value">Current: {{row.identifierTypeBeforeSuggestion}}</p>
{{/if}}
</div>
<div>
<span>
Field Format
<a
target="_blank"
href="http://go/gdpr-taxonomy#MetadataTaxonomyforDataSets-DatasetLevelTags">
<sup>
More Info
<span class="glyphicon glyphicon-question-sign"
title="More information on Field Format"></span>
</sup>
</a>
</span>
{{ember-selector
disabled=(not isEditing)
values=row.fieldFormats
selected=(readonly row.logicalType)
selectionDidChange=(action row.onFieldLogicalTypeChange)
}}
{{#if row.logicalTypeBeforeSuggestion}}
<p class="dataset-compliance-fields__current-value">Current: {{row.logicalTypeBeforeSuggestion}}</p>
{{/if}}
</div>
{{/row.cell}}
{{#row.cell class="dataset-compliance-fields__tall-cell"}}
{{#power-select
options=row.fieldFormats
selected=row.logicalType
disabled=(or row.isFieldFormatDisabled (not isEditing))
placeholder="Select Format"
allowClear=true
searchField="label"
triggerClass="ember-power-select-trigger-search"
onchange=(action row.onFieldLogicalTypeChange) as |fieldFormat|}}
{{fieldFormat.label}}
{{/power-select}}
{{#if row.logicalTypeBeforeSuggestion}}
<p class="dataset-compliance-fields__current-value">Current: {{row.logicalTypeBeforeSuggestion}}</p>
{{/if}}
{{/row.cell}}
{{#row.cell class="dataset-compliance-fields__tall-cell dataset-compliance-fields__tall-cell"}}
{{ember-selector
class="nacho-select--hidden-state nacho-select--pre-wrap"
values=classifiers