<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { Table } from 'antd';

const DataTable = ({ model, data, children, translate, rowKey, params, total, setParams, ...rest }) => {

  const columns = React.Children.map(children, (child, index) => {

    const { source, ...rest } = child.props;

    return ({
      title: translate(`models.${model}.fields.${source}`),
      dataIndex: source,
      key: index,
      render: (value, record) => React.cloneElement(child, {
        record
      }),
      ...rest,
    })
  });

  const handleChange = (pagination, filters, sorter) => {
    const newParams = {
      _page: pagination.current,
      _limit: pagination.pageSize,
    };
    if (sorter.field && sorter.order !== false) {
      newParams._sort = sorter.field;
      newParams._order = sorter.order === "descend" ? "desc" : "asc";
    } else {
      newParams._sort = null;
      newParams._order = "asc";
    }
    setParams(newParams);
  };

  return (
    <div style={{margin: "16px 0"}}>
      <Table
        {...rest}
        rowKey={rowKey}
        dataSource={data}
        columns={columns}
        onChange={handleChange}
        pagination={{
          total,
          current: parseInt(params._page, 10),
          pageSize: parseInt(params._limit, 10),
        }}
      />
    </div>
  );

};

DataTable.defaultProps = {
  data: [],
  rowKey: "id",
  params: {},
  total: 0,
};

DataTable.propTypes = {
  model: PropTypes.string,
  data: PropTypes.array,
  translate: PropTypes.func,
  rowKey: PropTypes.string,
  params: PropTypes.object,
  total: PropTypes.number,
  setParams: PropTypes.func,
};

export default DataTable;<commit_msg>表格支持按钮<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { Table } from 'antd';

const DataTable = ({ model, data, children, translate, rowKey, params, total, setParams, ...rest }) => {

  const columns = React.Children.map(children, (child, index) => {

    const { source, ...rest } = child.props;

    return ({
      title: source ? translate(`models.${model}.fields.${source}`) : "",
      dataIndex: source,
      key: index,
      render: (value, record) => React.cloneElement(child, {
        record,
        model,
      }),
      ...rest,
    })
  });

  const handleChange = (pagination, filters, sorter) => {
    const newParams = {
      _page: pagination.current,
      _limit: pagination.pageSize,
    };
    if (sorter.field && sorter.order !== false) {
      newParams._sort = sorter.field;
      newParams._order = sorter.order === "descend" ? "desc" : "asc";
    } else {
      newParams._sort = null;
      newParams._order = "asc";
    }
    setParams(newParams);
  };

  return (
    <div style={{margin: "16px 0"}}>
      <Table
        {...rest}
        rowKey={rowKey}
        dataSource={data}
        columns={columns}
        onChange={handleChange}
        pagination={{
          total,
          current: parseInt(params._page, 10),
          pageSize: parseInt(params._limit, 10),
        }}
      />
    </div>
  );

};

DataTable.defaultProps = {
  data: [],
  rowKey: "id",
  params: {},
  total: 0,
};

DataTable.propTypes = {
  model: PropTypes.string,
  data: PropTypes.array,
  translate: PropTypes.func,
  rowKey: PropTypes.string,
  params: PropTypes.object,
  total: PropTypes.number,
  setParams: PropTypes.func,
};

export default DataTable;
{'fraction_non_alphanumeric': 0.15528860240257839, 'fraction_numerical': 0.004687957808379725, 'mean_word_length': 2.5195876288659793, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6188012', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1091, 'n_words': 237}