connect-information.tsx 3.3 KB
Newer Older
Z
zengqiao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
import * as React from 'react';
import './index.less';
import { observer } from 'mobx-react';
import { topic, IConnectionInfo } from 'store/topic';
import { Table, Tooltip } from 'component/antd';
import { SearchAndFilterContainer } from 'container/search-filter';
import Url from 'lib/url-parser';
import { pagination, cellStyle } from 'constants/table';

@observer
export class ConnectInformation extends SearchAndFilterContainer {
  public clusterId: number;
  public topicName: string;

  public state = {
    searchKey: '',
  };
  constructor(props: any) {
    super(props);
    const url = Url();
    this.clusterId = Number(url.search.clusterId);
    this.topicName = url.search.topic;
  }

  public renderConnectionInfo(connectInfo: IConnectionInfo[]) {
    const clientType = Object.assign({
      title: '客户端类型',
      dataIndex: 'clientType',
      key: 'clientType',
      width: '20%',
      filters: [{ text: '消费', value: 'consumer' }, { text: '生产', value: 'produce' }],
      onFilter: (value: string, record: IConnectionInfo) => record.clientType.indexOf(value) === 0,
      render: (t: string) =>
        <span>{t === 'consumer' ? '消费' : '生产'}</span>,
    }, this.renderColumnsFilter('filterVisible'));

    const columns = [{
      title: 'AppID',
      dataIndex: 'appId',
      key: 'appId',
      width: '20%',
      sorter: (a: IConnectionInfo, b: IConnectionInfo) => a.appId.charCodeAt(0) - b.appId.charCodeAt(0),
    },
    {
      title: '主机名',
      dataIndex: 'hostname',
      key: 'hostname',
      width: '40%',
      onCell: () => ({
        style: {
          maxWidth: 250,
          ...cellStyle,
        },
      }),
      render: (t: string) => {
        return (
          <Tooltip placement="bottomLeft" title={t} >{t}</Tooltip>
        );
      },
    },
    {
      title: '客户端版本',
      dataIndex: 'clientVersion',
      key: 'clientVersion',
      width: '20%',
    },
      clientType,
    ];
    if (connectInfo) {
      return (
        <>
          <Table dataSource={connectInfo} columns={columns} pagination={pagination} loading={topic.loading} />
        </>
      );
    }
  }

  public getData<T extends IConnectionInfo>(origin: T[]) {
    let data: T[] = [];
    let { searchKey } = this.state;
    searchKey = (searchKey + '').trim().toLowerCase();

    if (searchKey !== '') {
      data = origin.filter(d =>
        ((d.appId !== undefined && d.appId !== null) && d.appId.toLowerCase().includes(searchKey as string))
        || ((d.hostname !== undefined && d.hostname !== null) && d.hostname.toLowerCase().includes(searchKey as string)),
      );
    } else {
      data = origin;
    }
    return data;
  }

  public componentDidMount() {
Z
v2.1 fe  
zengqiao 已提交
95 96
    // const appId = this.props.baseInfo.appId;
    topic.getConnectionInfo(this.clusterId, this.topicName, '');
Z
zengqiao 已提交
97 98 99 100 101 102 103
  }

  public render() {
    return (
      <>
        <div className="k-row" >
          <ul className="k-tab">
孙超 已提交
104 105 106
            <li>
              连接信息 <span style={{ color: '#a7a8a9', fontSize: '12px', padding: '0 15px' }}>展示近20分钟的连接信息</span>
            </li>
Z
zengqiao 已提交
107 108 109 110 111 112 113 114
            {this.renderSearch('', '请输入连接信息', 'searchKey')}
          </ul>
          {this.renderConnectionInfo(this.getData(topic.connectionInfo))}
        </div>
      </>
    );
  }
}