/**
 * Created by baoyinghai on 5/26/17.
 */
import React from 'react';
import Setting from './setting';
import DashboardTable from '../../../mxa/table/dashboardTable';

export default class Table extends React.Component {

  processData = data => {
    const demo = data[0];
    if (!demo) return [];
    const { chartSetting } = this.props;
    return Object.keys(demo)
      .filter(key => key !== 'key') // 过滤不显示的字段
      .map(key => {
      return {
        width: 80,
        title: chartSetting && chartSetting[key] ? chartSetting[key] : key,
        dataIndex: key,
        key,
      };
    });
  };

  render() {
    const { dataSource } = this.props;
    const columns = this.processData(dataSource || []);
    return (
      <DashboardTable dataSource={dataSource} columns={columns} />
    );
  }
}

export const TableSetting = Setting;