import { Space, Tag, Typography } from 'antd';
import { StatusEnum } from '../enum';
import { SENSITIVE_LEVEL_ENUM, SENSITIVE_LEVEL_COLOR } from '../constant';
import { TagsOutlined, ReadOutlined } from '@ant-design/icons';
import { history } from '@umijs/max';
import { ISemantic } from '../data';
import { isString } from 'lodash';
import dayjs from 'dayjs';
import { isArrayOfValues, replaceRouteParams } from '@/utils/utils';
import styles from './style.less';
import IndicatorStar, { StarType } from '../components/IndicatorStar';
interface IndicatorInfo {
url?: string;
starType?: StarType;
onNameClick?: (record: ISemantic.IMetricItem) => void | boolean;
}
interface ColumnsConfigParams {
indicatorInfo?: IndicatorInfo;
}
const { Text, Paragraph } = Typography;
export const ColumnsConfig = (params?: ColumnsConfigParams) => {
const renderAliasAndClassifications = (
alias: string | undefined,
classifications: string[] | undefined,
) => (
{alias && (
别名:
{isString(alias) &&
alias.split(',').map((aliasName: string) => (
{aliasName}
))}
)}
{isArrayOfValues(classifications) && (
分类:
{classifications.map((tag: string) => (
{tag}
))}
)}
);
return {
description: {
render: (_, record: ISemantic.IMetricItem) => (
{record.description}
),
},
dimensionInfo: {
render: (_, record: ISemantic.IDimensionItem) => {
const { name, alias, bizName } = record;
return (
<>
{name}
{bizName}
{renderAliasAndClassifications(alias, undefined)}
>
);
},
},
indicatorInfo: {
render: (_, record: ISemantic.IMetricItem) => {
const { name, alias, bizName, classifications, id, isCollect, domainId, modelId } = record;
let url = `/metric/detail/${id}`;
let starType: StarType = 'metric';
if (params?.indicatorInfo) {
url = replaceRouteParams(params.indicatorInfo.url || '', {
domainId: `${domainId}`,
modelId: `${modelId}`,
indicatorId: `${id}`,
});
starType = params.indicatorInfo.starType || 'metric';
}
return (
<>
{bizName}
{renderAliasAndClassifications(alias, classifications)}
>
);
},
},
sensitiveLevel: {
render: (_, record: ISemantic.IMetricItem) => (
{SENSITIVE_LEVEL_ENUM[record.sensitiveLevel] || '未知'}
),
},
state: {
render: (status) => {
const tagProps = {
color: 'default',
label: '未知',
style: {},
};
switch (status) {
case StatusEnum.ONLINE:
tagProps.color = 'geekblue';
tagProps.label = '已启用';
break;
case StatusEnum.OFFLINE:
tagProps.color = 'default';
tagProps.label = '未启用';
tagProps.style = { color: 'rgb(95, 116, 141)', fontWeight: 400 };
break;
case StatusEnum.INITIALIZED:
tagProps.color = 'processing';
tagProps.label = '初始化';
break;
case StatusEnum.DELETED:
tagProps.color = 'default';
tagProps.label = '已删除';
break;
case StatusEnum.UNAVAILABLE:
tagProps.color = 'default';
tagProps.label = '不可用';
break;
default:
break;
}
return (
{tagProps.label}
);
},
},
createInfo: {
dataIndex: 'updatedAt',
title: '创建信息',
tooltip: '创建人/更新时间',
width: 180,
search: false,
render: (value: any, record: ISemantic.IMetricItem) => (
{record.createdBy}
{value && value !== '-' ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : '-'}
),
},
};
};