<commit_before>import React from 'react';
import cx from 'classnames';
import { pure, skinnable, props, t } from '../utils';
import { Table } from 'fixed-data-table-2';
import Column, { defaultColumns, updateColumns } from './Column';
import FlexView from 'react-flexview';

const { maybe } = t;

/** A table component based on fixed-data-table-2
 * @param data - data shown in the table
 * @param width - the desired width of the table. Unless autosize is false, this can be left undefined
 * @param height - the desired height of the table.  Unless autosize is false, this can be left undefined
 * @param rowHeight - height in pixel of every row
 * @param headerHeight - height in pixel of header
 * @param groupHeaderHeight - height in pixel of groupHeader
 * @param footerHeight - height in pixel of footer
 * @param onRowMouseEnter - callback to be called when mouse enters a row
 * @param onRowMouseLeave - callback to be called when mouse leaves a row
 * @param autosize - wheater the table should resize to fit the available space. Default true.
 * @param columnsOrder - an array containing the ordered list of column names, in the same order they should be rendered
 * @param onColumnsReorder - callback to be called when the order of columns changes after dragging an header in a new position
 * @param onColumnResize - callback to be called when a column is resized
 * @param children - table children (Column or ColumnGroup)
 * @param scrollLeft - value of horizontal scroll
 * @param scrollTop - value of vertical scroll
 * @param onScrollStart - callback to be called when scrolling starts
 * @param onScrollEnd - callback to be called when scrolling ends
 * @param selectedRows - the list of selected row ids
 * @param onRowsSelect - callback to be called when the currently selected rows change
 * @param selectionType - single = only one selected row at a time, multi = multiple selection, none = selection disabled
 * @param hoveredRowIndex - the id of the hovered row
 * @param onHoverRowChange - callback to be called when the hovered row changes
 * @param sortBy - id of the column according which the data should be ordered
 * @param sortDir - sorting direction
 * @param onSortChange - callback to be called when sorting change
 *
 * @param scrollToRow - Private
 * @param onRowClick - Private
 * @param rowClassNameGetter - Private
 * @param onColumnResizeEndCallback - Private
 * @param isColumnResizing - Private
 */
@skinnable()
@pure
@props({
  // public
  className: maybe(t.String),
  data: t.Array,
  width: t.Number,
  height: t.Number,
  rowHeight: maybe(t.Number),
  headerHeight: maybe(t.Number),
  groupHeaderHeight: maybe(t.Number),
  footerHeight: maybe(t.Number),
  onRowMouseEnter: maybe(t.Function),
  onRowMouseLeave: maybe(t.Function),
  scrollLeft: maybe(t.Integer),
  scrollTop: maybe(t.Integer),
  onScrollStart: maybe(t.Function),
  onScrollEnd: maybe(t.Function),
  children: t.ReactChildren,

  // private
  scrollToRow: maybe(t.Integer),
  onRowClick: maybe(t.Function),
  rowClassNameGetter: maybe(t.Function),
  onColumnResizeEndCallback: maybe(t.Function),
  isColumnResizing: maybe(t.Boolean)
})
export default class Tablo extends React.Component {

  static defaultProps = {
    rowHeight: 30,
    headerHeight: 40,
    groupHeaderHeight: 50,
    footerHeight: 0
  }

  getLocals({ data, children, ...tableProps }) {

    const columnsOrGroups = updateColumns(children || defaultColumns(data), ({ col }) => {
      return <Column {...{ key: col.props.name, ...col.props, data }} />;
    }).map((ch, key) => ch.type({ key, ...ch.props }));

    t.assert(
      columnsOrGroups.length === ([].concat(children) || Object.keys).length,
      'There are extraneous children in the Grid. One should use only Column or ColumnGroup'
    );

    const rowsCount = data.length;

    return {
      columnsOrGroups,
      rowsCount,
      ...tableProps
    };
  }

