<commit_before>/*eslint-disable import/no-webpack-loader-syntax*/
// The above is required for client, but not core... we seem to have stricter build settings
// in client.
// TODO:
//   - use strict build settings in core
//   - fixup webpack so that we don't need the worker-loader! syntax
// Loads Runs data, potentially including histories, based on a Query (see util/query.js)

import React from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {graphql, withApollo} from 'react-apollo';
import {RUNS_QUERY} from '../graphql/runs';
import {fragments, FAKE_HISTORY_QUERY, HISTORY_QUERY} from '../graphql/runs';
import {BOARD} from '../util/board';
import {makeShouldUpdate} from '../util/shouldUpdate';
import {
  updateRuns,
  setupKeySuggestions,
  sortRuns,
  getColumns,
} from '../util/runhelpers.js';
import withHistoryLoader from '../containers/HistoryLoader';
// TODO: read this from query
import {MAX_HISTORIES_LOADED} from '../util/constants.js';
import {JSONparseNaN} from '../util/jsonnan';
import * as Query from '../util/query';
import * as Run from '../util/runs';
import * as Filter from '../util/filters';
import _ from 'lodash';
import RunsDataWorker from './workers/RunsDataDerived.worker.js';

// Load the graphql data for this panel, currently loads all data for this project and entity.
function withRunsData() {
  return graphql(RUNS_QUERY, {
    alias: 'withRunsData',
    skip: ({query}) => !Query.needsOwnRunsQuery(query),
    options: ({query, requestSubscribe}) => {
      let order = 'timeline';
      if (query.sort && query.sort.name) {
        const serverPath = Filter.serverPathKey(
          Run.keyFromString(query.sort.name)
        );
        if (serverPath) {
          order = (query.sort.ascending ? '-' : '+') + serverPath;
        }
      }
      const defaults = {
        variables: {
          entityName: query.entity,
          name: query.model,
          order: order,
          requestSubscribe: requestSubscribe || false,
          limit: query.page && query.page.size,
          filters: JSON.stringify(Filter.toMongo(query.filters)),
        },
        notifyOnNetworkStatusChange: true,
      };
      if (BOARD) {
        defaults.pollInterval = 5000;
      }
      if (Query.shouldPoll(query)) {
        defaults.pollInterval = 60000;
      }
      return defaults;
    },
    props: ({data: {loading, project, viewer, fetchMore}, errors}) => {
      //TODO: For some reason the first poll causes loading to be true
      // if (project && projects.runs && loading) loading = false;
      return {
        loading,
        runs: project && project.runs,
        views: project && project.views,
        projectID: project && project.id,
        counts: {
          base: project && project.runs && project.runs.count,
          filtered: project && project.runs && project.runs.count,
          selected: project && project.runs && project.runs.count,
        },
        loadMore:
          project &&
          project.runs &&
          project.runs.pageInfo.hasNextPage &&
          (onDone =>
            fetchMore({
              variables: {
                cursor: project.runs.pageInfo.endCursor,
              },
              updateQuery: (previousResult, {fetchMoreResult}) => {
                const newEdges = fetchMoreResult.project.runs.edges;
                const pageInfo = fetchMoreResult.project.runs.pageInfo;

                return newEdges.length
                  ? {
                      project: {
                        __typename: previousResult.project.__typename,
                        id: previousResult.project.id,
                        runs: {
                          __typename: previousResult.project.runs.__typename,
                          edges: [
                            ...previousResult.project.runs.edges,
                            ...newEdges,
                          ],
                          pageInfo,
                        },
                      },
                    }
                  : previousResult;
              },
            }).then(onDone)),
      };
    },
  });
}

