diff --git a/wherehows-web/app/components/datasets/containers/dataset-compliance.ts b/wherehows-web/app/components/datasets/containers/dataset-compliance.ts index 775a0119e9..a2b4caf27e 100644 --- a/wherehows-web/app/components/datasets/containers/dataset-compliance.ts +++ b/wherehows-web/app/components/datasets/containers/dataset-compliance.ts @@ -306,7 +306,7 @@ export default class DatasetComplianceContainer extends Component { await this.notifyOnSave( saveDatasetComplianceByUrn(get(this, 'urn'), { ...complianceInfo, - // filter out readonly entities, then fleece readonly attribute from remaining entities before save + // filter out readonly entities, then omit readonly attribute from remaining entities before save complianceEntities: removeReadonlyAttr(editableTags(complianceEntities)) }) ); diff --git a/wherehows-web/app/constants/dataset-compliance.ts b/wherehows-web/app/constants/dataset-compliance.ts index 7d5c9e2607..8b2fd1e97a 100644 --- a/wherehows-web/app/constants/dataset-compliance.ts +++ b/wherehows-web/app/constants/dataset-compliance.ts @@ -3,7 +3,7 @@ import { IdLogicalType, 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'; import { arrayEvery, arrayFilter, arrayMap, arrayReduce, arraySome, reduceArrayAsync } from 'wherehows-web/utils/array'; -import { fleece, hasEnumerableKeys } from 'wherehows-web/utils/object'; +import { omit, hasEnumerableKeys } from 'wherehows-web/utils/object'; import { lastSeenSuggestionInterval } from 'wherehows-web/constants/metadata-acquisition'; import { decodeUrn, isValidCustomValuePattern } from 'wherehows-web/utils/validators/urn'; import { @@ -120,7 +120,7 @@ const editableTags = (entities: Array): Array) => Array} */ const removeReadonlyAttr = <(entities: Array) => Array>arrayMap( - fleece(['readonly']) + (entity: IComplianceEntity) => omit(entity, ['readonly']) ); /** diff --git a/wherehows-web/app/services/notifications.ts b/wherehows-web/app/services/notifications.ts index 08c7c78f81..c6b405a765 100644 --- a/wherehows-web/app/services/notifications.ts +++ b/wherehows-web/app/services/notifications.ts @@ -2,7 +2,7 @@ import Service from '@ember/service'; import { setProperties, get, set } from '@ember/object'; import { delay } from 'wherehows-web/utils/promise-delay'; import { action } from '@ember-decorators/object'; -import { fleece } from 'wherehows-web/utils/object'; +import { omit } from 'wherehows-web/utils/object'; import { notificationDialogActionFactory } from 'wherehows-web/utils/notifications/notifications'; import { noop } from 'wherehows-web/utils/helpers/functions'; @@ -155,14 +155,9 @@ const notificationHandlers: INotificationHandler = { props = { dismissButtonText: 'No', confirmButtonText: 'Yes', ...props }; const { dismissButtonText, confirmButtonText, onDialogToggle } = props; // Removes dismiss or confirm buttons if set to false - let resolvedProps: IConfirmOptions = - dismissButtonText === false - ? fleece(['dismissButtonText'])(props) - : props; - resolvedProps = - confirmButtonText === false - ? fleece(['confirmButtonText'])(props) - : props; + let resolvedProps: IConfirmOptions = dismissButtonText === false ? omit(props, ['dismissButtonText']) : props; + + resolvedProps = confirmButtonText === false ? omit(props, ['confirmButtonText']) : props; resolvedProps = typeof onDialogToggle === 'function' ? props : { ...props, onDialogToggle: noop }; return { diff --git a/wherehows-web/app/utils/api/datasets/owners.ts b/wherehows-web/app/utils/api/datasets/owners.ts index 4bb36e3ef7..e7f6518e34 100644 --- a/wherehows-web/app/utils/api/datasets/owners.ts +++ b/wherehows-web/app/utils/api/datasets/owners.ts @@ -10,7 +10,7 @@ import { datasetUrlByUrn } from 'wherehows-web/utils/api/datasets/shared'; import { getJSON, postJSON } from 'wherehows-web/utils/api/fetcher'; import { getApiRoot, ApiStatus } from 'wherehows-web/utils/api/shared'; import { arrayFilter, arrayMap } from 'wherehows-web/utils/array'; -import { fleece } from 'wherehows-web/utils/object'; +import { omit } from 'wherehows-web/utils/object'; /** * Defines a string enum for valid owner types @@ -149,7 +149,7 @@ const readDatasetSuggestedOwnersByUrn = async (urn: string): Promise} */ const updateDatasetOwnersByUrn = (urn: string, csrfToken: string = '', updatedOwners: Array): Promise<{}> => { - const ownersWithoutModifiedTime = arrayMap(fleece(['modifiedTime'])); + const ownersWithoutModifiedTime = arrayMap((owner: IOwner) => omit(owner, ['modifiedTime'])); return postJSON<{}>({ url: datasetOwnersUrlByUrn(urn), diff --git a/wherehows-web/app/utils/api/datasets/retention.ts b/wherehows-web/app/utils/api/datasets/retention.ts index cf30d3f620..7f1444a9a6 100644 --- a/wherehows-web/app/utils/api/datasets/retention.ts +++ b/wherehows-web/app/utils/api/datasets/retention.ts @@ -2,7 +2,7 @@ import { getJSON, postJSON } from 'wherehows-web/utils/api/fetcher'; import { datasetUrlByUrn } from 'wherehows-web/utils/api/datasets/shared'; import { IDatasetRetention, IGetDatasetRetentionResponse } from 'wherehows-web/typings/api/datasets/retention'; import { isNotFoundApiError } from 'wherehows-web/utils/api'; -import { fleece } from 'wherehows-web/utils/object'; +import { omit } from 'wherehows-web/utils/object'; import { encodeUrn } from 'wherehows-web/utils/validators/urn'; /** @@ -38,7 +38,7 @@ const readDatasetRetentionByUrn = async (urn: string): Promise => postJSON({ url: datasetRetentionUrlByUrn(urn), - data: fleece(['modifiedBy', 'modifiedTime'])(retention) + data: omit(retention, ['modifiedBy', 'modifiedTime']) }); export { readDatasetRetentionByUrn, saveDatasetRetentionByUrn }; diff --git a/wherehows-web/app/utils/datasets/retention.ts b/wherehows-web/app/utils/datasets/retention.ts index 64d3ec0d03..972f72a1a8 100644 --- a/wherehows-web/app/utils/datasets/retention.ts +++ b/wherehows-web/app/utils/datasets/retention.ts @@ -1,6 +1,6 @@ import { IComplianceInfo } from 'wherehows-web/typings/api/datasets/compliance'; import { IDatasetRetention } from 'wherehows-web/typings/api/datasets/retention'; -import { fleece } from 'wherehows-web/utils/object'; +import { pick } from 'wherehows-web/utils/object'; /** * Extracts values from an IComplianceInfo instance to create an instance of IDatasetRetention @@ -8,11 +8,11 @@ import { fleece } from 'wherehows-web/utils/object'; * @returns {IDatasetRetention} */ const extractRetentionFromComplianceInfo = (complianceInfo: IComplianceInfo): IDatasetRetention => { - const { datasetUrn, compliancePurgeNote, complianceType } = fleece([ + const { datasetUrn, compliancePurgeNote, complianceType } = pick(complianceInfo, [ 'complianceType', 'compliancePurgeNote', 'datasetUrn' - ])(complianceInfo); + ]); return { purgeNote: compliancePurgeNote, diff --git a/wherehows-web/app/utils/object.ts b/wherehows-web/app/utils/object.ts index 01ba2361a2..7551a289d7 100644 --- a/wherehows-web/app/utils/object.ts +++ b/wherehows-web/app/utils/object.ts @@ -1,3 +1,18 @@ +import { arrayReduce } from 'wherehows-web/utils/array'; + +/** + * Aliases the exclusion / diff conditional type that specifies that an object + * contains properties from T, that are not in K + * @alias + */ +type Omit = Pick>; + +/** + * Aliases the selection / extract conditional type that specifies that an object + * contains properties from T, that are in K + */ +type Select = Pick>; + /** * Checks if a type is an object * @param {any} candidate the entity to check @@ -12,30 +27,34 @@ const isObject = (candidate: any): candidate is object => */ const hasEnumerableKeys = (object: any): boolean => isObject(object) && !!Object.keys(object).length; -/** - * Function interface for a identity or partial return function - * @interface IPartialOrIdentityTypeFn - * @template T - */ -interface IPartialOrIdentityTypeFn { - (o: T): Partial | T; -} /** * Non mutative object attribute deletion. Removes the specified keys from a copy of the object and returns the copy. * @template T the object type to drop keys from * @template K the keys to be dropped from the object - * @param {Array} [droppedKeys=[]] the list of attributes on T to be dropped - * @returns {IPartialOrIdentityTypeFn} + * @param {T} o + * @param {Array} droppedKeys + * @return {Pick>} */ -const fleece = (droppedKeys: Array = []): IPartialOrIdentityTypeFn => ( - o: T -): Partial | T => { +const omit = (o: T, droppedKeys: Array): Omit => { const partialResult = Object.assign({}, o); - return droppedKeys.reduce((partial, key) => { + return arrayReduce((partial: T, key: K) => { delete partial[key]; return partial; - }, partialResult); + }, partialResult)(droppedKeys); }; -export { isObject, hasEnumerableKeys, fleece }; +/** + * Extracts keys from a source to a new object + * @template T the object to select keys from + * @param {T} o the source object + * @param {Array} pickedKeys + * @return {Select} + */ +const pick = (o: T, pickedKeys: Array): Select => + arrayReduce( + (partial: T, key: K) => (pickedKeys.includes(key) ? Object.assign(partial, { [key]: o[key] }) : partial), + {} + )(pickedKeys); + +export { isObject, hasEnumerableKeys, omit, pick };