import type { ProColumns } from '@ant-design/pro-table'; import { Button, Popconfirm, Space, Tooltip, Typography } from 'antd'; import _ from 'lodash'; import type { Dispatch, Key, SetStateAction } from 'react'; import { useCallback } from 'react'; import { FormattedMessage, useIntl } from 'umi'; import AuditCountersign from '../AuditCountersign'; import AuditPassOn from '../AuditPassOn'; import AuditProgress from '../AuditProgress'; import BindAllPermission from '../BindAllPermission'; import CustomTable from '../CustomTable'; import ExpandIcon from '../ExpandIcon'; import Tips from '../Tips'; import publicConst from '../utils/const'; import { AduitStatus } from './const'; import type { RowType } from './hooks'; import lessStyle from './index.less'; const { DataSensitiveLevelTips, DataSensitiveTips } = Tips; const { Text } = Typography; export interface UacTableProps { auditDetail: any; rowSelectionKeys: RowType; chainId: string; pageReadOnly?: boolean; setSelectionKeys: Dispatch>; approvalHandler: (id: Key[], state: number, type: string) => Promise; requestDetail: () => Promise; } const UacTable = (props: UacTableProps) => { const { auditDetail, rowSelectionKeys, chainId, pageReadOnly, setSelectionKeys, approvalHandler, requestDetail, } = props; const { auditList, appInfo } = auditDetail || {}; const { formatMessage } = useIntl(); const columns = useCallback( (type: string): ProColumns[] => { const { DataSensitiveMap, DataSensitiveLevelMap } = publicConst(formatMessage); return [ { title: ( ), dataIndex: 'name', search: false, hideInTable: false, className: lessStyle.nameColumn, render: (__, record: any) => { const { id, name } = record; return ( <> {name} {type === 'role' && ( )} ); }, }, { title: , dataIndex: 'dataSensitive', search: false, tooltip: DataSensitiveLevelTips, valueType: 'select', valueEnum: DataSensitiveLevelMap, }, { title: , dataIndex: 'sensitiveLevel', search: false, tooltip: DataSensitiveTips, valueType: 'select', valueEnum: DataSensitiveMap, }, { title: , dataIndex: 'expiredAt', search: false, ellipsis: true, render: (__: any, record: any) => { const expiredAt = type === 'city' ? 0 : record.expiredAt; return ( _.isNumber(expiredAt) && ( {expiredAt === 0 ? formatMessage({ id: 'pages.setting.base.defaultExpirationTime.forever' }) : expiredAt / 86400} ) ); }, }, { title: , dataIndex: 'uacAuditState', search: false, render: (__: any, record: any) => { const { uacAuditState } = record; return ( _.isNumber(uacAuditState) && uacAuditState !== 0 && ( {formatMessage({ id: AduitStatus[uacAuditState] })} ) ); }, }, { title: , dataIndex: 'uacAuditId', search: false, render: (__: any, record: any) => { const { uacAuditId } = record; return ( Boolean(uacAuditId) && ( ) ); }, }, { title: , dataIndex: 'permissionOption', valueType: 'option', fixed: 'right', align: 'center', width: 240, search: false, hideInTable: pageReadOnly, render: (__: any, record: any) => { const { uacAuditId, uacCanAudit } = record; return ( Boolean(uacAuditId && uacCanAudit) && ( { approvalHandler([uacAuditId], 1, 'uac'); }} > { approvalHandler([uacAuditId], 3, 'uac'); }} > ) ); }, }, ]; }, [ formatMessage, pageReadOnly, appInfo?.id, chainId, requestDetail, auditDetail, approvalHandler, ], ); const rowSelection = useCallback( (type: string) => { if (pageReadOnly) return false; return { getCheckboxProps: (record: any) => ({ disabled: !record.uacCanAudit, }), selectedRowKeys: rowSelectionKeys?.[type], onChange: (rowKey: Key[]) => { setSelectionKeys((oldVal: RowType) => ({ ...oldVal, [type]: rowKey })); }, }; }, [pageReadOnly, rowSelectionKeys, setSelectionKeys], ); return ( <> {Array.isArray(auditList) && auditList.map((item, index) => { const { feature, option, policy, role, city } = item; const obj = { feature, option: option?.map((o: any) => ({ ...o, children: o?.optionTree })), policy, role, city, }; return Object.keys(obj) .filter((key) => Array.isArray(obj[key]) && obj[key].length) .map((key) => { const dataSource = obj[key]; return ( , }} pagination={false} headerTitle={false} search={false} options={false} rowKey={(record: any) => record.uacAuditId ?? record.uniqueKey} rowSelection={rowSelection(key)} columns={columns(key)} dataSource={dataSource} /> ); }); })} ); }; export default UacTable;