<commit_before>import * as  React from 'react';
import {
  Table,
  Row,
  Col,
} from 'antd';
import { ColumnProps as TableColumnConfig } from 'antd/lib/table/Column';
export { ColumnProps as TableColumnConfig } from 'antd/lib/table/Column';
import { connect } from 'react-redux';
import { TokenState } from '../../../models/common/token';
export { SearchTypeDecorator, ToolbarButtonDecorator, AdvanceSearchDecorator
, CascaderDecorator, DateDecorator, SelectDecorator, InputNumberDecorator, InputDecorator
, AdvanceSearchType } from '../../../components/common/TableSearchBar';
import TableSearchBar, { SearchTypeDecorator, ToolbarButtonDecorator
, AdvanceSearchDecorator, getAdvanceSearchDefaultValues } from '../../../components/common/TableSearchBar';
import { Sorter, ListState } from '../../../util/listReducers';
import './style.less';
import { MIN_HEIGHT } from '../../../util/constants';

const noLoop = () => {};

export interface SorterConfig {
  key: string;
  fieldName: string;
  ascend: any;
  descend: any;
}

interface TableStateDecorator extends ListState<any> {
}

export interface UniTableOwnProps {
  /** 加载数据的action */
  apiAction: any;
  /** 表格store */
  tableState: TableStateDecorator;
  /** 行定义 */
  columns: TableColumnConfig<any>[];
  /** 是否显示工具栏 */
  hasToolbar?: boolean;
  /** 工具栏按钮 */
  toolbarButtons?: ToolbarButtonDecorator[];
  /** 查询类型 */
  searchTypes?: SearchTypeDecorator;
  /** 加载数据接口需要的额外参数 */
  otherParams?: any;
  /** 是否有scroll.x */
  hasScrollX?: boolean;
  /** scroll.y */
  scrollY?: number;
  /** scrol.y 需要减去的值 */
  scrollY_offset?: number;
  /** 是否不需要mappingType */
  noMappingType?: boolean;
  /** 首次渲染是否加载数据 */
  loadFirstTime?: boolean;
  /** 默认每页数据数量 */
  defaultPageSize?: number;
  /** 表格行的类名 */
  rowClassName?: string | ((record: any, index: number) => string);
  /** 是否提供选择行 */
  hasRowSelection?: boolean;
  /** 表头 */
  title?: any;
  /** 是否显示正在加载 */
  showLoading?: boolean;
  /** 首次加载是否重置页码 */
  resetPaginationFirstTime?: boolean;
  /** 高级查询项 */
  advanceSearchs?: AdvanceSearchDecorator[];
  /** 是否显示分页  */
  pagination?: boolean;
  rowSelection?: (selectedKeys: any[], selectedRows: any[]) => void;
  sorterConfigs?: SorterConfig[];
  className?: string;
  tableClassName?: string;
  toolbarClassName?: string;
  smallToolbar?: boolean;
  onExpand?: any;
  expandedRowKeys?: any;
  expandedRowRender?: any;
  rowKey?: any;
}

export interface UniTableProps extends UniTableOwnProps {
  height: number;
  dispatch: any;
  token: TokenState;
}

interface UniTableState {
  formValues: any;
  selectedRows: any[];
  selectedRowKeys: string[];
}

/**
 * 增强型Table
 */
class UniTable extends React.Component<UniTableProps, Partial<UniTableState>> {

  static defaultProps = {
    resetPaginationFirstTime: false,
    advanceSearchs: [],
    pagination: true,
    rowSelection: noLoop,
    rowClassName: '',
    toolbarButtons: [],
    className: '',
    tableClassName: '',
    smallToolbar: false,
    showLoading: true,
  };

  private columns: TableColumnConfig<any>[];
  private scrollX: number;
  private rowSelection: any;

  constructor(props) {
    super(props);

    this.state = {
      selectedRows: [],
      selectedRowKeys: [],
      formValues: {},
    };
  }

