import * as React from 'react'; import { SearchAndFilterContainer } from 'container/search-filter'; import { Table, Button, Popconfirm, Modal, Transfer, notification } from 'component/antd'; // import { Transfer } from 'antd' import { observer } from 'mobx-react'; import { pagination } from 'constants/table'; import Url from 'lib/url-parser'; import { IController } from 'types/base-type'; import { admin } from 'store/admin'; import './index.less'; import moment from 'moment'; import { timeFormat } from 'constants/strategy'; @observer export class ClusterController extends SearchAndFilterContainer { public clusterId: number; public state: any = { searchKey: '', searchCandidateKey: '', isCandidateModel: false, mockData: [], targetKeys: [], }; constructor(props: any) { super(props); const url = Url(); this.clusterId = Number(url.search.clusterId); } public getData(origin: T[]) { let data: T[] = origin; let { searchKey } = this.state; searchKey = (searchKey + '').trim().toLowerCase(); data = searchKey ? origin.filter((item: IController) => (item.host !== undefined && item.host !== null) && item.host.toLowerCase().includes(searchKey as string), ) : origin; return data; } public getCandidateData(origin: T[]) { let data: T[] = origin; let { searchCandidateKey } = this.state; searchCandidateKey = (searchCandidateKey + '').trim().toLowerCase(); data = searchCandidateKey ? origin.filter((item: IController) => (item.host !== undefined && item.host !== null) && item.host.toLowerCase().includes(searchCandidateKey as string), ) : origin; return data; } // 候选controller public renderCandidateController() { const columns = [ { title: 'BrokerId', dataIndex: 'brokerId', key: 'brokerId', width: '20%', sorter: (a: IController, b: IController) => b.brokerId - a.brokerId, render: (r: string, t: IController) => { return ( {r} ); }, }, { title: 'BrokerHost', key: 'host', dataIndex: 'host', width: '20%', // render: (r: string, t: IController) => { // return ( // {r} // // ); // }, }, { title: 'Broker状态', key: 'status', dataIndex: 'status', width: '20%', render: (r: number, t: IController) => { return ( {r === 1 ? '不在线' : '在线'} ); }, }, { title: '创建时间', dataIndex: 'startTime', key: 'startTime', width: '25%', sorter: (a: IController, b: IController) => b.timestamp - a.timestamp, render: (t: number) => moment(t).format(timeFormat), }, { title: '操作', dataIndex: 'operation', key: 'operation', width: '15%', render: (r: string, t: IController) => { return ( this.deleteCandidateCancel(t)} cancelText="取消" okText="确认" > 删除 ); }, }, ]; return ( ); } public renderController() { const columns = [ { title: 'BrokerId', dataIndex: 'brokerId', key: 'brokerId', width: '30%', sorter: (a: IController, b: IController) => b.brokerId - a.brokerId, render: (r: string, t: IController) => { return ( {r} ); }, }, { title: 'BrokerHost', key: 'host', dataIndex: 'host', width: '30%', }, { title: '变更时间', dataIndex: 'timestamp', key: 'timestamp', width: '40%', sorter: (a: IController, b: IController) => b.timestamp - a.timestamp, render: (t: number) => moment(t).format(timeFormat), }, ]; return (
); } public componentDidMount() { admin.getControllerHistory(this.clusterId); admin.getCandidateController(this.clusterId); admin.getBrokersMetadata(this.clusterId); } public addController = () => { this.setState({ isCandidateModel: true, targetKeys: [] }) } public addCandidateChange = (targetKeys: any) => { this.setState({ targetKeys }) } public handleCandidateCancel = () => { this.setState({ isCandidateModel: false }); } public handleCandidateOk = () => { let brokerIdList = this.state.targetKeys.map((item: any) => { return admin.brokersMetadata[item].brokerId }) admin.addCandidateController(this.clusterId, brokerIdList).then(data => { notification.success({ message: '新增成功' }); admin.getCandidateController(this.clusterId); }).catch(err => { notification.error({ message: '新增失败' }); }) this.setState({ isCandidateModel: false, targetKeys: [] }); } public deleteCandidateCancel = (target: any) => { admin.deleteCandidateCancel(this.clusterId, [target.brokerId]).then(() => { notification.success({ message: '删除成功' }); }); this.setState({ isCandidateModel: false }); } public renderAddCandidateController() { let filterControllerCandidate = admin.brokersMetadata.filter((item: any) => { return !admin.filtercontrollerCandidate.includes(item.brokerId) }) return ( this.handleCandidateOk()} onCancel={() => this.handleCandidateCancel()} footer={<> } > item.host} onChange={(targetKeys) => this.addCandidateChange(targetKeys)} titles={['未选', '已选']} locale={{ itemUnit: '项', itemsUnit: '项', }} listStyle={{ width: "45%", }} /> ); } public render() { return (
  • 候选Controller Controller将会优先从以下Broker中选举
  • {this.renderSearch('', '请查找Host', 'searchCandidateKey')}
{this.renderCandidateController()}
  • {this.props.tab}
  • {this.renderSearch('', '请输入Host')}
{this.renderController()} {this.renderAddCandidateController()}
); } }