config.tsx 11.6 KB
Newer Older
Z
zengqiao 已提交
1
import * as React from 'react';
2
import { IUser, IUploadFile, IConfigure, IConfigGateway, IMetaData } from 'types/base-type';
Z
zengqiao 已提交
3 4
import { users } from 'store/users';
import { version } from 'store/version';
5
import { showApplyModal, showApplyModalModifyPassword, showModifyModal, showConfigureModal, showConfigGatewayModal } from 'container/modal/admin';
Z
zengqiao 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import { Popconfirm, Tooltip } from 'component/antd';
import { admin } from 'store/admin';
import { cellStyle } from 'constants/table';
import { timeFormat } from 'constants/strategy';
import { urlPrefix } from 'constants/left-menu';
import moment = require('moment');

export const getUserColumns = () => {
  const columns = [
    {
      title: '用户名',
      dataIndex: 'username',
      key: 'username',
      width: '35%',
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: '30%',
      render: (text: string, record: IUser) => {
        return (
          <span className="table-operation">
Z
zengqiao 已提交
29
            <a onClick={() => showApplyModal(record)}>编辑</a>
30
            <a onClick={() => showApplyModalModifyPassword(record)}>修改密码</a>
31 32 33 34 35 36 37 38 39 40
            {record.username == users.currentUser.username ? "" :
                <Popconfirm
                  title="确定删除?"
                  onConfirm={() => users.deleteUser(record.username)}
                  cancelText="取消"
                  okText="确认"
                >
                  <a>删除</a>
                </Popconfirm>
            }
Z
zengqiao 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
          </span>);
      },
    },
  ];
  return columns;
};

export const getVersionColumns = () => {
  const columns = [
    {
      title: 'ID',
      dataIndex: 'id',
      key: 'id',
    },
    {
      title: '文件名称',
      dataIndex: 'fileName',
      key: 'fileName',
      render: (text: string, record: IUploadFile) => {
        return (
          <Tooltip placement="topLeft" title={text} >
Z
v2.1 fe  
zengqiao 已提交
62
            <a href={`${window.origin}/api/v1/rd/kafka-files/${record.id}/config-files?dataCenter=cn`} target="_blank">{text}</a>
Z
zengqiao 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
          </Tooltip>);
      },
    }, {
      title: 'MD5',
      dataIndex: 'fileMd5',
      key: 'fileMd5',
      onCell: () => ({
        style: {
          maxWidth: 120,
          ...cellStyle,
        },
      }),
      render: (text: string) => {
        return (
          <Tooltip placement="bottomLeft" title={text} >
Z
v2.1 fe  
zengqiao 已提交
78
            {text.substring(0, 8)}
Z
zengqiao 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
          </Tooltip>);
      },
    }, {
      title: '更新时间',
      dataIndex: 'gmtModify',
      key: 'gmtModify',
      render: (t: number) => moment(t).format(timeFormat),
    }, {
      title: '更新人',
      dataIndex: 'operator',
      key: 'operator',
    }, {
      title: '备注',
      dataIndex: 'description',
      key: 'description',
      onCell: () => ({
        style: {
          maxWidth: 200,
          ...cellStyle,
        },
      }),
      render: (text: string) => {
        return (
          <Tooltip placement="topLeft" title={text} >
Z
v2.1 fe  
zengqiao 已提交
103
            {text}
Z
zengqiao 已提交
104 105 106 107
          </Tooltip>);
      },
    }, {
      title: '操作',
Z
v2.1 fe  
zengqiao 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
      dataIndex: 'operation',
      key: 'operation',
      render: (text: string, record: IUploadFile) => {
        return (
          <span className="table-operation">
            <a onClick={() => showModifyModal(record)}>编辑</a>
            <Popconfirm
              title="确定删除?"
              onConfirm={() => version.deleteFile(record.id)}
              cancelText="取消"
              okText="确认"
            >
              <a>删除</a>
            </Popconfirm>
          </span>);
Z
zengqiao 已提交
123
      },
Z
v2.1 fe  
zengqiao 已提交
124
    },
Z
zengqiao 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
  ];
  return columns;
};

