diff --git a/wherehows-web/app/components/dataset-compliance.ts b/wherehows-web/app/components/dataset-compliance.ts index ea60f9dad7..1566885992 100644 --- a/wherehows-web/app/components/dataset-compliance.ts +++ b/wherehows-web/app/components/dataset-compliance.ts @@ -29,7 +29,8 @@ import { idTypeFieldsHaveLogicalType, changeSetFieldsRequiringReview, changeSetReviewableAttributeTriggers, - mapSchemaColumnPropsToCurrentPrivacyPolicy + mapSchemaColumnPropsToCurrentPrivacyPolicy, + foldComplianceChangeSets } from 'wherehows-web/constants'; import { isPolicyExpectedShape } from 'wherehows-web/utils/datasets/compliance-policy'; import scrollMonitor from 'scrollmonitor'; @@ -49,6 +50,7 @@ import { IComplianceChangeSet, IComplianceFieldIdentifierOption, IDatasetComplianceActions, + IdentifierFieldWithFieldChangeSetTuple, IDropDownOption, ISchemaFieldsToPolicy, ISchemaFieldsToSuggested, @@ -689,6 +691,18 @@ export default class DatasetCompliance extends Component { } ); + /** + * Reduces the current filtered changeSet to a list of IdentifierFieldWithFieldChangeSetTuple + * @type {ComputedProperty>} + * @memberof DatasetCompliance + */ + foldedChangeSet: ComputedProperty> = computed( + 'filteredChangeSet', + function(this: DatasetCompliance): Array { + return foldComplianceChangeSets(get(this, 'filteredChangeSet')); + } + ); + /** * Invokes external action with flag indicating that at least 1 suggestion exists for a field in the changeSet * @param {Array} changeSet diff --git a/wherehows-web/app/constants/dataset-compliance.ts b/wherehows-web/app/constants/dataset-compliance.ts index 819e21eecd..595c7f7bff 100644 --- a/wherehows-web/app/constants/dataset-compliance.ts +++ b/wherehows-web/app/constants/dataset-compliance.ts @@ -9,6 +9,8 @@ import { decodeUrn } from 'wherehows-web/utils/validators/urn'; import { IComplianceChangeSet, IComplianceFieldIdentifierOption, + IdentifierFieldWithFieldChangeSetTuple, + IIdentifierFieldWithFieldChangeSetObject, ISchemaFieldsToPolicy, ISchemaFieldsToSuggested } from 'wherehows-web/typings/app/dataset-compliance'; @@ -250,6 +252,31 @@ const mergeMappedColumnFieldsWithSuggestions = ( return field; }); +/** + * Creates a map of compliance changeSet identifier field to compliance change sets + * @param {IIdentifierFieldWithFieldChangeSetObject} identifierFieldMap + * @param {IComplianceChangeSet} changeSet + * @returns {IIdentifierFieldWithFieldChangeSetObject} + */ +const foldComplianceChangeSetToField = ( + identifierFieldMap: IIdentifierFieldWithFieldChangeSetObject, + changeSet: IComplianceChangeSet +): IIdentifierFieldWithFieldChangeSetObject => ({ + ...identifierFieldMap, + [changeSet.identifierField]: [...identifierFieldMap[changeSet.identifierField], changeSet] +}); + +/** + * Reduces a list of IComplianceChangeSet to a list of tuples with a complianceChangeSet identifierField + * and a changeSet list + * @param {Array} changeSet + * @returns {Array} + */ +const foldComplianceChangeSets = ( + changeSet: Array +): Array => + Object.entries>(arrayReduce(foldComplianceChangeSetToField, {})(changeSet)); + /** * Builds a default shape for securitySpecification & privacyCompliancePolicy with default / unset values * for non null properties as per Avro schema @@ -364,5 +391,6 @@ export { idTypeFieldsHaveLogicalType, changeSetFieldsRequiringReview, changeSetReviewableAttributeTriggers, - mapSchemaColumnPropsToCurrentPrivacyPolicy + mapSchemaColumnPropsToCurrentPrivacyPolicy, + foldComplianceChangeSets }; diff --git a/wherehows-web/app/typings/app/dataset-compliance.d.ts b/wherehows-web/app/typings/app/dataset-compliance.d.ts index e559bc0ab6..faf1a704ec 100644 --- a/wherehows-web/app/typings/app/dataset-compliance.d.ts +++ b/wherehows-web/app/typings/app/dataset-compliance.d.ts @@ -70,6 +70,19 @@ type IComplianceChangeSet = { suggestionAuthority?: SuggestionIntent; } & SchemaFieldToPolicyValue; +/** + * Describes the mapping of an identifier field to it's compliance changeset list + * @interface IIdentifierFieldWithFieldChangeSetObject + */ +interface IIdentifierFieldWithFieldChangeSetObject { + [identifierField: string]: Array; +} + +/** + * Defines a type for identifierField with it's changeSet tuple + */ +type IdentifierFieldWithFieldChangeSetTuple = [string, Array]; + /** * Defines the generic interface field identifier drop downs * @interface IDropDownOption @@ -120,5 +133,7 @@ export { IDropDownOption, IComplianceFieldIdentifierOption, IComplianceFieldFormatOption, - ISecurityClassificationOption + ISecurityClassificationOption, + IIdentifierFieldWithFieldChangeSetObject, + IdentifierFieldWithFieldChangeSetTuple };