2020-08-26 15:44:50 -07:00
|
|
|
import { IDatasetLineage, DatasetLineageList } from '@datahub/metadata-types/types/entity/dataset/lineage';
|
|
|
|
import { arrayFilter, take } from '@datahub/utils/array/index';
|
|
|
|
import { INachoDropdownOption } from '@nacho-ui/dropdown/types/nacho-dropdown';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut typing to reference dropdown options for relationship types
|
|
|
|
*/
|
|
|
|
type RelationshipType = INachoDropdownOption<string>;
|
2018-07-23 10:51:27 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constant for the relationship type i.e. nativeType property with an empty string value, intended
|
|
|
|
* to signify all nativeType
|
|
|
|
* @type {Readonly<{label: string; value: string}>}
|
|
|
|
*/
|
2018-07-23 11:33:33 -07:00
|
|
|
const allRelationshipType: RelationshipType = { label: 'All Types', value: '' };
|
2018-07-23 10:51:27 -07:00
|
|
|
|
|
|
|
/**
|
2018-09-18 12:24:39 -07:00
|
|
|
* Creates a filter function and will filter an instance of an IDatasetLineage based on its type property
|
|
|
|
* @param {IDatasetLineage.type} filter
|
2018-07-23 10:51:27 -07:00
|
|
|
*/
|
2018-09-13 20:26:48 -07:00
|
|
|
const lineageTypeFilter = (filter: IDatasetLineage['type'] = '') => ({ type }: IDatasetLineage): boolean =>
|
|
|
|
filter ? type === filter : true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters a list of dataset lineage objects on the type attribute
|
|
|
|
* @param {string} filter
|
|
|
|
* @return {(array: LineageList) => LineageList}
|
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
const filterLineageByType = (filter = ''): ((array: DatasetLineageList) => DatasetLineageList) =>
|
2018-09-13 20:26:48 -07:00
|
|
|
arrayFilter(lineageTypeFilter(filter));
|
|
|
|
|
2018-07-23 10:51:27 -07:00
|
|
|
/**
|
|
|
|
* Dedupes a list of RelationshipType objects
|
|
|
|
* @param {Array<RelationshipType>} set the deduped list
|
|
|
|
* @param {RelationshipType} relationshipType a RelationshipType element in the list
|
|
|
|
* @returns {Array<RelationshipType>}
|
|
|
|
*/
|
|
|
|
const dedupeType = (set: Array<RelationshipType>, relationshipType: RelationshipType): Array<RelationshipType> => {
|
|
|
|
const isSameType = ({ value }: RelationshipType): boolean => relationshipType.value === value;
|
|
|
|
const hasType = set.find(isSameType);
|
|
|
|
|
|
|
|
return hasType ? set : [...set, relationshipType];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes the first N elements in the list of relationships if the shouldShowAll flag is false
|
|
|
|
* @param {boolean} shouldShowAll flag to determine if all relationships should be shown
|
|
|
|
* @param {number} [n=10]
|
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
const takeNLineageItems = (shouldShowAll: boolean, n = 10) => (relationships: DatasetLineageList): DatasetLineageList =>
|
2018-09-13 20:26:48 -07:00
|
|
|
shouldShowAll ? relationships : take<IDatasetLineage>(n)(relationships);
|
2018-07-23 10:51:27 -07:00
|
|
|
|
2018-09-18 12:24:39 -07:00
|
|
|
export { allRelationshipType, dedupeType, takeNLineageItems, filterLineageByType };
|