export const getConfigureColumns = () => {
  const columns = [
    {
      title: '配置键',
      dataIndex: 'configKey',
      key: 'configKey',
      width: '20%',
      sorter: (a: IConfigure, b: IConfigure) => a.configKey.charCodeAt(0) - b.configKey.charCodeAt(0),
    },
    {
      title: '配置值',
      dataIndex: 'configValue',
      key: 'configValue',
      width: '30%',
      sorter: (a: IConfigure, b: IConfigure) => a.configValue.charCodeAt(0) - b.configValue.charCodeAt(0),
      render: (t: string) => {
        return t.substr(0, 1) === '{' && t.substr(0, -1) === '}' ? JSON.stringify(JSON.parse(t), null, 4) : t;
      },
    },
    {
      title: '修改时间',
      dataIndex: 'gmtModify',
      key: 'gmtModify',
      width: '20%',
      sorter: (a: IConfigure, b: IConfigure) => b.gmtModify - a.gmtModify,
      render: (t: number) => moment(t).format(timeFormat),
    },
    {
      title: '描述信息',
      dataIndex: 'configDescription',
      key: 'configDescription',
      width: '20%',
      onCell: () => ({
        style: {
          maxWidth: 180,
          ...cellStyle,
        },
      }),
    },
    {
      title: '操作',
      width: '10%',
      render: (text: string, record: IConfigure) => {
        return (
          <span className="table-operation">
Z
zengqiao 已提交
174
            <a onClick={() => showConfigureModal(record)}>编辑</a>
Z
zengqiao 已提交
175 176 177
            <Popconfirm
              title="确定删除?"
              onConfirm={() => admin.deleteConfigure(record.configKey)}
Z
v2.1 fe  
zengqiao 已提交
178 179
              cancelText="取消"
              okText="确认"
Z
zengqiao 已提交
180 181 182 183 184 185 186 187 188 189
            >
              <a>删除</a>
            </Popconfirm>
          </span>);
      },
    },
  ];
  return columns;
};

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
// 网关配置
export const getConfigColumns = () => {
  const columns = [
    {
      title: '配置类型',
      dataIndex: 'type',
      key: 'type',
      width: '25%',
      ellipsis: true,
      sorter: (a: IConfigGateway, b: IConfigGateway) => a.type.charCodeAt(0) - b.type.charCodeAt(0),
    },
    {
      title: '配置键',
      dataIndex: 'name',
      key: 'name',
      width: '15%',
      ellipsis: true,
      sorter: (a: IConfigGateway, b: IConfigGateway) => a.name.charCodeAt(0) - b.name.charCodeAt(0),
    },
    {
      title: '配置值',
      dataIndex: 'value',
      key: 'value',
      width: '20%',
      ellipsis: true,
      sorter: (a: IConfigGateway, b: IConfigGateway) => a.value.charCodeAt(0) - b.value.charCodeAt(0),
      render: (t: string) => {
        return t.substr(0, 1) === '{' && t.substr(0, -1) === '}' ? JSON.stringify(JSON.parse(t), null, 4) : t;
      },
    },
    {
      title: '修改时间',
      dataIndex: 'modifyTime',
      key: 'modifyTime',
      width: '15%',
      sorter: (a: IConfigGateway, b: IConfigGateway) => b.modifyTime - a.modifyTime,
      render: (t: number) => moment(t).format(timeFormat),
    },
    {
      title: '版本号',
      dataIndex: 'version',
      key: 'version',
      width: '10%',
      ellipsis: true,
      sorter: (a: IConfigGateway, b: IConfigGateway) => b.version.charCodeAt(0) - a.version.charCodeAt(0),
    },
    {
      title: '描述信息',
      dataIndex: 'description',
      key: 'description',
      width: '20%',
      ellipsis: true,
      onCell: () => ({
        style: {
          maxWidth: 180,
          ...cellStyle,
        },
      }),
    },
    {
      title: '操作',
      width: '10%',
      render: (text: string, record: IConfigGateway) => {
        return (
          <span className="table-operation">
            <a onClick={() => showConfigGatewayModal(record)}>编辑</a>
            <Popconfirm
              title="确定删除?"
              onConfirm={() => admin.deleteConfigGateway({ id: record.id })}
              cancelText="取消"
              okText="确认"
            >
              <a>删除</a>
            </Popconfirm>
          </span>);
      },
    },
  ];
  return columns;
};

Z
v2.1 fe  
zengqiao 已提交
271
const renderClusterHref = (value: number | string, item: IMetaData, key: number) => {
Z
zengqiao 已提交
272 273
  return ( // 0 暂停监控--不可点击  1 监控中---可正常点击
    <>
Z
v2.1 fe  
zengqiao 已提交
274 275
      {item.status === 1 ? <a href={`${urlPrefix}/admin/cluster-detail?clusterId=${item.clusterId}#${key}`}>{value}</a>
        : <a style={{ cursor: 'not-allowed', color: '#999' }}>{value}</a>}
Z
zengqiao 已提交
276 277 278 279 280 281 282
    </>
  );
};

