<commit_before>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import _ from 'lodash';
import Filter from './Filter.js';
import Pagination from './Pagination.js';
import PageSize from './PageSize.js';
import makeSelectors from './selectors.js';
import {
  tableInitialize,
  tableNewData,
  tablePageChanged,
  tablePageSizeChanged,
  tableFilterChanged,
  tableFilterTextChanged,
  tableSortChanged,
  tableRowCheckedChanged,
  tableSelectAllChanged,
  tableSetFilter,
} from './actions.js';

const propTypes = {
  data: PropTypes.array,

  isInitialized: PropTypes.bool.isRequired,
  visibleRows: PropTypes.array,
  filter: PropTypes.array,
  sortInfo: PropTypes.object,
  pageInfo: PropTypes.object,
  selectAll: PropTypes.bool,
  selectedRows: PropTypes.array,
  primaryKey: PropTypes.string,
  filterOptions: PropTypes.array,
  filterValue: PropTypes.array,

  onPageChange: PropTypes.func.isRequired,
  onPageSizeChange: PropTypes.func.isRequired,
  onFilterChange: PropTypes.func.isRequired,
  onFilterTextChange: PropTypes.func.isRequired,
  onHeaderClick: PropTypes.func.isRequired,
  onInitialize: PropTypes.func.isRequired,
  onNewData: PropTypes.func.isRequired,
  onNewFilterValue: PropTypes.func.isRequired,
  onRowCheckedChange: PropTypes.func.isRequired,
  onSelectAllChange: PropTypes.func.isRequired,
};

/**
 * Wrapper for adding filter, sort and pagination for tabular data.
 *
 * See AppsTable.js and AppsPage.js on how to use the wrapper.
 *
 * When wrapping a table component, you need to provide the component itself,
 * and column definitions.  Column definitions should look like this:
 *
 *  {
 *    id: { header: 'ID', searchable: true },
 *    name: { header: 'Name', searchable: true },
 *  };
 *
 */