  componentDidMount() {
    if (this.props.loadFirstTime !== false) {
      let pageNo = undefined;
      let pageSize = undefined;
      if (this.props.pagination !== false) {
        pageNo = 1;
        pageSize = 10;
        if (!this.props.resetPaginationFirstTime) {
          pageNo = this.props.tableState.pagination.current || 1;
          pageSize = this.props.tableState.pagination.pageSize || 10;
        }
      }
      let advanceSearchSelectFields = getAdvanceSearchDefaultValues(this.props.advanceSearchs);
      this.getList({ pageNo: pageNo, pageSize: pageSize,
      ...advanceSearchSelectFields, ...this.props.tableState.queryData}, this.props.tableState.sorter);
    }
  }

  getList = (queryData, sorter: Sorter) => {
    const {
      token,
      dispatch,
      apiAction,
      otherParams,
    } = this.props;
    let sorterParams = {};
    if (sorter) {
      sorterParams[sorter.fieldName] = sorter.value;
    }
    let except = {
      sorter: sorter,
    };
    dispatch(apiAction({...token, ...queryData, ...otherParams, ...sorterParams, except}));
  }

  onSelectChange(selectedKeys, selectedRows) {
    this.setState({
      selectedRows,
      selectedRowKeys: selectedKeys,
    });
    this.props.rowSelection(selectedKeys, selectedRows);
  }

  handleTableChange(pagination, filters, sorter) {
    let params = {
      pageNo: pagination.current,
      pageSize: pagination.pageSize,
    };
    let advanceSearchSelectFields = this.state.formValues;
    let sorterState: Sorter = null;
    let sorterConfigs = this.props.sorterConfigs || [];
    sorterConfigs.forEach(s => {
      if (s.key === sorter.columnKey) {
        sorterState = {
          key: sorter.columnKey,
          fieldName: s.fieldName,
          sortOrder: sorter.order,
          value: s[sorter.order],
        };
      }
    });
    this.getList({...advanceSearchSelectFields, ...params}, sorterState);
  }

  handleSearch = (queryData) => {
    this.getList(queryData, this.props.tableState.sorter);
  }

  handleReset = (queryData) => {
    this.getList(queryData, this.props.tableState.sorter);
  }

