import React, { useState, useEffect } from 'react';
import { useParams, useHistory, useLocation } from 'react-router-dom';
import { Tabs, Drawer, Tag, Utils, AppContainer, SearchInput, Empty } from 'knowdesign';
import Api from '@src/api';
import { hashDataParse } from '../../constants/common';
import DataLogs from './DataLogs';
import Configuration from './Configuration';
import BrokerDetailHealthCheck from '@src/components/CardBar/BrokerDetailHealthCheck';
import './index.less';
import { ControlStatusMap } from '../CommonRoute';
const { TabPane } = Tabs;
const OperationsSlot: any = {
// eslint-disable-next-line react/display-name
['Configuration']: (arg: any) => {
return (
);
},
// eslint-disable-next-line react/display-name
['DataLogs']: (arg: any) => {
return (
);
},
};
const BrokerDetail = (props: any) => {
const [global] = AppContainer.useGlobalValue();
const urlParams = useParams<{ clusterId: string; brokerId: string }>();
const urlLocation = useLocation();
const history = useHistory();
const [positionType, setPositionType] = useState('Configuration');
const [searchKeywords, setSearchKeywords] = useState('');
const [searchValue, setSearchValue] = useState('');
const [visible, setVisible] = useState(false);
const [hashData, setHashData] = useState({});
const callback = (key: any) => {
setSearchValue('');
setSearchKeywords('');
setPositionType(key);
};
const onClose = () => {
setVisible(false);
setSearchValue('');
setSearchKeywords('');
setPositionType('Configuration');
// clean hash
history.push(urlLocation.pathname);
};
useEffect(() => {
global?.clusterInfo?.id && hashDataParse(urlLocation.hash).brokerId
? Utils.request(Api.getBrokerMetadata(hashDataParse(urlLocation.hash).brokerId, global?.clusterInfo?.id), {
init: {
errorNoTips: true,
},
})
.then((brokerData: any) => {
if (brokerData?.exist && brokerData?.alive) {
setHashData(brokerData);
setVisible(true);
} else {
history.replace(urlLocation.pathname);
setVisible(false);
}
})
.catch((err) => {
history.replace(urlLocation.pathname);
setVisible(false);
})
: setVisible(false);
}, [hashDataParse(urlLocation.hash).brokerId, global?.clusterInfo, urlLocation]);
return (
Broker {hashData?.brokerId}
{hashData?.host && (
{hashData?.host}
)}
{global?.clusterInfo?.name && (
{global?.clusterInfo?.name}
)}
}
width={1080}
placement="right"
onClose={onClose}
visible={visible}
className="broker-detail-drawer"
destroyOnClose
maskClosable={false}
>
{hashData && positionType && (
{global.isShowControl && global.isShowControl(ControlStatusMap.BROKER_DETAIL_CONFIG) ? (
) : (
)}
{global.isShowControl && global.isShowControl(ControlStatusMap.BROKER_DETAIL_DATALOGS) ? (
) : (
)}
)}
);
};
export default BrokerDetail;