const sematable = (tableName, TableComponent, columns, configs = {}) => {
  const selectors = makeSelectors(tableName);

  const mapStateToProps = (state) => {
    const isInitialized = selectors.getIsInitialized(state);
    if (!isInitialized) {
      return {
        isInitialized,
      };
    }
    return {
      isInitialized,
      visibleRows: selectors.getVisible(state),
      filter: selectors.getFilter(state),
      sortInfo: selectors.getSortInfo(state),
      pageInfo: selectors.getPageInfo(state),
      selectAll: selectors.getSelectAll(state),
      selectedRows: selectors.getSelectedRows(state),
      primaryKey: selectors.getPrimaryKey(state),
      filterOptions: selectors.getFilterOptions(state),
    };
  };

  const mapDispatchToProps = (dispatch) => ({
    onPageChange: (page) => dispatch(tablePageChanged(tableName, page)),
    onPageSizeChange: (pageSize) => dispatch(tablePageSizeChanged(tableName, pageSize)),
    onFilterChange: (filter) => dispatch(tableFilterChanged(tableName, filter)),
    onFilterTextChange: (filterText) => dispatch(tableFilterTextChanged(tableName, filterText)),
    onHeaderClick: (sortKey) => dispatch(tableSortChanged(tableName, sortKey)),
    onNewData: (data) => dispatch(tableNewData(tableName, data)),
    onNewFilterValue: (data) => dispatch(tableSetFilter(tableName, data)),
    onSelectAllChange: () => dispatch(tableSelectAllChanged(tableName)),
    onRowCheckedChange: (row) => dispatch(tableRowCheckedChanged(tableName, row)),
    onInitialize: (data, filterValue) =>
      dispatch(tableInitialize(tableName, data, columns, configs, filterValue)),
  });

  class DataTable extends Component {
    componentWillMount() {
      const { data, filterValue, onInitialize } = this.props;
      onInitialize(data, filterValue);
    }

    componentWillReceiveProps(nextProps) {
      const {
        data,
        filterValue,
        onNewData,
        onNewFilterValue,
      } = this.props;

      if (data !== nextProps.data) {
        onNewData(nextProps.data);
      }

      if (filterValue !== nextProps.filterValue) {
        onNewFilterValue(nextProps.filterValue);
      }
    }

    render() {
      const {
        /* props */
        isInitialized,
        visibleRows,
        filter,
        sortInfo,
        pageInfo,
        selectAll,
        selectedRows,
        primaryKey,
        filterOptions,

        /* actions */
        onPageChange,
        onPageSizeChange,
        onFilterChange,
        onFilterTextChange,
        onHeaderClick,
        onRowCheckedChange,
        onSelectAllChange,
        ...otherProps,
      } = this.props;
      const {
        showPageSize = true,
        showFilter = true,
        autoHidePagination = true,
        pageSizeContainerClassName = 'col-md-6',
        filterContainerClassName = 'col-md-6',
        pageSizeClassName,<commit_msg>Fix data not being defined<commit_after>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import _ from 'lodash';
import Filter from './Filter.js';
import Pagination from './Pagination.js';
import PageSize from './PageSize.js';
import makeSelectors from './selectors.js';
import {
  tableInitialize,
  tableNewData,
  tablePageChanged,
  tablePageSizeChanged,
  tableFilterChanged,
  tableFilterTextChanged,
  tableSortChanged,
  tableRowCheckedChanged,
  tableSelectAllChanged,
  tableSetFilter,
} from './actions.js';

const propTypes = {
  data: PropTypes.array,

  isInitialized: PropTypes.bool.isRequired,
  visibleRows: PropTypes.array,
  filter: PropTypes.array,
  sortInfo: PropTypes.object,
  pageInfo: PropTypes.object,
  selectAll: PropTypes.bool,
  selectedRows: PropTypes.array,
  primaryKey: PropTypes.string,
  filterOptions: PropTypes.array,
  filterValue: PropTypes.array,

  onPageChange: PropTypes.func.isRequired,
  onPageSizeChange: PropTypes.func.isRequired,
  onFilterChange: PropTypes.func.isRequired,
  onFilterTextChange: PropTypes.func.isRequired,
  onHeaderClick: PropTypes.func.isRequired,
  onInitialize: PropTypes.func.isRequired,
  onNewData: PropTypes.func.isRequired,
  onNewFilterValue: PropTypes.func.isRequired,
  onRowCheckedChange: PropTypes.func.isRequired,
  onSelectAllChange: PropTypes.func.isRequired,
};

/**
 * Wrapper for adding filter, sort and pagination for tabular data.
 *
 * See AppsTable.js and AppsPage.js on how to use the wrapper.
 *
 * When wrapping a table component, you need to provide the component itself,
 * and column definitions.  Column definitions should look like this:
 *
 *  {
 *    id: { header: 'ID', searchable: true },
 *    name: { header: 'Name', searchable: true },
 *  };
 *
 */
const sematable = (tableName, TableComponent, columns, configs = {}) => {
  const selectors = makeSelectors(tableName);

  const mapStateToProps = (state) => {
    const isInitialized = selectors.getIsInitialized(state);
    if (!isInitialized) {
      return {
        isInitialized,
      };
    }
    return {
      isInitialized,
      visibleRows: selectors.getVisible(state),
      filter: selectors.getFilter(state),
      sortInfo: selectors.getSortInfo(state),
      pageInfo: selectors.getPageInfo(state),
      selectAll: selectors.getSelectAll(state),
      selectedRows: selectors.getSelectedRows(state),
      primaryKey: selectors.getPrimaryKey(state),
      filterOptions: selectors.getFilterOptions(state),
    };
  };

  const mapDispatchToProps = (dispatch) => ({
    onPageChange: (page) => dispatch(tablePageChanged(tableName, page)),
    onPageSizeChange: (pageSize) => dispatch(tablePageSizeChanged(tableName, pageSize)),
    onFilterChange: (filter) => dispatch(tableFilterChanged(tableName, filter)),
    onFilterTextChange: (filterText) => dispatch(tableFilterTextChanged(tableName, filterText)),
    onHeaderClick: (sortKey) => dispatch(tableSortChanged(tableName, sortKey)),
    onNewData: (data) => dispatch(tableNewData(tableName, data)),
    onNewFilterValue: (data) => dispatch(tableSetFilter(tableName, data)),
    onSelectAllChange: () => dispatch(tableSelectAllChanged(tableName)),
    onRowCheckedChange: (row) => dispatch(tableRowCheckedChanged(tableName, row)),
    onInitialize: (data, filterValue) =>
      dispatch(tableInitialize(tableName, data, columns, configs, filterValue)),
  });

  class DataTable extends Component {
    componentWillMount() {
      const { data, filterValue, onInitialize } = this.props;
      onInitialize(data, filterValue);
    }

    componentWillReceiveProps(nextProps) {
      const {
        data,
        filterValue,
        onNewData,
        onNewFilterValue,
      } = this.props;

      if (data !== nextProps.data) {
        onNewData(nextProps.data);
      }

      if (filterValue !== nextProps.filterValue) {
        onNewFilterValue(nextProps.filterValue);
      }
    }

    render() {
      const {
        /* props */
        isInitialized,
        visibleRows,
        filter,
        sortInfo,
        pageInfo,
        selectAll,
        selectedRows,
        primaryKey,
        filterOptions,
        data,

        /* actions */
        onPageChange,
        onPageSizeChange,
        onFilterChange,
        onFilterTextChange,
        onHeaderClick,
        onRowCheckedChange,
        onSelectAllChange,
        ...otherProps,
      } = this.props;
      const {
        showPageSize = true,
        showFilter = true,
        autoHidePagination = true,
        pageSizeContainerClassName = 'col-md-6',
        filterContainerClassName = 'col-md-6',
        pageSizeClassName,
{'fraction_non_alphanumeric': 0.10739191073919108, 'fraction_numerical': 0.000429138504452312, 'mean_word_length': 3.4688398849472675, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2922536', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2700, 'n_words': 564}