/* eslint-disable react/display-name */ import React, { useState, useEffect } from 'react'; import { useHistory, useParams } from 'react-router-dom'; import { AppContainer, IconFont, Input, ProTable, Select, Switch, Tooltip, Utils, Dropdown, Menu, Button } from 'knowdesign'; import Create from './Create'; import './index.less'; import Api from '@src/api/index'; import ExpandPartition from './ExpandPartition'; import TopicHealthCheck from '@src/components/CardBar/TopicHealthCheck'; import TopicDetail from '../TopicDetail'; import Delete from './Delete'; import { ClustersPermissionMap } from '../CommonConfig'; import DBreadcrumb from 'knowdesign/es/extend/d-breadcrumb'; import ReplicaChange from '@src/components/TopicJob/ReplicaChange'; import SmallChart from '@src/components/SmallChart'; import ReplicaMove from '@src/components/TopicJob/ReplicaMove'; import { formatAssignSize } from '../Jobs/config'; import { DownOutlined } from '@ant-design/icons'; const { Option } = Select; const AutoPage = (props: any) => { const routeParams = useParams<{ clusterId: string }>(); const history = useHistory(); const [global] = AppContainer.useGlobalValue(); const [selectedRowKeys, setSelectedRowKeys] = useState([]); const [selectedRows, setSelectedRows] = useState([]); const [topicList, setTopicList] = useState([]); const [pageIndex, setPageIndex] = useState(1); const [pageTotal, setPageTotal] = useState(1); const [pageSize, setPageSize] = useState(10); const [showInternalTopics, setShowInternalTopics] = useState(false); const [searchKeywords, setSearchKeywords] = useState(''); const [searchKeywordsInput, setSearchKeywordsInput] = useState(''); const [topicListLoading, setTopicListLoading] = useState(false); const [type, setType] = useState(''); const [changeVisible, setChangeVisible] = useState(false); const [moveVisible, setMoveVisible] = useState(false); const [selectValue, setSelectValue] = useState('批量操作'); const [sortObj, setSortObj] = useState<{ sortField: string; sortType: 'desc' | 'asc' | ''; }>({ sortField: 'createTime', sortType: 'desc' }); const getRecent1DayTimeStamp = () => [Date.now() - 24 * 60 * 60 * 1000, Date.now()]; const getTopicsList = () => { const [startStamp, endStamp] = getRecent1DayTimeStamp(); // const [startStamp, endStamp] = [1650445216000, 1650448576988] const params: any = { metricLines: { aggType: 'avg', endTime: endStamp, metricsNames: ['HealthScore', 'BytesIn', 'BytesOut', 'LogSize'], startTime: startStamp, topNu: 0, }, latestMetricNames: ['HealthScore', 'BytesIn', 'BytesOut', 'LogSize'], pageNo: pageIndex, pageSize: pageSize, searchKeywords, showInternalTopics, sortType: sortObj.sortType || 'desc', sortField: sortObj.sortField || 'createTime', }; // if (sortObj.sortField && sortObj.sortType) { // params.sortField = sortObj.sortField; // params.sortType = sortObj.sortType || 'desc'; // } Utils.post(Api.getTopicsList(Number(routeParams.clusterId)), params) .then((data: any) => { setTopicListLoading(false); setTopicList(data?.bizData || []); // setPageIndex(data.pagination.pageNo) setPageTotal(data.pagination.total); // setPageSize(data.pagination.pageSize) }) .catch((e) => { setTopicListLoading(false); }); }; useEffect(() => { setTopicListLoading(true); getTopicsList(); }, [sortObj, showInternalTopics, searchKeywords, pageIndex, pageSize]); const calcCurValue = (record: any, metricName: string) => { // const item = (record.metricPoints || []).find((item: any) => item.metricName === metricName); // return item?.value || ''; const orgVal = record?.latestMetrics?.metrics?.[metricName]; if (orgVal !== undefined) { if (metricName === 'HealthScore') { return Math.round(orgVal); } else if (metricName === 'LogSize') { return Number(Utils.formatAssignSize(orgVal, 'MB')); } else { return Number(Utils.formatAssignSize(orgVal, 'KB')); // return Utils.formatAssignSize(orgVal, 'KB'); } } return '-'; // return orgVal !== undefined ? (metricName !== 'HealthScore' ? formatAssignSize(orgVal, 'KB') : orgVal) : '-'; }; const renderLine = (record: any, metricName: string) => { const points = record.metricLines.find((item: any) => item.metricName === metricName)?.metricPoints || []; return (
({ time: item.timeStamp, value: item.value })), }} /> {calcCurValue(record, metricName)}
); }; const columns = () => { const baseColumns: any = [ { title: 'TopicName', dataIndex: 'topicName', key: 'topicName', fixed: 'left', width: 140, className: 'clean-padding-left', lineClampOne: true, // eslint-disable-next-line react/display-name render: (t: string, r: any) => { return ( { window.location.hash = `topicName=${t}`; }} > {t} ); }, }, { title: 'Partitions', dataIndex: 'partitionNum', key: 'partitionNum', width: 95, }, { title: 'Replications', dataIndex: 'replicaNum', key: 'replicaNum', width: 95, }, { title: '健康分', dataIndex: 'HealthScore', key: 'HealthScore', sorter: true, // 设计图上量出来的是144,但做的时候发现写144 header部分的sort箭头不出来,所以临时调大些 width: 170, render: (value: any, record: any) => renderLine(record, 'HealthScore'), }, // { // title: '创建时间', // dataIndex: 'createTime', // key: 'createTime', // width: 240, // render: (v: string) => moment(new Date(v)).format('YYYY-MM-DD HH:mm:ss') // }, { title: 'Bytes In(KB/s)', dataIndex: 'BytesIn', key: 'BytesIn', sorter: true, width: 170, render: (value: any, record: any) => renderLine(record, 'BytesIn'), }, { title: 'Bytes Out(KB/s)', dataIndex: 'BytesOut', key: 'BytesOut', sorter: true, width: 170, render: (value: any, record: any) => renderLine(record, 'BytesOut'), }, { title: 'MessageSize(MB)', dataIndex: 'LogSize', key: 'LogSize', sorter: true, width: 170, render: (value: any, record: any) => renderLine(record, 'LogSize'), }, { title: '保存时间(h)', dataIndex: 'retentionTimeUnitMs', key: 'retentionTimeUnitMs', width: 120, render: (v: any) => { return (v / 3600000).toFixed(2); }, }, { title: '描述', dataIndex: 'description', key: 'description', lineClampTwo: true, width: 150, needTooltip: true, }, ]; if ( global.hasPermission && (global.hasPermission(ClustersPermissionMap.TOPIC_EXPOND) || global.hasPermission(ClustersPermissionMap.TOPIC_DEL)) ) { baseColumns.push({ title: '操作', dataIndex: 'desc', key: 'desc', fixed: 'right', width: 140, render: (value: any, record: any) => { return (
{global.hasPermission(ClustersPermissionMap.TOPIC_EXPOND) ? ( ) : ( <> )} {global.hasPermission(ClustersPermissionMap.TOPIC_DEL) ? : <>}
); }, }); } return baseColumns; }; const onSelectChange = (selectedRowKeys: any, selectedRows: any) => { setSelectedRowKeys(selectedRowKeys); setSelectedRows(selectedRows); }; const rowSelection = { selectedRowKeys, onChange: onSelectChange, }; const onclose = () => { setChangeVisible(false); setMoveVisible(false); setSelectValue('批量操作'); }; const menu = ( {global.hasPermission(ClustersPermissionMap.TOPIC_CHANGE_REPLICA) && ( setChangeVisible(true)}>扩缩副本 )} {global.hasPermission(ClustersPermissionMap.TOPIC_MOVE_REPLICA) && ( setMoveVisible(true)}>迁移副本 )} ); return ( <>
{/* 批量扩缩副本 */} {/* 批量迁移 */} {/* */} {/* */} {/*
*/}
{ setShowInternalTopics(checked); }} /> 展示系统Topic
{ setSearchKeywords(searchKeywordsInput); }} style={{ fontSize: '16px' }} /> } placeholder="请输入TopicName" value={searchKeywordsInput} onPressEnter={(_) => { setSearchKeywords(searchKeywordsInput); }} onChange={(e) => { setSearchKeywordsInput(e.target.value); }} /> {(global.hasPermission(ClustersPermissionMap.TOPIC_CHANGE_REPLICA) || global.hasPermission(ClustersPermissionMap.TOPIC_MOVE_REPLICA)) && ( )} {global.hasPermission && global.hasPermission(ClustersPermissionMap.TOPIC_ADD) ? ( ) : ( <> )}
{/* */} 0 ? { current: pageIndex, total: pageTotal, pageSize: pageSize, } : null, attrs: { className: `topic-list`, bordered: false, // rowSelection: rowSelection, scroll: { x: 'max-content', y: 'calc(100vh - 400px)' }, sortDirections: ['descend', 'ascend', 'default'], onChange: (pagination: any, filters: any, sorter: any) => { setSortObj({ sortField: sorter.field || '', sortType: sorter.order ? sorter.order.substring(0, sorter.order.indexOf('end')) : '', }); setPageIndex(pagination.current); setPageSize(pagination.pageSize); }, }, }} /> {} ); }; export default AutoPage;