import { AppContainer, Divider, IconFont, Progress, Tooltip, Utils } from 'knowdesign';
import React, { useEffect, useState } from 'react';
import AccessClusters from '../MutliClusterPage/AccessCluster';
import './index.less';
import API from '../../api';
import HealthySetting from './HealthySetting';
import CheckDetail from './CheckDetail';
import { Link, useHistory, useParams } from 'react-router-dom';
import { getHealthClassName, getHealthProcessColor, getHealthState, getHealthText, renderToolTipValue } from './config';
import { ClustersPermissionMap } from '../CommonConfig';
const LeftSider = () => {
const [global] = AppContainer.useGlobalValue();
const history = useHistory();
const [kafkaVersion, setKafkaVersion] = useState({});
const [clusterInfo, setClusterInfo] = useState({} as any);
const [loading, setLoading] = React.useState(false);
const [clusterMetrics, setClusterMetrics] = useState({} as any);
const [brokerState, setBrokerState] = useState({} as any);
const detailDrawerRef: any = React.createRef();
const healthyDrawerRef: any = React.createRef();
const { clusterId } = useParams<{ clusterId: string }>();
const [visible, setVisible] = React.useState(false);
const getSupportKafkaVersion = () => {
Utils.request(API.supportKafkaVersion).then((res) => {
setKafkaVersion(res || {});
});
};
const getBrokerState = () => {
return Utils.request(API.getBrokersState(clusterId)).then((res) => {
setBrokerState(res);
});
};
const getPhyClusterMetrics = () => {
return Utils.post(
API.getPhyClusterMetrics(+clusterId),
[
'HealthScore',
'HealthCheckPassed',
'HealthCheckTotal',
'Topics',
'PartitionURP',
'PartitionNoLeader', // > 0 error
'PartitionMinISR_S', // > 0 error
'Groups',
'GroupDeads',
'Alive',
].concat(process.env.BUSINESS_VERSION ? ['LoadReBalanceEnable', 'LoadReBalanceNwIn', 'LoadReBalanceNwOut', 'LoadReBalanceDisk'] : [])
).then((res: any) => {
setClusterMetrics(res?.metrics || {});
});
};
const getPhyClusterInfo = () => {
setLoading(true);
Utils.request(API.getPhyClusterBasic(+clusterId))
.then((res: any) => {
let jmxProperties = null;
try {
jmxProperties = JSON.parse(res?.jmxProperties);
} catch (err) {
console.error(err);
}
// 转化值对应成表单值
if (jmxProperties?.openSSL) {
jmxProperties.security = 'Password';
}
if (jmxProperties) {
res = Object.assign({}, res || {}, jmxProperties);
}
setClusterInfo(res);
setLoading(false);
})
.catch((err) => {
setLoading(false);
});
};
useEffect(() => {
getBrokerState();
getPhyClusterMetrics();
getSupportKafkaVersion();
getPhyClusterInfo();
}, []);
const renderIcon = (type: string) => {
return (