alarm-list.tsx 2.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
import * as React from 'react';
import { Table, Button } from 'component/antd';
import { SearchAndFilterContainer } from 'container/search-filter';
import { observer } from 'mobx-react';
import { app } from 'store/app';
import { getAlarmColumns } from './add-alarm/config';
import { IMonitorStrategies } from 'types/base-type';
import { pagination } from 'constants/table';
import { urlPrefix } from 'constants/left-menu';
import { alarm } from 'store/alarm';
import 'styles/table-filter.less';

@observer
export class AlarmList extends SearchAndFilterContainer {
  public state = {
    searchKey: '',
  };

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

    if (app.active !== '-1' || searchKey !== '') {
      data = origin.filter(d =>
        ((d.name !== undefined && d.name !== null) && d.name.toLowerCase().includes(searchKey as string)
        || ((d.operator !== undefined && d.operator !== null) && d.operator.toLowerCase().includes(searchKey as string)))
        && (app.active === '-1' || d.appId === (app.active + '')),
      );
    } else {
      data = origin;
    }
    return data;
  }

  public renderTableList(data: IMonitorStrategies[]) {
    return (
      <Table
        rowKey="key"
        columns={getAlarmColumns(urlPrefix)}
        dataSource={data}
        pagination={pagination}
      />
    );
  }

  public renderTable() {
    return this.renderTableList(this.getData(alarm.monitorStrategies));
  }

  public renderOperationPanel() {
    return (
      <>
        {this.renderApp('应用:')}
Z
zengqiao 已提交
55
        {this.renderSearch('名称:', '请输入告警规则或者操作人')}
Z
zengqiao 已提交
56 57 58
        <li className="right-btn-1">
          <Button type="primary">
            <a href={`${urlPrefix}/alarm/add`}>
Z
zengqiao 已提交
59
              新增规则
Z
zengqiao 已提交
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
            </a>
          </Button>
        </li>
      </>
    );
  }

  public componentDidMount() {
    if (!alarm.monitorStrategies.length) {
      alarm.getMonitorStrategies();
    }
  }

  public render() {
    return (
      <div className="container">
        <div className="table-operation-panel">
          <ul>
            {this.renderOperationPanel()}
          </ul>
        </div>
        <div className="table-wrapper">
          {this.renderTable()}
        </div>
      </div>
    );
  }
}