  template({ columnsOrGroups, className, ...tableProps }) {
    return (
      <FlexView column grow className={cx('tablo', className)}>
        <Table {...tableProps}><commit_msg>fix tablo assert on children<commit_after>import React from 'react';
import cx from 'classnames';
import { pure, skinnable, props, t } from '../utils';
import { Table } from 'fixed-data-table-2';
import Column, { defaultColumns, updateColumns } from './Column';
import FlexView from 'react-flexview';

const { maybe } = t;

/** A table component based on fixed-data-table-2
 * @param data - data shown in the table
 * @param width - the desired width of the table. Unless autosize is false, this can be left undefined
 * @param height - the desired height of the table.  Unless autosize is false, this can be left undefined
 * @param rowHeight - height in pixel of every row
 * @param headerHeight - height in pixel of header
 * @param groupHeaderHeight - height in pixel of groupHeader
 * @param footerHeight - height in pixel of footer
 * @param onRowMouseEnter - callback to be called when mouse enters a row
 * @param onRowMouseLeave - callback to be called when mouse leaves a row
 * @param autosize - wheater the table should resize to fit the available space. Default true.
 * @param columnsOrder - an array containing the ordered list of column names, in the same order they should be rendered
 * @param onColumnsReorder - callback to be called when the order of columns changes after dragging an header in a new position
 * @param onColumnResize - callback to be called when a column is resized
 * @param children - table children (Column or ColumnGroup)
 * @param scrollLeft - value of horizontal scroll
 * @param scrollTop - value of vertical scroll
 * @param onScrollStart - callback to be called when scrolling starts
 * @param onScrollEnd - callback to be called when scrolling ends
 * @param selectedRows - the list of selected row ids
 * @param onRowsSelect - callback to be called when the currently selected rows change
 * @param selectionType - single = only one selected row at a time, multi = multiple selection, none = selection disabled
 * @param hoveredRowIndex - the id of the hovered row
 * @param onHoverRowChange - callback to be called when the hovered row changes
 * @param sortBy - id of the column according which the data should be ordered
 * @param sortDir - sorting direction
 * @param onSortChange - callback to be called when sorting change
 *
 * @param scrollToRow - Private
 * @param onRowClick - Private
 * @param rowClassNameGetter - Private
 * @param onColumnResizeEndCallback - Private
 * @param isColumnResizing - Private
 */
@skinnable()
@pure
@props({
  // public
  className: maybe(t.String),
  data: t.Array,
  width: t.Number,
  height: t.Number,
  rowHeight: maybe(t.Number),
  headerHeight: maybe(t.Number),
  groupHeaderHeight: maybe(t.Number),
  footerHeight: maybe(t.Number),
  onRowMouseEnter: maybe(t.Function),
  onRowMouseLeave: maybe(t.Function),
  scrollLeft: maybe(t.Integer),
  scrollTop: maybe(t.Integer),
  onScrollStart: maybe(t.Function),
  onScrollEnd: maybe(t.Function),
  children: t.ReactChildren,

  // private
  scrollToRow: maybe(t.Integer),
  onRowClick: maybe(t.Function),
  rowClassNameGetter: maybe(t.Function),
  onColumnResizeEndCallback: maybe(t.Function),
  isColumnResizing: maybe(t.Boolean)
})
export default class Tablo extends React.Component {

  static defaultProps = {
    rowHeight: 30,
    headerHeight: 40,
    groupHeaderHeight: 50,
    footerHeight: 0
  }

  getLocals({ data, children, ...tableProps }) {

    const columnsOrGroups = updateColumns(children || defaultColumns(data), ({ col }) => {
      return <Column {...{ key: col.props.name, ...col.props, data }} />;
    }).map((ch, key) => ch.type({ key, ...ch.props }));

    t.assert(
      columnsOrGroups.length === [].concat(children || Object.keys(data[0])).length,
      'There are extraneous children in the Grid. One should use only Column or ColumnGroup'
    );

    const rowsCount = data.length;

    return {
      columnsOrGroups,
      rowsCount,
      ...tableProps
    };
  }

  template({ columnsOrGroups, className, ...tableProps }) {
    return (
      <FlexView column grow className={cx('tablo', className)}>
        <Table {...tableProps}>
{'fraction_non_alphanumeric': 0.09902439024390244, 'fraction_numerical': 0.002317073170731707, 'mean_word_length': 3.776354105998835, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '613012', 'n_tokens_mistral': 2285, 'n_tokens_neox': 2241, 'n_words': 893}