mirror of
				https://github.com/datahub-project/datahub.git
				synced 2025-11-03 20:27:50 +00:00 
			
		
		
		
	Merge pull request #1283 from theseyi/up-types
updates types and refactors object key transform functions. implements write to both retention and compliance apis for persisting
This commit is contained in:
		
						commit
						15373de097
					
				@ -306,7 +306,7 @@ export default class DatasetComplianceContainer extends Component {
 | 
			
		||||
      await this.notifyOnSave<void>(
 | 
			
		||||
        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))
 | 
			
		||||
        })
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
@ -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<IComplianceEntity>): Array<IComplianceEnti
 | 
			
		||||
 * @type {(entities: Array<IComplianceEntity>) => Array<IComplianceEntity>}
 | 
			
		||||
 */
 | 
			
		||||
const removeReadonlyAttr = <(entities: Array<IComplianceEntity>) => Array<IComplianceEntity>>arrayMap(
 | 
			
		||||
  fleece<IComplianceEntity, 'readonly'>(['readonly'])
 | 
			
		||||
  (entity: IComplianceEntity) => omit(entity, ['readonly'])
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
        ? <IConfirmOptions>fleece<IConfirmOptions, 'dismissButtonText'>(['dismissButtonText'])(props)
 | 
			
		||||
        : props;
 | 
			
		||||
    resolvedProps =
 | 
			
		||||
      confirmButtonText === false
 | 
			
		||||
        ? <IConfirmOptions>fleece<IConfirmOptions, 'confirmButtonText'>(['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 {
 | 
			
		||||
 | 
			
		||||
@ -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<IOwnerRespo
 | 
			
		||||
 * @return {Promise<void>}
 | 
			
		||||
 */
 | 
			
		||||
const updateDatasetOwnersByUrn = (urn: string, csrfToken: string = '', updatedOwners: Array<IOwner>): Promise<{}> => {
 | 
			
		||||
  const ownersWithoutModifiedTime = arrayMap(fleece<IOwner, 'modifiedTime'>(['modifiedTime']));
 | 
			
		||||
  const ownersWithoutModifiedTime = arrayMap((owner: IOwner) => omit(owner, ['modifiedTime']));
 | 
			
		||||
 | 
			
		||||
  return postJSON<{}>({
 | 
			
		||||
    url: datasetOwnersUrlByUrn(urn),
 | 
			
		||||
 | 
			
		||||
@ -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<IGetDatasetRetent
 | 
			
		||||
const saveDatasetRetentionByUrn = (urn: string, retention: IDatasetRetention): Promise<IDatasetRetention> =>
 | 
			
		||||
  postJSON<IDatasetRetention>({
 | 
			
		||||
    url: datasetRetentionUrlByUrn(urn),
 | 
			
		||||
    data: fleece<IDatasetRetention, 'modifiedTime' | 'modifiedBy'>(['modifiedBy', 'modifiedTime'])(retention)
 | 
			
		||||
    data: omit(retention, ['modifiedBy', 'modifiedTime'])
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
export { readDatasetRetentionByUrn, saveDatasetRetentionByUrn };
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
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';
 | 
			
		||||
import { isExempt } from 'wherehows-web/constants';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Extracts values from an IComplianceInfo instance to create an instance of IDatasetRetention
 | 
			
		||||
@ -8,14 +9,14 @@ import { fleece } from 'wherehows-web/utils/object';
 | 
			
		||||
 * @returns {IDatasetRetention}
 | 
			
		||||
 */
 | 
			
		||||
const extractRetentionFromComplianceInfo = (complianceInfo: IComplianceInfo): IDatasetRetention => {
 | 
			
		||||
  const { datasetUrn, compliancePurgeNote, complianceType } = <IComplianceInfo>fleece<IComplianceInfo>([
 | 
			
		||||
  let { datasetUrn, compliancePurgeNote, complianceType } = pick(complianceInfo, [
 | 
			
		||||
    'complianceType',
 | 
			
		||||
    'compliancePurgeNote',
 | 
			
		||||
    'datasetUrn'
 | 
			
		||||
  ])(complianceInfo);
 | 
			
		||||
  ]);
 | 
			
		||||
 | 
			
		||||
  return {
 | 
			
		||||
    purgeNote: compliancePurgeNote,
 | 
			
		||||
    purgeNote: complianceType && isExempt(complianceType) ? compliancePurgeNote : '',
 | 
			
		||||
    purgeType: complianceType,
 | 
			
		||||
    datasetUrn: datasetUrn!
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
@ -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<T, K> = Pick<T, Exclude<keyof T, K>>;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Aliases the selection / extract conditional type that specifies that an object
 | 
			
		||||
 * contains properties from T, that are in K
 | 
			
		||||
 */
 | 
			
		||||
type Select<T, K> = Pick<T, Extract<keyof T, K>>;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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<T> {
 | 
			
		||||
  (o: T): Partial<T> | 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<K>} [droppedKeys=[]] the list of attributes on T to be dropped
 | 
			
		||||
 * @returns {IPartialOrIdentityTypeFn<T>}
 | 
			
		||||
 * @param {T} o
 | 
			
		||||
 * @param {Array<K extends keyof T>} droppedKeys
 | 
			
		||||
 * @return {Pick<T, Exclude<keyof T, K extends keyof T>>}
 | 
			
		||||
 */
 | 
			
		||||
const fleece = <T, K extends keyof T = keyof T>(droppedKeys: Array<K> = []): IPartialOrIdentityTypeFn<T> => (
 | 
			
		||||
  o: T
 | 
			
		||||
): Partial<T> | T => {
 | 
			
		||||
const omit = <T, K extends keyof T>(o: T, droppedKeys: Array<K>): Omit<T, K> => {
 | 
			
		||||
  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<K extends keyof T>} pickedKeys
 | 
			
		||||
 * @return {Select<T extends object, K extends keyof T>}
 | 
			
		||||
 */
 | 
			
		||||
const pick = <T extends object, K extends keyof T>(o: T, pickedKeys: Array<K>): Select<T, K> =>
 | 
			
		||||
  arrayReduce(
 | 
			
		||||
    (partial: T, key: K) => (pickedKeys.includes(key) ? Object.assign(partial, { [key]: o[key] }) : partial),
 | 
			
		||||
    <T>{}
 | 
			
		||||
  )(pickedKeys);
 | 
			
		||||
 | 
			
		||||
export { isObject, hasEnumerableKeys, omit, pick };
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user