2022-01-27 10:33:12 -08:00
|
|
|
import YAML from 'yamljs';
|
|
|
|
import { CheckCircleOutlined, CloseCircleOutlined, LoadingOutlined } from '@ant-design/icons';
|
|
|
|
import { ANTD_GRAY, REDESIGN_COLORS } from '../../entity/shared/constants';
|
|
|
|
import { SOURCE_TEMPLATE_CONFIGS } from './conf/sources';
|
2022-08-08 14:33:57 -07:00
|
|
|
import { EntityType, FacetMetadata } from '../../../types.generated';
|
|
|
|
import { capitalizeFirstLetterOnly, pluralize } from '../../shared/textUtil';
|
2022-08-10 15:12:53 -07:00
|
|
|
import EntityRegistry from '../../entity/EntityRegistry';
|
2022-01-27 10:33:12 -08:00
|
|
|
|
|
|
|
export const sourceTypeToIconUrl = (type: string) => {
|
|
|
|
return SOURCE_TEMPLATE_CONFIGS.find((config) => config.type === type)?.logoUrl;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getSourceConfigs = (sourceType: string) => {
|
|
|
|
const sourceConfigs = SOURCE_TEMPLATE_CONFIGS.find((configs) => configs.type === sourceType);
|
|
|
|
if (!sourceConfigs) {
|
|
|
|
throw new Error(`Failed to find source configs with source type ${sourceType}`);
|
|
|
|
}
|
|
|
|
return sourceConfigs;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const yamlToJson = (yaml: string): string => {
|
|
|
|
const obj = YAML.parse(yaml);
|
|
|
|
const jsonStr = JSON.stringify(obj);
|
|
|
|
return jsonStr;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const jsonToYaml = (json: string): string => {
|
|
|
|
const obj = JSON.parse(json);
|
|
|
|
const yamlStr = YAML.stringify(obj, 6);
|
|
|
|
return yamlStr;
|
|
|
|
};
|
|
|
|
|
2022-08-01 12:12:02 -04:00
|
|
|
export const RUNNING = 'RUNNING';
|
|
|
|
export const SUCCESS = 'SUCCESS';
|
|
|
|
export const FAILURE = 'FAILURE';
|
|
|
|
export const CANCELLED = 'CANCELLED';
|
|
|
|
|
2022-01-27 10:33:12 -08:00
|
|
|
export const getExecutionRequestStatusIcon = (status: string) => {
|
|
|
|
return (
|
2022-08-01 12:12:02 -04:00
|
|
|
(status === RUNNING && LoadingOutlined) ||
|
|
|
|
(status === SUCCESS && CheckCircleOutlined) ||
|
|
|
|
(status === FAILURE && CloseCircleOutlined) ||
|
|
|
|
(status === CANCELLED && CloseCircleOutlined) ||
|
2022-01-27 10:33:12 -08:00
|
|
|
undefined
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getExecutionRequestStatusDisplayText = (status: string) => {
|
|
|
|
return (
|
2022-08-01 12:12:02 -04:00
|
|
|
(status === RUNNING && 'Running') ||
|
|
|
|
(status === SUCCESS && 'Succeeded') ||
|
|
|
|
(status === FAILURE && 'Failed') ||
|
|
|
|
(status === CANCELLED && 'Cancelled') ||
|
2022-01-27 10:33:12 -08:00
|
|
|
status
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-08-16 19:01:26 -04:00
|
|
|
export const getExecutionRequestSummaryText = (status: string) => {
|
|
|
|
switch (status) {
|
|
|
|
case RUNNING:
|
|
|
|
return 'Ingestion is running';
|
|
|
|
case SUCCESS:
|
|
|
|
return 'Ingestion successfully completed';
|
|
|
|
case FAILURE:
|
|
|
|
return 'Ingestion completed with errors';
|
|
|
|
case CANCELLED:
|
|
|
|
return 'Ingestion was cancelled';
|
|
|
|
default:
|
|
|
|
return 'Ingestion status not recognized';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-27 10:33:12 -08:00
|
|
|
export const getExecutionRequestStatusDisplayColor = (status: string) => {
|
|
|
|
return (
|
2022-08-01 12:12:02 -04:00
|
|
|
(status === RUNNING && REDESIGN_COLORS.BLUE) ||
|
|
|
|
(status === SUCCESS && 'green') ||
|
|
|
|
(status === FAILURE && 'red') ||
|
|
|
|
(status === CANCELLED && ANTD_GRAY[9]) ||
|
2022-01-27 10:33:12 -08:00
|
|
|
ANTD_GRAY[7]
|
|
|
|
);
|
|
|
|
};
|
2022-08-08 14:33:57 -07:00
|
|
|
|
|
|
|
const ENTITIES_WITH_SUBTYPES = new Set([
|
|
|
|
EntityType.Dataset.toLowerCase(),
|
|
|
|
EntityType.Container.toLowerCase(),
|
|
|
|
EntityType.Notebook.toLowerCase(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
type EntityTypeCount = {
|
|
|
|
count: number;
|
|
|
|
displayName: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract entity type counts to display in the ingestion summary.
|
|
|
|
*
|
|
|
|
* @param entityTypeFacets the filter facets for entity type.
|
|
|
|
* @param subTypeFacets the filter facets for sub types.
|
|
|
|
*/
|
|
|
|
export const extractEntityTypeCountsFromFacets = (
|
2022-08-10 15:12:53 -07:00
|
|
|
entityRegistry: EntityRegistry,
|
2022-08-08 14:33:57 -07:00
|
|
|
entityTypeFacets: FacetMetadata,
|
|
|
|
subTypeFacets?: FacetMetadata | null,
|
|
|
|
): EntityTypeCount[] => {
|
|
|
|
const finalCounts: EntityTypeCount[] = [];
|
|
|
|
|
|
|
|
if (subTypeFacets) {
|
2022-08-10 15:12:53 -07:00
|
|
|
subTypeFacets.aggregations
|
|
|
|
.filter((agg) => agg.count > 0)
|
|
|
|
.forEach((agg) =>
|
|
|
|
finalCounts.push({
|
|
|
|
count: agg.count,
|
|
|
|
displayName: pluralize(agg.count, capitalizeFirstLetterOnly(agg.value) || ''),
|
|
|
|
}),
|
|
|
|
);
|
2022-08-08 14:33:57 -07:00
|
|
|
entityTypeFacets.aggregations
|
2022-08-10 15:12:53 -07:00
|
|
|
.filter((agg) => agg.count > 0)
|
2022-08-08 14:33:57 -07:00
|
|
|
.filter((agg) => !ENTITIES_WITH_SUBTYPES.has(agg.value.toLowerCase()))
|
|
|
|
.forEach((agg) =>
|
|
|
|
finalCounts.push({
|
|
|
|
count: agg.count,
|
2022-08-10 15:12:53 -07:00
|
|
|
displayName: entityRegistry.getCollectionName(agg.value as EntityType),
|
2022-08-08 14:33:57 -07:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Only use Entity Types- no subtypes.
|
2022-08-10 15:12:53 -07:00
|
|
|
entityTypeFacets.aggregations
|
|
|
|
.filter((agg) => agg.count > 0)
|
|
|
|
.forEach((agg) =>
|
|
|
|
finalCounts.push({
|
|
|
|
count: agg.count,
|
|
|
|
displayName: entityRegistry.getCollectionName(agg.value as EntityType),
|
|
|
|
}),
|
|
|
|
);
|
2022-08-08 14:33:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return finalCounts;
|
|
|
|
};
|