export const getAdminClusterColumns = () => {
  return [
    {
Z
v2.1 fe  
zengqiao 已提交
283
      title: '物理集群ID',
Z
zengqiao 已提交
284 285 286 287 288
      dataIndex: 'clusterId',
      key: 'clusterId',
      sorter: (a: IMetaData, b: IMetaData) => b.clusterId - a.clusterId,
    },
    {
Z
v2.1 fe  
zengqiao 已提交
289
      title: '物理集群名称',
Z
zengqiao 已提交
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
      dataIndex: 'clusterName',
      key: 'clusterName',
      sorter: (a: IMetaData, b: IMetaData) => a.clusterName.charCodeAt(0) - b.clusterName.charCodeAt(0),
      render: (text: string, item: IMetaData) => renderClusterHref(text, item, 1),
    },
    {
      title: 'Topic数',
      dataIndex: 'topicNum',
      key: 'topicNum',
      sorter: (a: any, b: IMetaData) => b.topicNum - a.topicNum,
      render: (text: number, item: IMetaData) => renderClusterHref(text, item, 2),
    },
    {
      title: 'Broker数',
      dataIndex: 'brokerNum',
      key: 'brokerNum',
      sorter: (a: IMetaData, b: IMetaData) => b.brokerNum - a.brokerNum,
      render: (text: number, item: IMetaData) => renderClusterHref(text, item, 3),
    },
    {
      title: 'Consumer数',
      dataIndex: 'consumerGroupNum',
      key: 'consumerGroupNum',
      sorter: (a: IMetaData, b: IMetaData) => b.consumerGroupNum - a.consumerGroupNum,
      render: (text: number, item: IMetaData) => renderClusterHref(text, item, 4),
    },
    {
      title: 'Region数',
      dataIndex: 'regionNum',
      key: 'regionNum',
      sorter: (a: IMetaData, b: IMetaData) => b.regionNum - a.regionNum,
      render: (text: number, item: IMetaData) => renderClusterHref(text, item, 5),
    },
    {
      title: 'Controllerld',
      dataIndex: 'controllerId',
      key: 'controllerId',
      sorter: (a: IMetaData, b: IMetaData) => b.controllerId - a.controllerId,
      render: (text: number, item: IMetaData) => renderClusterHref(text, item, 7),
    },
    {
      title: '监控中',
      dataIndex: 'status',
      key: 'status',
      sorter: (a: IMetaData, b: IMetaData) => b.key - a.key,
      render: (value: number) => value === 1 ?
        <span className="success"></span > : <span className="fail"></span>,
    },
  ];
};

export const getPartitionInfoColumns = () => {
  return [{
    title: 'Topic',
    dataIndex: 'topicName',
    key: 'topicName',
    width: '21%',
    render: (val: string) => <Tooltip placement="bottomLeft" title={val}> {val} </Tooltip>,
  }, {
    title: 'Leader',
    dataIndex: 'leaderPartitionList',
    width: '20%',
    onCell: () => ({
      style: {
        maxWidth: 250,
        overflow: 'hidden',
        whiteSpace: 'nowrap',
        textOverflow: 'ellipsis',
        cursor: 'pointer',
      },
    }),
    render: (value: number[]) => {
      return (
        <Tooltip placement="bottomLeft" title={value.join('')}>
          {value.map(i => <span key={i} className="p-params">{i}</span>)}
        </Tooltip>
      );
    },
  }, {
    title: '副本',
    dataIndex: 'followerPartitionIdList',
    width: '22%',
    onCell: () => ({
      style: {
        maxWidth: 250,
        overflow: 'hidden',
        whiteSpace: 'nowrap',
        textOverflow: 'ellipsis',
        cursor: 'pointer',
      },
    }),
    render: (value: number[]) => {
      return (
        <Tooltip placement="bottomLeft" title={value.join('')}>
          {value.map(i => <span key={i} className="p-params">{i}</span>)}
        </Tooltip>
      );
    },
  }, {
    title: '未同步副本',
    dataIndex: 'notUnderReplicatedPartitionIdList',
    width: '22%',
    onCell: () => ({
      style: {
        maxWidth: 250,
        overflow: 'hidden',
        whiteSpace: 'nowrap',
        textOverflow: 'ellipsis',
        cursor: 'pointer',
      },
    }),
    render: (value: number[]) => {
      return (
        <Tooltip placement="bottomLeft" title={value.join('')}>
          {value.map(i => <span key={i} className="p-params p-params-unFinished">{i}</span>)}
        </Tooltip>
      );
    },
  }];
};