From d20a54e88a002ef935d6678d7d0ef4e48c171ecb Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Tue, 10 Apr 2018 12:19:29 -0700 Subject: [PATCH] refactors compliance typings and constants module definitions/imports --- .../app/components/auto-suggest-action.ts | 2 +- .../app/components/dataset-compliance-row.ts | 10 +- .../app/components/dataset-compliance.ts | 83 ++---------- .../components/datasets/schemaless-tagging.ts | 3 +- .../app/constants/dataset-classification.ts | 3 +- .../app/constants/dataset-compliance.ts | 50 +------ .../app/constants/metadata-acquisition.ts | 3 +- .../app/typings/api/datasets/aclaccess.d.ts | 2 +- .../app/typings/app/dataset-compliance.d.ts | 124 ++++++++++++++++++ .../utils/datasets/compliance-suggestions.ts | 2 +- 10 files changed, 154 insertions(+), 128 deletions(-) create mode 100644 wherehows-web/app/typings/app/dataset-compliance.d.ts diff --git a/wherehows-web/app/components/auto-suggest-action.ts b/wherehows-web/app/components/auto-suggest-action.ts index 1895fb9ada..2d9eed7e06 100644 --- a/wherehows-web/app/components/auto-suggest-action.ts +++ b/wherehows-web/app/components/auto-suggest-action.ts @@ -1,9 +1,9 @@ import Component from '@ember/component'; import ComputedProperty from '@ember/object/computed'; import { computed, getProperties } from '@ember/object'; -import { IComplianceChangeSet } from 'wherehows-web/components/dataset-compliance'; import noop from 'wherehows-web/utils/noop'; import { SuggestionIntent } from 'wherehows-web/constants'; +import { IComplianceChangeSet } from 'wherehows-web/typings/app/dataset-compliance'; /** * Describes the interface for the auto-suggest-action component diff --git a/wherehows-web/app/components/dataset-compliance-row.ts b/wherehows-web/app/components/dataset-compliance-row.ts index ebfa7236bc..cd8d506014 100644 --- a/wherehows-web/app/components/dataset-compliance-row.ts +++ b/wherehows-web/app/components/dataset-compliance-row.ts @@ -1,5 +1,4 @@ import { action } from 'ember-decorators/object'; -import { IComplianceChangeSet } from 'wherehows-web/components/dataset-compliance'; import DatasetTableRow from 'wherehows-web/components/dataset-table-row'; import ComputedProperty, { alias, bool } from '@ember/object/computed'; import { computed, get, getProperties, getWithDefault } from '@ember/object'; @@ -8,9 +7,6 @@ import { ComplianceFieldIdValue, SuggestionIntent, getDefaultSecurityClassification, - IComplianceFieldFormatOption, - IComplianceFieldIdentifierOption, - IDropDownOption, fieldChangeSetRequiresReview, isFieldIdType, changeSetReviewableAttributeTriggers, @@ -21,6 +17,12 @@ import { getFieldSuggestions } from 'wherehows-web/utils/datasets/compliance-sug import noop from 'wherehows-web/utils/noop'; import { hasEnumerableKeys } from 'wherehows-web/utils/object'; import { IComplianceEntity } from 'wherehows-web/typings/api/datasets/compliance'; +import { + IComplianceChangeSet, + IComplianceFieldFormatOption, + IComplianceFieldIdentifierOption, + IDropDownOption +} from 'wherehows-web/typings/app/dataset-compliance'; /** * Constant definition for an unselected field format diff --git a/wherehows-web/app/components/dataset-compliance.ts b/wherehows-web/app/components/dataset-compliance.ts index 738443a7fe..115b9cd7d0 100644 --- a/wherehows-web/app/components/dataset-compliance.ts +++ b/wherehows-web/app/components/dataset-compliance.ts @@ -5,11 +5,10 @@ import { run, schedule, next } from '@ember/runloop'; import { inject } from '@ember/service'; import { classify } from '@ember/string'; import { assert } from '@ember/debug'; -import { IDropDownOption, ISecurityClassificationOption } from 'wherehows-web/constants/dataset-compliance'; import { IDatasetView } from 'wherehows-web/typings/api/datasets/dataset'; import { IDataPlatform } from 'wherehows-web/typings/api/list/platforms'; import { readPlatforms } from 'wherehows-web/utils/api/list/platforms'; - +import { task, TaskInstance } from 'ember-concurrency'; import { getSecurityClassificationDropDownOptions, DatasetClassifiers, @@ -19,7 +18,6 @@ import { getComplianceSteps, isExempt, ComplianceFieldIdValue, - IComplianceFieldIdentifierOption, IDatasetClassificationOption, DatasetClassification, SuggestionIntent, @@ -47,75 +45,16 @@ import { ISuggestedFieldClassification, IComplianceSuggestion } from 'wherehows-web/typings/api/datasets/compliance'; -import { task, TaskInstance } from 'ember-concurrency'; - -/** - * Describes the DatasetCompliance actions index signature to allow - * access to actions using `did${editStepName}` accessors - */ -interface IDatasetComplianceActions { - didEditCompliancePolicy: () => Promise; - didEditPurgePolicy: () => Promise<{} | void>; - didEditDatasetLevelCompliancePolicy: () => Promise; - [K: string]: (...args: Array) => any; -} - -/** - * Alias for the properties defined on an object indicating the values for a compliance entity object in - * addition to related component metadata using in processing ui interactions / rendering for the field - */ -type SchemaFieldToPolicyValue = Pick< - IComplianceEntity, - 'identifierField' | 'identifierType' | 'logicalType' | 'securityClassification' | 'nonOwner' | 'readonly' -> & { - // flag indicating that the field has a current policy upstream - privacyPolicyExists: boolean; - // flag indicating the field changeSet has been modified on the client - isDirty: boolean; - policyModificationTime: IComplianceInfo['modifiedTime']; - dataType: string; -}; - -/** - * Describes the interface for a mapping of field names to type, SchemaFieldToPolicyValue - * @interface ISchemaFieldsToPolicy - */ -export interface ISchemaFieldsToPolicy { - [fieldName: string]: SchemaFieldToPolicyValue; -} - -/** - * Alias for the properties on an object indicating the suggested values for field / record properties - * as well as suggestions metadata - */ -type SchemaFieldToSuggestedValue = Pick< - IComplianceEntity, - 'identifierType' | 'logicalType' | 'securityClassification' -> & - Pick & { - suggestionsModificationTime: IComplianceSuggestion['lastModified']; - }; - -/** - * Describes the mapping of attributes to value types for a datasets schema field names to suggested property values - * @interface ISchemaFieldsToSuggested - */ -export interface ISchemaFieldsToSuggested { - [fieldName: string]: SchemaFieldToSuggestedValue; -} -/** - * Describes the interface for a locally assembled compliance field instance - * used in rendering a compliance row - */ -export type IComplianceChangeSet = { - suggestion?: SchemaFieldToSuggestedValue; - suggestionAuthority?: SuggestionIntent; -} & SchemaFieldToPolicyValue; - -/** - * Defines the applicable string values for compliance fields drop down filter - */ -type ShowAllShowReview = 'showReview' | 'showAll'; +import { + IComplianceChangeSet, + IComplianceFieldIdentifierOption, + IDatasetComplianceActions, + IDropDownOption, + ISchemaFieldsToPolicy, + ISchemaFieldsToSuggested, + ISecurityClassificationOption, + ShowAllShowReview +} from 'wherehows-web/typings/app/dataset-compliance'; const { complianceDataException, diff --git a/wherehows-web/app/components/datasets/schemaless-tagging.ts b/wherehows-web/app/components/datasets/schemaless-tagging.ts index 6794382b74..c87998b16b 100644 --- a/wherehows-web/app/components/datasets/schemaless-tagging.ts +++ b/wherehows-web/app/components/datasets/schemaless-tagging.ts @@ -1,6 +1,7 @@ import Component from '@ember/component'; import { get, computed } from '@ember/object'; -import { getSecurityClassificationDropDownOptions, ISecurityClassificationOption } from 'wherehows-web/constants'; +import { ISecurityClassificationOption } from 'wherehows-web/typings/app/dataset-compliance'; +import { getSecurityClassificationDropDownOptions } from 'wherehows-web/constants'; export default class SchemalessTagging extends Component { classNames = ['schemaless-tagging']; diff --git a/wherehows-web/app/constants/dataset-classification.ts b/wherehows-web/app/constants/dataset-classification.ts index a08acb64f0..9c72d18f0a 100644 --- a/wherehows-web/app/constants/dataset-classification.ts +++ b/wherehows-web/app/constants/dataset-classification.ts @@ -1,5 +1,4 @@ -import { IDropDownOption } from 'wherehows-web/constants'; - +import { IDropDownOption } from 'wherehows-web/typings/app/dataset-compliance'; /** * List of string values for every dataset classifier * @enum {string} diff --git a/wherehows-web/app/constants/dataset-compliance.ts b/wherehows-web/app/constants/dataset-compliance.ts index d3ab73f5cb..e41abd776f 100644 --- a/wherehows-web/app/constants/dataset-compliance.ts +++ b/wherehows-web/app/constants/dataset-compliance.ts @@ -1,9 +1,3 @@ -import { - IComplianceChangeSet, - ISchemaFieldsToPolicy, - ISchemaFieldsToSuggested -} from 'wherehows-web/components/dataset-compliance'; -import { Classification, ComplianceFieldIdValue, IdLogicalType } from 'wherehows-web/constants/datasets/compliance'; import { PurgePolicy } from 'wherehows-web/constants/index'; import { IComplianceEntity, IComplianceInfo } from 'wherehows-web/typings/api/datasets/compliance'; import { IComplianceDataType } from 'wherehows-web/typings/api/list/compliance-datatypes'; @@ -12,40 +6,12 @@ import { fleece } from 'wherehows-web/utils/object'; import { lastSeenSuggestionInterval } from 'wherehows-web/constants/metadata-acquisition'; import { pick } from 'lodash'; import { decodeUrn } from 'wherehows-web/utils/validators/urn'; - -/** - * Defines the generic interface field identifier drop downs - * @interface IDropDownOption - * @template T - */ -interface IDropDownOption { - value: T; - label: string; - isDisabled?: boolean; -} - -/** - * Defines the interface for compliance data type field option - * @interface IComplianceFieldIdentifierOption - * @extends {IDropDownOption} - */ -interface IComplianceFieldIdentifierOption extends IDropDownOption { - isId: boolean; -} - -/** - * Defines the interface for a compliance field format dropdown option - * @interface IComplianceFieldFormatOption - * @extends {(IDropDownOption)} - */ -interface IComplianceFieldFormatOption extends IDropDownOption {} - -/** - * Defines the interface for an each security classification dropdown option - * @interface ISecurityClassificationOption - * @extends {(IDropDownOption)} - */ -interface ISecurityClassificationOption extends IDropDownOption {} +import { + IComplianceChangeSet, + IComplianceFieldIdentifierOption, + ISchemaFieldsToPolicy, + ISchemaFieldsToSuggested +} from 'wherehows-web/typings/app/dataset-compliance'; /** * Defines a map of values for the compliance policy on a dataset @@ -307,10 +273,6 @@ export { filterEditableEntities, isAutoGeneratedPolicy, removeReadonlyAttr, - IComplianceFieldIdentifierOption, - IComplianceFieldFormatOption, - ISecurityClassificationOption, - IDropDownOption, fieldChangeSetRequiresReview, isFieldIdType, mergeMappedColumnFieldsWithSuggestions, diff --git a/wherehows-web/app/constants/metadata-acquisition.ts b/wherehows-web/app/constants/metadata-acquisition.ts index a90c376d83..7d70386324 100644 --- a/wherehows-web/app/constants/metadata-acquisition.ts +++ b/wherehows-web/app/constants/metadata-acquisition.ts @@ -1,8 +1,7 @@ -import { IComplianceChangeSet } from 'wherehows-web/components/dataset-compliance'; -import { ISecurityClassificationOption } from 'wherehows-web/constants/dataset-compliance'; import { Classification, ComplianceFieldIdValue } from 'wherehows-web/constants/datasets/compliance'; import { IComplianceDataType } from 'wherehows-web/typings/api/list/compliance-datatypes'; import { formatAsCapitalizedStringWithSpaces } from 'wherehows-web/utils/helpers/string'; +import { IComplianceChangeSet, ISecurityClassificationOption } from 'wherehows-web/typings/app/dataset-compliance'; /** * Length of time between suggestion modification time and last modified time for the compliance policy diff --git a/wherehows-web/app/typings/api/datasets/aclaccess.d.ts b/wherehows-web/app/typings/api/datasets/aclaccess.d.ts index 904c4ded7a..e37778506f 100644 --- a/wherehows-web/app/typings/api/datasets/aclaccess.d.ts +++ b/wherehows-web/app/typings/api/datasets/aclaccess.d.ts @@ -1,5 +1,5 @@ -import { IDropDownOption } from 'wherehows-web/constants/dataset-compliance'; import { AccessControlAccessType } from 'wherehows-web/utils/datasets/acl-access'; +import { IDropDownOption } from 'wherehows-web/typings/app/dataset-compliance'; /** * Describes the interface for an AccessControlEntry object diff --git a/wherehows-web/app/typings/app/dataset-compliance.d.ts b/wherehows-web/app/typings/app/dataset-compliance.d.ts new file mode 100644 index 0000000000..e559bc0ab6 --- /dev/null +++ b/wherehows-web/app/typings/app/dataset-compliance.d.ts @@ -0,0 +1,124 @@ +import { + IComplianceEntity, + IComplianceInfo, + ISuggestedFieldClassification, + IComplianceSuggestion +} from 'wherehows-web/typings/api/datasets/compliance'; +import { SuggestionIntent } from 'wherehows-web/constants'; +import { Classification, ComplianceFieldIdValue, IdLogicalType } from 'wherehows-web/constants/datasets/compliance'; + +/** + * Describes the DatasetCompliance actions index signature to allow + * access to actions using `did${editStepName}` accessors + */ +interface IDatasetComplianceActions { + didEditCompliancePolicy: () => Promise; + didEditPurgePolicy: () => Promise<{} | void>; + didEditDatasetLevelCompliancePolicy: () => Promise; + [K: string]: (...args: Array) => any; +} + +/** + * Alias for the properties defined on an object indicating the values for a compliance entity object in + * addition to related component metadata using in processing ui interactions / rendering for the field + */ +type SchemaFieldToPolicyValue = Pick< + IComplianceEntity, + 'identifierField' | 'identifierType' | 'logicalType' | 'securityClassification' | 'nonOwner' | 'readonly' +> & { + // flag indicating that the field has a current policy upstream + privacyPolicyExists: boolean; + // flag indicating the field changeSet has been modified on the client + isDirty: boolean; + policyModificationTime: IComplianceInfo['modifiedTime']; + dataType: string; +}; + +/** + * Describes the interface for a mapping of field names to type, SchemaFieldToPolicyValue + * @interface ISchemaFieldsToPolicy + */ +interface ISchemaFieldsToPolicy { + [fieldName: string]: SchemaFieldToPolicyValue; +} + +/** + * Alias for the properties on an object indicating the suggested values for field / record properties + * as well as suggestions metadata + */ +type SchemaFieldToSuggestedValue = Pick< + IComplianceEntity, + 'identifierType' | 'logicalType' | 'securityClassification' +> & + Pick & { + suggestionsModificationTime: IComplianceSuggestion['lastModified']; + }; + +/** + * Describes the mapping of attributes to value types for a datasets schema field names to suggested property values + * @interface ISchemaFieldsToSuggested + */ +interface ISchemaFieldsToSuggested { + [fieldName: string]: SchemaFieldToSuggestedValue; +} +/** + * Describes the interface for a locally assembled compliance field instance + * used in rendering a compliance row + */ +type IComplianceChangeSet = { + suggestion?: SchemaFieldToSuggestedValue; + suggestionAuthority?: SuggestionIntent; +} & SchemaFieldToPolicyValue; + +/** + * Defines the generic interface field identifier drop downs + * @interface IDropDownOption + * @template T + */ +interface IDropDownOption { + value: T; + label: string; + isDisabled?: boolean; +} + +/** + * Defines the interface for compliance data type field option + * @interface IComplianceFieldIdentifierOption + * @extends {IDropDownOption} + */ +interface IComplianceFieldIdentifierOption extends IDropDownOption { + isId: boolean; +} + +/** + * Defines the interface for a compliance field format dropdown option + * @interface IComplianceFieldFormatOption + * @extends {(IDropDownOption)} + */ +interface IComplianceFieldFormatOption extends IDropDownOption {} + +/** + * Defines the interface for an each security classification dropdown option + * @interface ISecurityClassificationOption + * @extends {(IDropDownOption)} + */ +interface ISecurityClassificationOption extends IDropDownOption {} + +/** + * Defines the applicable string values for compliance fields drop down filter + */ +type ShowAllShowReview = 'showReview' | 'showAll'; + +export { + IComplianceChangeSet, + ShowAllShowReview, + IDatasetComplianceActions, + SchemaFieldToPolicyValue, + ISchemaFieldsToPolicy, + SchemaFieldToSuggestedValue, + ISchemaFieldsToSuggested, + IDropDownOption, + IComplianceFieldIdentifierOption, + IComplianceFieldFormatOption, + ISecurityClassificationOption +}; diff --git a/wherehows-web/app/utils/datasets/compliance-suggestions.ts b/wherehows-web/app/utils/datasets/compliance-suggestions.ts index fe88e43932..962fc6b5d9 100644 --- a/wherehows-web/app/utils/datasets/compliance-suggestions.ts +++ b/wherehows-web/app/utils/datasets/compliance-suggestions.ts @@ -1,6 +1,6 @@ -import { IComplianceChangeSet } from 'wherehows-web/components/dataset-compliance'; import { lowQualitySuggestionConfidenceThreshold } from 'wherehows-web/constants'; import { arrayMap } from 'wherehows-web/utils/array'; +import { IComplianceChangeSet } from 'wherehows-web/typings/app/dataset-compliance'; /** * Takes a list of suggestions with confidence values, and if the confidence is greater than