// columns.ts import AutoTooltip from '@/components/auto-tooltip'; import DropdownButtons from '@/components/drop-down-buttons'; import { SealColumnProps } from '@/components/seal-table/types'; import { OPENAI_COMPATIBLE, tableSorter } from '@/config/settings'; import { QuestionCircleOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Tooltip } from 'antd'; import dayjs from 'dayjs'; import _ from 'lodash'; import { useMemo } from 'react'; import ModelTag from '../components/model-tag'; import { ActionList, generateSource } from '../config/button-actions'; import { ListItem } from '../config/types'; const setModelActionList = (record: any) => { return _.filter(ActionList, (action: any) => { if (action.key === 'chat' || action.key === 'api') { return record.ready_replicas > 0; } if (action.key === 'start') { return record.replicas === 0; } if (action.key === 'stop') { return record.replicas > 0; } return true; }); }; interface ModelsColumnsHookProps { handleSelect: (val: string, record: ListItem) => void; sortOrder: string[]; clusterList: Global.BaseOption< number, { provider: string; state: string | number } >[]; } const useModelsColumns = ({ handleSelect, clusterList, sortOrder }: ModelsColumnsHookProps): SealColumnProps[] => { const intl = useIntl(); return useMemo(() => { return [ { title: intl.formatMessage({ id: 'common.table.name' }), dataIndex: 'name', key: 'name', sorter: tableSorter(1), span: 5, render: (text: string, record: ListItem) => ( {text} ) }, { title: intl.formatMessage({ id: 'clusters.title' }), dataIndex: 'cluster_id', key: 'cluster_id', sorter: tableSorter(2), span: 3, render: (text: string, record: ListItem) => ( { clusterList.find((item) => item.value === record.cluster_id) ?.label } ) }, { title: intl.formatMessage({ id: 'models.form.source' }), dataIndex: 'source', key: 'source', sorter: tableSorter(3), span: 5, render: (text: string, record: ListItem) => ( {generateSource(record)} ) }, { title: ( {intl.formatMessage({ id: 'models.form.replicas' })} ), dataIndex: 'ready_replicas', key: 'ready_replicas', align: 'center', sorter: tableSorter(4), span: 4, editable: { valueType: 'number', title: intl.formatMessage({ id: 'models.table.replicas.edit' }) }, render: (text: number, record: ListItem) => ( {record.ready_replicas} / {record.replicas} ) }, { title: intl.formatMessage({ id: 'common.table.createTime' }), dataIndex: 'created_at', key: 'created_at', defaultSortOrder: 'descend', sorter: tableSorter(5), span: 4, render: (text: number) => ( {dayjs(text).format('YYYY-MM-DD HH:mm:ss')} ) }, { title: intl.formatMessage({ id: 'common.table.operation' }), key: 'operation', dataIndex: 'operation', span: 3, render: (text, record) => ( handleSelect(val, record)} /> ) } ]; }, [sortOrder, clusterList, intl, handleSelect]); }; export default useModelsColumns;