// Parses runs into runs/keySuggestions
function withDerivedRunsData(WrappedComponent) {
  let RunsDataDerived = class extends React.Component {
    state = {
      data: {
        base: [],
        filtered: [],
        filteredRunsById: {},
        selectedRuns: [],<commit_msg>Fix bug where we loaded same rusn twice sometimes.<commit_after>/*eslint-disable import/no-webpack-loader-syntax*/
// The above is required for client, but not core... we seem to have stricter build settings
// in client.
// TODO:
//   - use strict build settings in core
//   - fixup webpack so that we don't need the worker-loader! syntax
// Loads Runs data, potentially including histories, based on a Query (see util/query.js)

import React from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {graphql, withApollo} from 'react-apollo';
import {RUNS_QUERY} from '../graphql/runs';
import {fragments, FAKE_HISTORY_QUERY, HISTORY_QUERY} from '../graphql/runs';
import {BOARD} from '../util/board';
import {makeShouldUpdate} from '../util/shouldUpdate';
import {
  updateRuns,
  setupKeySuggestions,
  sortRuns,
  getColumns,
} from '../util/runhelpers.js';
import withHistoryLoader from '../containers/HistoryLoader';
// TODO: read this from query
import {MAX_HISTORIES_LOADED} from '../util/constants.js';
import {JSONparseNaN} from '../util/jsonnan';
import * as Query from '../util/query';
import * as Run from '../util/runs';
import * as Filter from '../util/filters';
import _ from 'lodash';
import RunsDataWorker from './workers/RunsDataDerived.worker.js';

// Load the graphql data for this panel, currently loads all data for this project and entity.
function withRunsData() {
  return graphql(RUNS_QUERY, {
    alias: 'withRunsData',
    skip: ({query}) => !Query.needsOwnRunsQuery(query),
    options: ({query, requestSubscribe}) => {
      let order = 'timeline';
      if (query.sort && query.sort.name) {
        const serverPath = Filter.serverPathKey(
          Run.keyFromString(query.sort.name)
        );
        if (serverPath) {
          order = (query.sort.ascending ? '-' : '+') + serverPath;
        }
      }
      const defaults = {
        variables: {
          entityName: query.entity,
          name: query.model,
          order: order,
          requestSubscribe: requestSubscribe || false,
          limit: query.page && query.page.size,
          filters: JSON.stringify(Filter.toMongo(query.filters)),
        },
        notifyOnNetworkStatusChange: true,
      };
      if (BOARD) {
        defaults.pollInterval = 5000;
      }
      if (Query.shouldPoll(query)) {
        defaults.pollInterval = 60000;
      }
      return defaults;
    },
    props: ({data: {loading, project, viewer, fetchMore}, errors}) => {
      let lastFetchMoreEndCursor;
      return {
        loading,
        runs: project && project.runs,
        views: project && project.views,
        projectID: project && project.id,
        counts: {
          base: project && project.runs && project.runs.count,
          filtered: project && project.runs && project.runs.count,
          selected: project && project.runs && project.runs.count,
        },
        loadMore:
          project &&
          project.runs &&
          project.runs.pageInfo.hasNextPage &&
          (onDone => {
            if (lastFetchMoreEndCursor === project.runs.pageInfo.endCursor) {
              onDone();
              return;
            }
            lastFetchMoreEndCursor = project.runs.pageInfo.endCursor;
            fetchMore({
              variables: {
                cursor: project.runs.pageInfo.endCursor,
              },
              updateQuery: (previousResult, {fetchMoreResult}) => {
                const newEdges = fetchMoreResult.project.runs.edges;
                const pageInfo = fetchMoreResult.project.runs.pageInfo;

                return newEdges.length
                  ? {
                      project: {
                        __typename: previousResult.project.__typename,
                        id: previousResult.project.id,
                        runs: {
                          __typename: previousResult.project.runs.__typename,
                          edges: [
                            ...previousResult.project.runs.edges,
                            ...newEdges,
                          ],
                          pageInfo,
                        },
                      },
                    }
                  : previousResult;
              },
            }).then(onDone);
          }),
      };
    },
  });
}

// Parses runs into runs/keySuggestions
function withDerivedRunsData(WrappedComponent) {
  let RunsDataDerived = class extends React.Component {
    state = {
      data: {
        base: [],
        filtered: [],
        filteredRunsById: {},
        selectedRuns: [],
{'fraction_non_alphanumeric': 0.11694352159468438, 'fraction_numerical': 0.0019933554817275745, 'mean_word_length': 1.913225806451613, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4729', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2425, 'n_words': 603}