mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-13 09:54:10 +00:00
refactors dataset-author function definitions by moving non api-related functions from api module to constants
This commit is contained in:
parent
1b98b0f6a9
commit
a3be2ee30b
@ -12,15 +12,11 @@ import {
|
||||
ownerAlreadyExists,
|
||||
confirmOwner,
|
||||
updateOwner,
|
||||
minRequiredConfirmedOwners
|
||||
minRequiredConfirmedOwners,
|
||||
validConfirmedOwners,
|
||||
isRequiredMinOwnersNotConfirmed
|
||||
} from 'wherehows-web/constants/datasets/owner';
|
||||
import {
|
||||
isRequiredMinOwnersNotConfirmed,
|
||||
OwnerIdType,
|
||||
OwnerSource,
|
||||
OwnerType,
|
||||
validConfirmedOwners
|
||||
} from 'wherehows-web/utils/api/datasets/owners';
|
||||
import { OwnerIdType, OwnerSource, OwnerType } from 'wherehows-web/utils/api/datasets/owners';
|
||||
import Notifications, { NotificationEvent } from 'wherehows-web/services/notifications';
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { set } from '@ember/object';
|
||||
import { IOwner } from 'wherehows-web/typings/api/datasets/owners';
|
||||
import { OwnerIdType, OwnerSource, OwnerType, OwnerUrnNamespace } from 'wherehows-web/utils/api/datasets/owners';
|
||||
import { isListUnique } from 'wherehows-web/utils/array';
|
||||
import { set } from '@ember/object';
|
||||
import { arrayFilter, isListUnique } from 'wherehows-web/utils/array';
|
||||
|
||||
/**
|
||||
* Initial user name for candidate owners
|
||||
@ -10,7 +10,7 @@ import { set } from '@ember/object';
|
||||
const defaultOwnerUserName = 'New Owner';
|
||||
|
||||
/**
|
||||
* The minimum required number of owners
|
||||
* The minimum required number of owners with a confirmed status
|
||||
* @type {number}
|
||||
*/
|
||||
const minRequiredConfirmedOwners = 2;
|
||||
@ -90,6 +90,7 @@ function updateOwner<K extends keyof IOwner>(
|
||||
*/
|
||||
const confirmOwner = (owner: IOwner, confirmedBy: string): IOwner['confirmedBy'] =>
|
||||
set(owner, 'confirmedBy', confirmedBy || null);
|
||||
|
||||
/**
|
||||
* Defines the default properties for a newly created IOwner instance
|
||||
*@type {IOwner}
|
||||
@ -109,10 +110,34 @@ const defaultOwnerProps: IOwner = {
|
||||
isActive: true
|
||||
};
|
||||
|
||||
/**
|
||||
* Given an IOwner object, determines if it qualifies as a valid confirmed owner
|
||||
* @param {IOwner}
|
||||
* @return {boolean}
|
||||
*/
|
||||
const isValidConfirmedOwner = ({ confirmedBy, type, idType, isActive }: IOwner): boolean =>
|
||||
!!confirmedBy && type === OwnerType.Owner && idType === OwnerIdType.User && isActive;
|
||||
|
||||
/**
|
||||
* Filters out a list of valid confirmed owners in a list of owners
|
||||
* @type {(array: Array<IOwner> = []) => Array<IOwner>}
|
||||
*/
|
||||
const validConfirmedOwners = arrayFilter(isValidConfirmedOwner);
|
||||
|
||||
/**
|
||||
* Checks that the required minimum number of confirmed users is met with the type Owner and idType User
|
||||
* @param {Array<IOwner>} owners the list of owners to check
|
||||
* @return {boolean}
|
||||
*/
|
||||
const isRequiredMinOwnersNotConfirmed = (owners: Array<IOwner> = []): boolean =>
|
||||
validConfirmedOwners(owners).length < minRequiredConfirmedOwners;
|
||||
|
||||
export {
|
||||
defaultOwnerProps,
|
||||
defaultOwnerUserName,
|
||||
minRequiredConfirmedOwners,
|
||||
validConfirmedOwners,
|
||||
isRequiredMinOwnersNotConfirmed,
|
||||
ownerAlreadyExists,
|
||||
updateOwner,
|
||||
confirmOwner
|
||||
|
@ -13,11 +13,8 @@ import {
|
||||
augmentObjectsWithHtmlComments
|
||||
} from 'wherehows-web/utils/api/datasets/columns';
|
||||
|
||||
import {
|
||||
readDatasetOwners,
|
||||
getUserEntities,
|
||||
isRequiredMinOwnersNotConfirmed
|
||||
} from 'wherehows-web/utils/api/datasets/owners';
|
||||
import { readDatasetOwners, getUserEntities } from 'wherehows-web/utils/api/datasets/owners';
|
||||
import { isRequiredMinOwnersNotConfirmed } from 'wherehows-web/constants/datasets/owner';
|
||||
import { readDataset, datasetUrnToId, readDatasetView } from 'wherehows-web/utils/api/datasets/dataset';
|
||||
import isDatasetUrn from 'wherehows-web/utils/validators/urn';
|
||||
|
||||
|
@ -1,14 +1,13 @@
|
||||
import { ApiRoot, ApiStatus } from 'wherehows-web/utils/api/shared';
|
||||
import { datasetUrlById } from 'wherehows-web/utils/api/datasets/shared';
|
||||
import { IOwner, IOwnerPostResponse, IOwnerResponse } from 'wherehows-web/typings/api/datasets/owners';
|
||||
import {
|
||||
IPartyEntity,
|
||||
IPartyEntityResponse,
|
||||
IPartyProps,
|
||||
IUserEntityMap
|
||||
} from 'wherehows-web/typings/api/datasets/party-entities';
|
||||
import { IOwner, IOwnerPostResponse, IOwnerResponse } from 'wherehows-web/typings/api/datasets/owners';
|
||||
import { datasetUrlById } from 'wherehows-web/utils/api/datasets/shared';
|
||||
import { getJSON, postJSON } from 'wherehows-web/utils/api/fetcher';
|
||||
import { arrayFilter } from 'wherehows-web/utils/array';
|
||||
import { ApiRoot, ApiStatus } from 'wherehows-web/utils/api/shared';
|
||||
|
||||
/**
|
||||
* Defines a string enum for valid owner types
|
||||
@ -51,12 +50,6 @@ enum OwnerSource {
|
||||
Other = 'OTHER'
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimum required number of owners with a confirmed status
|
||||
* @type {number}
|
||||
*/
|
||||
const minRequiredConfirmed = 2;
|
||||
|
||||
/**
|
||||
* Constructs the dataset owners url
|
||||
* @param {number} id the id of the dataset
|
||||
@ -184,31 +177,7 @@ const readPartyEntitiesMap = (partyEntities: Array<IPartyEntity>): IUserEntityMa
|
||||
{}
|
||||
);
|
||||
|
||||
/**
|
||||
* Given an IOwner object, determines if it qualifies as a valid confirmed owner
|
||||
* @param {IOwner}
|
||||
* @return {boolean}
|
||||
*/
|
||||
const isValidConfirmedOwner = ({ confirmedBy, type, idType, isActive }: IOwner): boolean =>
|
||||
!!confirmedBy && type === OwnerType.Owner && idType === OwnerIdType.User && isActive;
|
||||
|
||||
/**
|
||||
* Filters out a list of valid confirmed owners in a list of owners
|
||||
* @type {(array: Array<IOwner> = []) => Array<IOwner>}
|
||||
*/
|
||||
const validConfirmedOwners = arrayFilter(isValidConfirmedOwner);
|
||||
|
||||
/**
|
||||
* Checks that the required minimum number of confirmed users is met with the type Owner and idType User
|
||||
* @param {Array<IOwner>} owners the list of owners to check
|
||||
* @return {boolean}
|
||||
*/
|
||||
const isRequiredMinOwnersNotConfirmed = (owners: Array<IOwner> = []): boolean =>
|
||||
validConfirmedOwners(owners).length < minRequiredConfirmed;
|
||||
|
||||
export {
|
||||
validConfirmedOwners,
|
||||
isRequiredMinOwnersNotConfirmed,
|
||||
readDatasetOwners,
|
||||
readPartyEntities,
|
||||
readPartyEntitiesMap,
|
||||
|
Loading…
x
Reference in New Issue
Block a user