<commit_before>/*

### withList

Paginated items container

Options:

  - queryName: an arbitrary name for the query
  - collection: the collection to fetch the documents from
  - fragment: the fragment that defines which properties to fetch
  - fragmentName: the name of the fragment, passed to getFragment
  - limit: the number of documents to show initially
  - pollInterval: how often the data should be updated, in ms (set to 0 to disable polling)
  - terms: an object that defines which documents to fetch

Props Received:

  - terms: an object that defines which documents to fetch

Terms object can have the following properties:

  - view: String
  - userId: String
  - cat: String
  - date: String
  - after: String
  - before: String
  - enableCache: Boolean
  - listId: String
  - query: String # search query
  - postId: String
  - limit: String

*/

import React, { Component } from 'react';
import { withApollo, graphql } from 'react-apollo';
import gql from 'graphql-tag';
import update from 'immutability-helper';
import { getSetting, getFragment, getFragmentName, getCollection } from 'meteor/vulcan:core';
import Mingo from 'mingo';
import compose from 'recompose/compose';
import withState from 'recompose/withState';
import withIdle from './withIdle.jsx';
import withIdlePollingStopper from './withIdlePollingStopper.jsx'
// import IDLE_STATUSES from 'meteor/vulcan:core'

const withList = (options) => {

  // console.log(options)

  const {
    collectionName,
    stopPollingIdleStatus = "INACTIVE",
    limit = 10,
    pollInterval = getSetting('pollInterval', 0),
    totalResolver = true,
    enableCache = false,
    extraQueries,
  } = options;

  const collection = options.collection || getCollection(collectionName);

  const queryName = options.queryName || `${collection.options.collectionName}ListQuery`;
  const listResolverName = collection.options.resolvers.list && collection.options.resolvers.list.name;
  const totalResolverName = collection.options.resolvers.total && collection.options.resolvers.total.name;

  let fragment;

  if (options.fragment) {
    fragment = options.fragment;
  } else if (options.fragmentName) {
    fragment = getFragment(options.fragmentName);
  } else {
    fragment = getFragment(`${collection.options.collectionName}DefaultFragment`);
  }

  const fragmentName = getFragmentName(fragment);

  // build graphql query from options
  const query = gql`
    query ${queryName}($terms: JSON) {
      ${totalResolver ? `${totalResolverName}(terms: $terms)` : ``}
      ${listResolverName}(terms: $terms) {
        __typename
        ...${fragmentName}
      }
      ${extraQueries || ''}
    }
    ${fragment}
  `;

  const stateHoC = withState('paginationTerms', 'setPaginationTerms', props => {

    // get initial limit from props, or else options
    const paginationLimit = props.terms && props.terms.limit || limit;
    const paginationTerms = {
      limit: paginationLimit,
      itemsPerPage: paginationLimit,
    };

    return paginationTerms;
  });

  const graphQLHoC = graphql(
<commit_msg>Fixed caching<commit_after>/*

### withList

Paginated items container

Options:

  - queryName: an arbitrary name for the query
  - collection: the collection to fetch the documents from
  - fragment: the fragment that defines which properties to fetch
  - fragmentName: the name of the fragment, passed to getFragment
  - limit: the number of documents to show initially
  - pollInterval: how often the data should be updated, in ms (set to 0 to disable polling)
  - terms: an object that defines which documents to fetch

Props Received:

  - terms: an object that defines which documents to fetch

Terms object can have the following properties:

  - view: String
  - userId: String
  - cat: String
  - date: String
  - after: String
  - before: String
  - enableCache: Boolean
  - listId: String
  - query: String # search query
  - postId: String
  - limit: String

*/

import React, { Component } from 'react';
import { withApollo, graphql } from 'react-apollo';
import gql from 'graphql-tag';
import update from 'immutability-helper';
import { getSetting, getFragment, getFragmentName, getCollection } from 'meteor/vulcan:core';
import Mingo from 'mingo';
import compose from 'recompose/compose';
import withState from 'recompose/withState';
import withIdle from './withIdle.jsx';
import withIdlePollingStopper from './withIdlePollingStopper.jsx'
// import IDLE_STATUSES from 'meteor/vulcan:core'

const withList = (options) => {

  // console.log(options)

  const {
    collectionName,
    stopPollingIdleStatus = "INACTIVE",
    limit = 10,
    pollInterval = getSetting('pollInterval', 0),
    totalResolver = true,
    enableCache = false,
    extraQueries,
  } = options;

  const collection = options.collection || getCollection(collectionName);

  const queryName = options.queryName || `${collection.options.collectionName}ListQuery`;
  const listResolverName = collection.options.resolvers.list && collection.options.resolvers.list.name;
  const totalResolverName = collection.options.resolvers.total && collection.options.resolvers.total.name;

  let fragment;

  if (options.fragment) {
    fragment = options.fragment;
  } else if (options.fragmentName) {
    fragment = getFragment(options.fragmentName);
  } else {
    fragment = getFragment(`${collection.options.collectionName}DefaultFragment`);
  }

  const fragmentName = getFragmentName(fragment);

  // build graphql query from options
  const query = gql`
    query ${queryName}($terms: JSON, $enableCache: Boolean) {
      ${totalResolver ? `${totalResolverName}(terms: $terms, enableCache: $enableCache)` : ``}
      ${listResolverName}(terms: $terms, enableCache: $enableCache) {
        __typename
        ...${fragmentName}
      }
      ${extraQueries || ''}
    }
    ${fragment}
  `;

  const stateHoC = withState('paginationTerms', 'setPaginationTerms', props => {

    // get initial limit from props, or else options
    const paginationLimit = props.terms && props.terms.limit || limit;
    const paginationTerms = {
      limit: paginationLimit,
      itemsPerPage: paginationLimit,
    };

    return paginationTerms;
  });

  const graphQLHoC = graphql(

{'fraction_non_alphanumeric': 0.1040025719337727, 'fraction_numerical': 0.0012859668863526765, 'mean_word_length': 3.8083462132921175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2271707', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1779, 'n_words': 535}