<commit_before>//@flow
import { change, formValueSelector } from "redux-form";
import { connect } from "react-redux";
import {
  makeDataTableHandlers,
  getQueryParams,
  setCurrentParamsOnUrl,
  getMergedOpts,
  getCurrentParamsFromUrl
} from "./queryParams";
import compose from "lodash/fp/compose";
import { map } from "lodash";
import { withRouter } from "react-router-dom";

/**
 *  Note all these options can be passed at Design Time or at Runtime (like reduxForm())
 * 
 * @export
 * 
 * @param {compOrOpts} compOrOpts  
 * @typedef {object} compOrOpts  
 * @property {*string} formName - required unique identifier for the table
 * @property {*boolean} schema - The data table schema
 * @property {boolean} urlConnected - whether the table should connect to/update the URL
 * @property {boolean} withSelectedEntities - whether or not to pass the selected entities
 * @property {object} defaults - tableParam defaults such as pageSize, filter, etc
 */
export default function withTableParams(compOrOpts, pTopLevelOpts) {
  let topLevelOptions;
  let Component;
  if (!pTopLevelOpts) {
    topLevelOptions = compOrOpts;
  } else {
    topLevelOptions = pTopLevelOpts;
    Component = compOrOpts;
  }
  const { isLocalCall } = topLevelOptions;

  const mapStateToProps = (state, ownProps) => {
    const mergedOpts = getMergedOpts(topLevelOptions, ownProps);
    const {
      history,
      urlConnected,
      withSelectedEntities,
      formName,
      formNameFromWithTPCall,
      defaults,
      schema,
      isInfinite
    } = mergedOpts;

    if (ownProps.isTableParamsConnected) {
      if (
        formName &&
        formNameFromWithTPCall &&
        formName !== formNameFromWithTPCall
      ) {
        console.error(
          `You passed a formName prop, ${formName} to a <DataTable/> component that is already withTableParams() connected, formNameFromWithTableParamsCall: ${formNameFromWithTPCall}`
        );
      }
      if (!ownProps.entities) {
        console.error(
          `No entities array detected in tableParams object (<DataTable {...tableParams}/>). You need to compose(withTableParams(), withQuery(something)). formNameFromWithTableParamsCall: ${formNameFromWithTPCall}`
        );
      }
      //short circuit because we've already run this logic
      return {};
    }

    let formNameFromWithTableParamsCall;
    if (isLocalCall) {
      if (!formName) {
        console.error(<commit_msg>fixing warning to ensure withQuery is invoked after withTableParams<commit_after>//@flow
import { change, formValueSelector } from "redux-form";
import { connect } from "react-redux";
import {
  makeDataTableHandlers,
  getQueryParams,
  setCurrentParamsOnUrl,
  getMergedOpts,
  getCurrentParamsFromUrl
} from "./queryParams";
import compose from "lodash/fp/compose";
import { map } from "lodash";
import { withRouter } from "react-router-dom";

/**
 *  Note all these options can be passed at Design Time or at Runtime (like reduxForm())
 * 
 * @export
 * 
 * @param {compOrOpts} compOrOpts  
 * @typedef {object} compOrOpts  
 * @property {*string} formName - required unique identifier for the table
 * @property {*boolean} schema - The data table schema
 * @property {boolean} urlConnected - whether the table should connect to/update the URL
 * @property {boolean} withSelectedEntities - whether or not to pass the selected entities
 * @property {object} defaults - tableParam defaults such as pageSize, filter, etc
 */
export default function withTableParams(compOrOpts, pTopLevelOpts) {
  let topLevelOptions;
  let Component;
  if (!pTopLevelOpts) {
    topLevelOptions = compOrOpts;
  } else {
    topLevelOptions = pTopLevelOpts;
    Component = compOrOpts;
  }
  const { isLocalCall } = topLevelOptions;

  const mapStateToProps = (state, ownProps) => {
    const mergedOpts = getMergedOpts(topLevelOptions, ownProps);
    const {
      history,
      urlConnected,
      withSelectedEntities,
      formName,
      formNameFromWithTPCall,
      defaults,
      schema,
      isInfinite
    } = mergedOpts;

    if (ownProps.isTableParamsConnected) {
      if (
        formName &&
        formNameFromWithTPCall &&
        formName !== formNameFromWithTPCall
      ) {
        console.error(
          `You passed a formName prop, ${formName} to a <DataTable/> component that is already withTableParams() connected, formNameFromWithTableParamsCall: ${formNameFromWithTPCall}`
        );
      }
      if (ownProps.tableParams && !ownProps.tableParams.entities) {
        console.error(
          `No entities array detected in tableParams object (<DataTable {...tableParams}/>). You need to call withQuery() after withTableParams() like: compose(withTableParams(), withQuery(something)). formNameFromWithTableParamsCall: ${formNameFromWithTPCall}`
        );
      }
      //short circuit because we've already run this logic
      return {};
    }

    let formNameFromWithTableParamsCall;
    if (isLocalCall) {
      if (!formName) {
        console.error(
{'fraction_non_alphanumeric': 0.09446774515678051, 'fraction_numerical': 0.0, 'mean_word_length': 3.408450704225352, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2634473', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1444, 'n_words': 411}