Merge pull request #1107 from theseyi/multi-tagging-updates

5407 fix variable name casing. adds feature to remove already selecte…
This commit is contained in:
Seyi Adebajo 2018-04-19 13:29:18 -07:00 committed by GitHub
commit 2bb01b94f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 22 deletions

View File

@ -10,6 +10,8 @@ import {
} from 'wherehows-web/typings/app/dataset-compliance';
import { IComplianceDataType } from 'wherehows-web/typings/api/list/compliance-datatypes';
import { action } from 'ember-decorators/object';
import { IComplianceEntity } from 'wherehows-web/typings/api/datasets/compliance';
import { arrayFilter } from 'wherehows-web/utils/array';
/**
* Constant definition for an unselected field format
@ -21,6 +23,16 @@ const unSelectedFieldFormatValue: IDropDownOption<null> = {
isDisabled: true
};
/**
* Creates a filter function that excludes options that are already included in other field tags
* @param {IComplianceEntity.identifierType} currentTagId
* @return {(fieldIdTypeTags: Array<IComplianceEntity["identifierType"]>) => ({ value }: IComplianceFieldIdentifierOption) => boolean}
*/
const resolvedOptionsFilterFn = (currentTagId: IComplianceEntity['identifierType']) => (
fieldIdTypeTags: Array<IComplianceEntity['identifierType']>
) => ({ value }: IComplianceFieldIdentifierOption): boolean =>
!fieldIdTypeTags.includes(value) || value === currentTagId;
export default class DatasetComplianceFieldTag extends Component {
tagName = 'tr';
@ -54,6 +66,13 @@ export default class DatasetComplianceFieldTag extends Component {
*/
parentHasSingleTag: boolean;
/**
* List of identifierTypes for the parent field
* @type {Array<IComplianceEntity['identifierType']>}
* @memberof DatasetComplianceFieldTag
*/
fieldIdentifiers: Array<IComplianceEntity['identifierType']>;
/**
* Reference to the compliance data types
* @type {Array<IComplianceDataType>}
@ -67,25 +86,28 @@ export default class DatasetComplianceFieldTag extends Component {
complianceFieldIdDropdownOptions: Array<IComplianceFieldIdentifierOption>;
/**
* Build the dropdown options available for this tag by filtering out options that are not applicable /available for this tag
* Build the drop down options available for this tag by filtering out options that are not applicable /available for this tag
* @type {ComputedProperty<Array<IComplianceFieldIdentifierOption>>}
* @memberof DatasetComplianceFieldTag
*/
fieldIdDropDownOptions = computed('hasSingleTag', function(
fieldIdDropDownOptions = computed('hasSingleTag', 'fieldIdentifiers', function(
this: DatasetComplianceFieldTag
): Array<IComplianceFieldIdentifierOption> {
const { parentHasSingleTag, complianceFieldIdDropdownOptions: dropDownOptions } = getProperties(this, [
'parentHasSingleTag',
'complianceFieldIdDropdownOptions'
]);
const { parentHasSingleTag, fieldIdentifiers, complianceFieldIdDropdownOptions: allOptions, tag } = getProperties(
this,
['parentHasSingleTag', 'fieldIdentifiers', 'complianceFieldIdDropdownOptions', 'tag']
);
// if the parent field does not have a single tag, then no field can be tagged as ComplianceFieldIdValue.None
if (!parentHasSingleTag) {
const NoneOption = dropDownOptions.findBy('value', ComplianceFieldIdValue.None);
return dropDownOptions.without(NoneOption!);
const thisTagIdentifierType = get(tag, 'identifierType');
const noneOption = allOptions.findBy('value', ComplianceFieldIdValue.None);
// if the parent field does not have a single tag, then no field can be tagged as ComplianceFieldIdValue.None
const options = allOptions.without(noneOption!);
return arrayFilter(resolvedOptionsFilterFn(thisTagIdentifierType)(fieldIdentifiers))(options);
}
return dropDownOptions;
return allOptions;
});
/**

View File

@ -1,5 +1,5 @@
import Component from '@ember/component';
import ComputedProperty, { alias, equal, bool } from '@ember/object/computed';
import ComputedProperty, { alias, equal, bool, mapBy } from '@ember/object/computed';
import { get, set, getWithDefault, getProperties, computed } from '@ember/object';
import { action } from 'ember-decorators/object';
import {
@ -14,12 +14,15 @@ import {
SuggestionIntent,
fieldTagsRequiringReview,
tagsHaveNoneAndNotNoneType,
tagsHaveNoneType
tagsHaveNoneType,
suggestedIdentifierTypesInList
} from 'wherehows-web/constants';
import { getTagSuggestions } from 'wherehows-web/utils/datasets/compliance-suggestions';
import { IColumnFieldProps } from 'wherehows-web/typings/app/dataset-columns';
import { fieldTagsHaveIdentifierType } from 'wherehows-web/constants/dataset-compliance';
import { IComplianceDataType } from 'wherehows-web/typings/api/list/compliance-datatypes';
import { arrayReduce } from 'wherehows-web/utils/array';
import { IComplianceEntity } from 'wherehows-web/typings/api/datasets/compliance';
export default class DatasetComplianceRollupRow extends Component.extend({
tagName: ''
@ -199,23 +202,28 @@ export default class DatasetComplianceRollupRow extends Component.extend({
}
});
/**
* Lists the ComplianceFieldIdValue values this field is currently tagged with
* @type {ComputedProperty<Array<ComplianceFieldIdValue>>}
* @memberof DatasetComplianceRollupRow
*/
taggedIdentifiers: ComputedProperty<Array<IComplianceEntity['identifierType']>> = mapBy(
'fieldChangeSet',
'identifierType'
);
/**
* Lists the identifierTypes that are suggested values but are currently in the fields tags
* @type {ComputedProperty<Array<string>>}
* @memberof DatasetComplianceRollupRow
* TODO: multi valued suggestions
*/
suggestedValuesInChangeSet = computed('fieldChangeSet.@each.identifierType', 'suggestion', function(
suggestedValuesInChangeSet = computed('taggedIdentifiers', 'suggestion', function(
this: DatasetComplianceRollupRow
): Array<string> {
const { fieldChangeSet, suggestion } = getProperties(this, ['fieldChangeSet', 'suggestion']);
return fieldChangeSet.mapBy('identifierType').reduce((list, identifierType) => {
if (suggestion && suggestion.identifierType === identifierType) {
return [...list, identifierType];
}
): Array<IComplianceEntity['identifierType']> {
const { taggedIdentifiers, suggestion } = getProperties(this, ['taggedIdentifiers', 'suggestion']);
return list;
}, []);
return arrayReduce(suggestedIdentifierTypesInList(suggestion), [])(taggedIdentifiers);
});
/**

View File

@ -12,7 +12,8 @@ import {
IIdentifierFieldWithFieldChangeSetObject,
ISchemaFieldsToPolicy,
ISchemaFieldsToSuggested,
IComplianceEntityWithMetadata
IComplianceEntityWithMetadata,
ISuggestedFieldTypeValues
} from 'wherehows-web/typings/app/dataset-compliance';
import {
IColumnFieldProps,
@ -162,6 +163,17 @@ const isRecentSuggestion = (
(!!suggestionModificationTime &&
suggestionModificationTime - parseInt(policyModificationTime) >= lastSeenSuggestionInterval);
/**
* Takes a suggestion and populates a list of ComplianceFieldIdValues if the suggestion matches the identifier
* @param {ISuggestedFieldTypeValues | void} suggestion
* @return {(list: Array<ComplianceFieldIdValue>, identifierType: ComplianceFieldIdValue) => Array<ComplianceFieldIdValue>}
*/
const suggestedIdentifierTypesInList = (suggestion: ISuggestedFieldTypeValues | void) => (
list: Array<IComplianceEntity['identifierType']>,
identifierType: IComplianceEntity['identifierType']
): Array<IComplianceEntity['identifierType']> =>
suggestion && suggestion.identifierType === identifierType ? [...list, identifierType] : list;
/**
* Checks if a compliance policy changeSet field requires user attention: if a suggestion
* is available but the user has not indicated intent or a policy for the field does not currently exist remotely
@ -494,6 +506,7 @@ const sortFoldedChangeSetTuples = (
};
export {
suggestedIdentifierTypesInList,
compliancePolicyStrings,
getFieldIdentifierOption,
getFieldIdentifierOptions,

View File

@ -11,6 +11,7 @@
suggestion=suggestion
isReadonly=isReadonlyField
hasSingleTag=hasSingleTag
taggedIdentifiers=taggedIdentifiers
isReviewRequested=isReviewRequested
suggestionResolution=suggestionResolution
suggestionMatchesCurrentValue=suggestionMatchesCurrentValue

View File

@ -240,6 +240,7 @@
class="dataset-compliance-fields__tag-row"
tag=tag
parentHasSingleTag=row.hasSingleTag
fieldIdentifiers=row.taggedIdentifiers
onTagIdentifierTypeChange=(action "tagIdentifierChanged")
onTagLogicalTypeChange=(action "tagLogicalTypeChanged")
onTagOwnerChange=(action "tagOwnerChanged")