import PageTools from '@/components/page-tools'; import ProgressBar from '@/components/progress-bar'; import StatusTag from '@/components/status-tag'; import useTableRowSelection from '@/hooks/use-table-row-selection'; import useTableSort from '@/hooks/use-table-sort'; import { convertFileSize, handleBatchRequest } from '@/utils'; import { DeleteOutlined, InfoCircleOutlined, SyncOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Input, Modal, Space, Table, Tooltip, message } from 'antd'; import _ from 'lodash'; import { memo, useEffect, useState } from 'react'; import { deleteWorker, queryWorkersList } from '../apis'; import { WorkerStatusMapValue, status } from '../config'; import { Filesystem, GPUDeviceItem, ListItem } from '../config/types'; const { Column } = Table; const Resources: React.FC = () => { console.log('resources======workers'); const { sortOrder, setSortOrder } = useTableSort({ defaultSortOrder: 'descend' }); const rowSelection = useTableRowSelection(); const intl = useIntl(); const [total, setTotal] = useState(0); const [loading, setLoading] = useState(false); const [dataSource, setDataSource] = useState([]); const [queryParams, setQueryParams] = useState({ page: 1, perPage: 10, search: '' }); const fetchData = async () => { setLoading(true); try { const params = { ..._.pickBy(queryParams, (val: any) => !!val) }; const res = await queryWorkersList(params); setDataSource(res.items); setTotal(res.pagination.total); } catch (error) { setDataSource([]); console.log('error', error); } finally { setLoading(false); } }; const handleShowSizeChange = (current: number, size: number) => { setQueryParams({ ...queryParams, page: current, perPage: size || 10 }); }; const handlePageChange = (page: number, perPage: number | undefined) => { console.log(page, perPage); setQueryParams({ ...queryParams, page: page, perPage: perPage || 10 }); }; const handleTableChange = (pagination: any, filters: any, sorter: any) => { setSortOrder(sorter.order); }; const handleSearch = (e: any) => { fetchData(); }; const handleNameChange = (e: any) => { setQueryParams({ ...queryParams, search: e.target.value }); }; const formateUtilazation = (val1: number, val2: number): number => { if (!val2 || !val1) { return 0; } return _.round((val1 / val2) * 100, 0); }; const calcStorage = (files: Filesystem[]) => { const mountRoot = _.find( files, (item: Filesystem) => item.mount_point === '/' ); return mountRoot ? formateUtilazation(mountRoot.used, mountRoot.total) : 0; }; const handleDelete = (row: ListItem) => { Modal.confirm({ title: '', content: intl.formatMessage( { id: 'common.delete.confirm' }, { type: ' worker ' } ), async onOk() { console.log('OK'); await deleteWorker(row.id); message.success(intl.formatMessage({ id: 'common.message.success' })); fetchData(); }, onCancel() { console.log('Cancel'); } }); }; const handleDeleteBatch = () => { Modal.confirm({ title: '', content: intl.formatMessage( { id: 'common.delete.confirm' }, { type: ` wokers ` } ), async onOk() { await handleBatchRequest(rowSelection.selectedRowKeys, deleteWorker); message.success(intl.formatMessage({ id: 'common.message.success' })); rowSelection.clearSelections(); fetchData(); }, onCancel() { console.log('Cancel'); } }); }; const renderStorageTooltip = (files: Filesystem[]) => { const mountRoot = _.find( files, (item: Filesystem) => item.mount_point === '/' ); return mountRoot ? ( {intl.formatMessage({ id: 'resources.table.total' })}:{' '} {convertFileSize(mountRoot?.total, 0)} {intl.formatMessage({ id: 'resources.table.used' })}:{' '} {convertFileSize(mountRoot?.used, 0)} ) : ( 0 ); }; useEffect(() => { fetchData(); }, [queryParams]); return ( <> } right={ } > { return ( ); }} /> { return ( ); }} /> { return ( {intl.formatMessage({ id: 'resources.table.total' })}:{' '} {convertFileSize(record?.status?.memory.total, 0)} {intl.formatMessage({ id: 'resources.table.used' })}:{' '} {convertFileSize(record?.status?.memory.used, 0)} } > ); }} /> { return ( {record?.status?.gpu_devices.map((item, index) => { return ( [{index}] ); })} ); }} /> { return ( {record?.status?.gpu_devices.map( (item: GPUDeviceItem, index) => { return ( [{index}] {intl.formatMessage({ id: 'resources.table.total' })} : {convertFileSize(item.memory?.total, 0)} {intl.formatMessage({ id: 'resources.table.used' })} : {convertFileSize(item.memory?.used, 0)} } > {item.memory.is_unified_memory && ( )} ); } )} ); }} /> { return ( ); }} /> { return ( ); }} />
); }; export default memo(Resources);