  handleActionClick = (clickFunc) => {<commit_msg>react-admin: fix bug of UniTable<commit_after>import * as  React from 'react';
import {
  Table,
  Row,
  Col,
} from 'antd';
import { ColumnProps as TableColumnConfig } from 'antd/lib/table/Column';
export { ColumnProps as TableColumnConfig } from 'antd/lib/table/Column';
import { connect } from 'react-redux';
import { TokenState } from '../../../models/common/token';
export { SearchTypeDecorator, ToolbarButtonDecorator, AdvanceSearchDecorator
, CascaderDecorator, DateDecorator, SelectDecorator, InputNumberDecorator, InputDecorator
, AdvanceSearchType } from '../../../components/common/TableSearchBar';
import TableSearchBar, { SearchTypeDecorator, ToolbarButtonDecorator
, AdvanceSearchDecorator, getAdvanceSearchDefaultValues } from '../../../components/common/TableSearchBar';
import { Sorter, ListState } from '../../../util/listReducers';
import './style.less';
import { MIN_HEIGHT } from '../../../util/constants';

const noLoop = () => {};

export interface SorterConfig {
  key: string;
  fieldName: string;
  ascend: any;
  descend: any;
}

interface TableStateDecorator extends ListState<any> {
}

export interface UniTableOwnProps {
  /** 加载数据的action */
  apiAction: any;
  /** 表格store */
  tableState: TableStateDecorator;
  /** 行定义 */
  columns: TableColumnConfig<any>[];
  /** 是否显示工具栏 */
  hasToolbar?: boolean;
  /** 工具栏按钮 */
  toolbarButtons?: ToolbarButtonDecorator[];
  /** 查询类型 */
  searchTypes?: SearchTypeDecorator;
  /** 加载数据接口需要的额外参数 */
  otherParams?: any;
  /** 是否有scroll.x */
  hasScrollX?: boolean;
  /** scroll.y */
  scrollY?: number;
  /** scrol.y 需要减去的值 */
  scrollY_offset?: number;
  /** 是否不需要mappingType */
  noMappingType?: boolean;
  /** 首次渲染是否加载数据 */
  loadFirstTime?: boolean;
  /** 默认每页数据数量 */
  defaultPageSize?: number;
  /** 表格行的类名 */
  rowClassName?: string | ((record: any, index: number) => string);
  /** 是否提供选择行 */
  hasRowSelection?: boolean;
  /** 表头 */
  title?: any;
  /** 是否显示正在加载 */
  showLoading?: boolean;
  /** 首次加载是否重置页码 */
  resetPaginationFirstTime?: boolean;
  /** 高级查询项 */
  advanceSearchs?: AdvanceSearchDecorator[];
  /** 是否显示分页  */
  pagination?: boolean;
  rowSelection?: (selectedKeys: any[], selectedRows: any[]) => void;
  sorterConfigs?: SorterConfig[];
  className?: string;
  tableClassName?: string;
  toolbarClassName?: string;
  smallToolbar?: boolean;
  onExpand?: any;
  expandedRowKeys?: any;
  expandedRowRender?: any;
  rowKey?: any;
}

export interface UniTableProps extends UniTableOwnProps {
  height: number;
  dispatch: any;
  token: TokenState;
}

interface UniTableState {
  formValues: any;
  selectedRows: any[];
  selectedRowKeys: string[];
}

/**
 * 增强型Table
 */
class UniTable extends React.Component<UniTableProps, Partial<UniTableState>> {

  static defaultProps = {
    resetPaginationFirstTime: false,
    advanceSearchs: [],
    pagination: true,
    rowSelection: noLoop,
    rowClassName: '',
    toolbarButtons: [],
    className: '',
    tableClassName: '',
    smallToolbar: false,
    showLoading: true,
  };

  private columns: TableColumnConfig<any>[];
  private scrollX: number;
  private rowSelection: any;

  constructor(props) {
    super(props);

    this.state = {
      selectedRows: [],
      selectedRowKeys: [],
      formValues: {},
    };
  }

  componentDidMount() {
    if (this.props.loadFirstTime !== false) {
      let pageNo = undefined;
      let pageSize = undefined;
      if (this.props.pagination !== false) {
        pageNo = 1;
        pageSize = 10;
        if (!this.props.resetPaginationFirstTime) {
          pageNo = this.props.tableState.pagination.current || 1;
          pageSize = this.props.tableState.pagination.pageSize || 10;
        }
      }
      let advanceSearchSelectFields = getAdvanceSearchDefaultValues(this.props.advanceSearchs);
      this.getList({ pageNo: pageNo, pageSize: pageSize,
      ...advanceSearchSelectFields, ...this.props.tableState.queryData}, this.props.tableState.sorter);
    }
  }

  getList = (queryData, sorter: Sorter) => {
    const {
      token,
      dispatch,
      apiAction,
      otherParams,
    } = this.props;
    let sorterParams = {};
    if (sorter) {
      sorterParams[sorter.fieldName] = sorter.value;
    }
    let except = {
      sorter: sorter,
    };
    dispatch(apiAction({...token, ...queryData, ...otherParams, ...sorterParams, except}));
  }

  onSelectChange(selectedKeys, selectedRows) {
    this.setState({
      selectedRows,
      selectedRowKeys: selectedKeys,
    });
    this.props.rowSelection(selectedKeys, selectedRows);
  }

  handleTableChange(pagination, filters, sorter) {
    let params = {
      pageNo: pagination.current,
      pageSize: pagination.pageSize,
    };
    let advanceSearchSelectFields = this.state.formValues;
    let sorterState: Sorter = null;
    let sorterConfigs = this.props.sorterConfigs || [];
    sorterConfigs.forEach(s => {
      if (s.key === sorter.columnKey) {
        sorterState = {
          key: sorter.columnKey,
          fieldName: s.fieldName,
          sortOrder: sorter.order,
          value: s[sorter.order],
        };
      }
    });
    this.getList({...advanceSearchSelectFields, ...params}, sorterState);
  }

  handleSearch = (queryData) => {
    this.getList(queryData, this.props.tableState.sorter);
  }

  handleReset = (queryData) => {
    this.setState({
      formValues: {},
    });
    this.getList(queryData, this.props.tableState.sorter);
  }

  handleActionClick = (clickFunc) => {
{'fraction_non_alphanumeric': 0.14097727063587007, 'fraction_numerical': 0.0011042606055028986, 'mean_word_length': 3.2536203522504894, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, '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': '4229208', 'n_tokens_mistral': 3579, 'n_tokens_neox': 3654, 'n_words': 692}