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,
|
ownerAlreadyExists,
|
||||||
confirmOwner,
|
confirmOwner,
|
||||||
updateOwner,
|
updateOwner,
|
||||||
minRequiredConfirmedOwners
|
minRequiredConfirmedOwners,
|
||||||
|
validConfirmedOwners,
|
||||||
|
isRequiredMinOwnersNotConfirmed
|
||||||
} from 'wherehows-web/constants/datasets/owner';
|
} from 'wherehows-web/constants/datasets/owner';
|
||||||
import {
|
import { OwnerIdType, OwnerSource, OwnerType } from 'wherehows-web/utils/api/datasets/owners';
|
||||||
isRequiredMinOwnersNotConfirmed,
|
|
||||||
OwnerIdType,
|
|
||||||
OwnerSource,
|
|
||||||
OwnerType,
|
|
||||||
validConfirmedOwners
|
|
||||||
} from 'wherehows-web/utils/api/datasets/owners';
|
|
||||||
import Notifications, { NotificationEvent } from 'wherehows-web/services/notifications';
|
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 { IOwner } from 'wherehows-web/typings/api/datasets/owners';
|
||||||
import { OwnerIdType, OwnerSource, OwnerType, OwnerUrnNamespace } from 'wherehows-web/utils/api/datasets/owners';
|
import { OwnerIdType, OwnerSource, OwnerType, OwnerUrnNamespace } from 'wherehows-web/utils/api/datasets/owners';
|
||||||
import { isListUnique } from 'wherehows-web/utils/array';
|
import { arrayFilter, isListUnique } from 'wherehows-web/utils/array';
|
||||||
import { set } from '@ember/object';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initial user name for candidate owners
|
* Initial user name for candidate owners
|
||||||
@ -10,7 +10,7 @@ import { set } from '@ember/object';
|
|||||||
const defaultOwnerUserName = 'New Owner';
|
const defaultOwnerUserName = 'New Owner';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum required number of owners
|
* The minimum required number of owners with a confirmed status
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
const minRequiredConfirmedOwners = 2;
|
const minRequiredConfirmedOwners = 2;
|
||||||
@ -90,6 +90,7 @@ function updateOwner<K extends keyof IOwner>(
|
|||||||
*/
|
*/
|
||||||
const confirmOwner = (owner: IOwner, confirmedBy: string): IOwner['confirmedBy'] =>
|
const confirmOwner = (owner: IOwner, confirmedBy: string): IOwner['confirmedBy'] =>
|
||||||
set(owner, 'confirmedBy', confirmedBy || null);
|
set(owner, 'confirmedBy', confirmedBy || null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the default properties for a newly created IOwner instance
|
* Defines the default properties for a newly created IOwner instance
|
||||||
*@type {IOwner}
|
*@type {IOwner}
|
||||||
@ -109,10 +110,34 @@ const defaultOwnerProps: IOwner = {
|
|||||||
isActive: true
|
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 {
|
export {
|
||||||
defaultOwnerProps,
|
defaultOwnerProps,
|
||||||
defaultOwnerUserName,
|
defaultOwnerUserName,
|
||||||
minRequiredConfirmedOwners,
|
minRequiredConfirmedOwners,
|
||||||
|
validConfirmedOwners,
|
||||||
|
isRequiredMinOwnersNotConfirmed,
|
||||||
ownerAlreadyExists,
|
ownerAlreadyExists,
|
||||||
updateOwner,
|
updateOwner,
|
||||||
confirmOwner
|
confirmOwner
|
||||||
|
@ -13,11 +13,8 @@ import {
|
|||||||
augmentObjectsWithHtmlComments
|
augmentObjectsWithHtmlComments
|
||||||
} from 'wherehows-web/utils/api/datasets/columns';
|
} from 'wherehows-web/utils/api/datasets/columns';
|
||||||
|
|
||||||
import {
|
import { readDatasetOwners, getUserEntities } from 'wherehows-web/utils/api/datasets/owners';
|
||||||
readDatasetOwners,
|
import { isRequiredMinOwnersNotConfirmed } from 'wherehows-web/constants/datasets/owner';
|
||||||
getUserEntities,
|
|
||||||
isRequiredMinOwnersNotConfirmed
|
|
||||||
} from 'wherehows-web/utils/api/datasets/owners';
|
|
||||||
import { readDataset, datasetUrnToId, readDatasetView } from 'wherehows-web/utils/api/datasets/dataset';
|
import { readDataset, datasetUrnToId, readDatasetView } from 'wherehows-web/utils/api/datasets/dataset';
|
||||||
import isDatasetUrn from 'wherehows-web/utils/validators/urn';
|
import isDatasetUrn from 'wherehows-web/utils/validators/urn';
|
||||||
|
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import { ApiRoot, ApiStatus } from 'wherehows-web/utils/api/shared';
|
import { IOwner, IOwnerPostResponse, IOwnerResponse } from 'wherehows-web/typings/api/datasets/owners';
|
||||||
import { datasetUrlById } from 'wherehows-web/utils/api/datasets/shared';
|
|
||||||
import {
|
import {
|
||||||
IPartyEntity,
|
IPartyEntity,
|
||||||
IPartyEntityResponse,
|
IPartyEntityResponse,
|
||||||
IPartyProps,
|
IPartyProps,
|
||||||
IUserEntityMap
|
IUserEntityMap
|
||||||
} from 'wherehows-web/typings/api/datasets/party-entities';
|
} 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 { 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
|
* Defines a string enum for valid owner types
|
||||||
@ -51,12 +50,6 @@ enum OwnerSource {
|
|||||||
Other = 'OTHER'
|
Other = 'OTHER'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The minimum required number of owners with a confirmed status
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
const minRequiredConfirmed = 2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the dataset owners url
|
* Constructs the dataset owners url
|
||||||
* @param {number} id the id of the dataset
|
* @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 {
|
export {
|
||||||
validConfirmedOwners,
|
|
||||||
isRequiredMinOwnersNotConfirmed,
|
|
||||||
readDatasetOwners,
|
readDatasetOwners,
|
||||||
readPartyEntities,
|
readPartyEntities,
|
||||||
readPartyEntitiesMap,
|
readPartyEntitiesMap,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user