<commit_before>import { formatSelectOptionsForRange, formatSelectOptions } from '../../modules/utils';
import React from 'react';
import visTypes from './visTypes';
import * as v from '../validators';

const D3_FORMAT_DOCS = 'D3 format syntax: https://github.com/d3/d3-format';

// input choices & options
const D3_TIME_FORMAT_OPTIONS = [
  ['.3s', '.3s | 12.3k'],
  ['.3%', '.3% | 1234543.210%'],
  ['.4r', '.4r | 12350'],
  ['.3f', '.3f | 12345.432'],
  ['+,', '+, | +12,345.4321'],
  ['$,.2f', '$,.2f | $12,345.43'],
];

const ROW_LIMIT_OPTIONS = [10, 50, 100, 250, 500, 1000, 5000, 10000, 50000];

const SERIES_LIMITS = [0, 5, 10, 25, 50, 100, 500];

export const TIME_STAMP_OPTIONS = [
  ['smart_date', 'Adaptative formating'],
  ['%m/%d/%Y', '%m/%d/%Y | 01/14/2019'],
  ['%Y-%m-%d', '%Y-%m-%d | 2019-01-14'],
  ['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S | 2019-01-14 01:32:10'],
  ['%H:%M:%S', '%H:%M:%S | 01:32:10'],
];

export const fields = {
  datasource: {
    type: 'SelectField',
    label: 'Datasource',
    isLoading: true,
    clearable: false,
    default: null,
    mapStateToProps: (state) => {
      const datasources = state.datasources || [];
      return {
        choices: datasources,
        isLoading: datasources.length === 0,
        rightNode: state.datasource ?
          <a href={state.datasource.edit_url}>edit</a>
          : null,
      };
    },
    description: '',
  },

  viz_type: {
    type: 'SelectField',
    label: 'Visualization Type',
    clearable: false,
    default: 'table',
    choices: Object.keys(visTypes).map(vt => [
      vt,
      visTypes[vt].label,
      `/static/assets/images/viz_thumbnails/${vt}.png`,
    ]),
    description: 'The type of visualization to display',
  },

  metrics: {
    type: 'SelectField',
    multi: true,
    label: 'Metrics',
    validators: [v.nonEmpty],
    default: field => field.choices !== null ? [field.choices[0][0]] : null,
    mapStateToProps: (state) => ({
      choices: (state.datasource) ? state.datasource.metrics_combo : [],
    }),
    description: 'One or many metrics to display',
  },

  order_by_cols: {
    type: 'SelectField',
    multi: true,
    label: 'Ordering',
    default: [],
    description: 'One or many metrics to display',
    mapStateToProps: (state) => ({
      choices: (state.datasource) ? state.datasource.order_by_choices : [],
    }),
  },

  metric: {
    type: 'SelectField',
    label: 'Metric',
    clearable: false,
    description: 'Choose the metric',
    default: field => field.choices && field.choices.length > 0 ? field.choices[0][0] : null,
    mapStateToProps: (state) => ({
      choices: (state.datasource) ? state.datasource.metrics_combo : null,
    }),
  },
<commit_msg>[hotfix] dashboard won't load, error in fields.js<commit_after>import { formatSelectOptionsForRange, formatSelectOptions } from '../../modules/utils';
import React from 'react';
import visTypes from './visTypes';
import * as v from '../validators';

const D3_FORMAT_DOCS = 'D3 format syntax: https://github.com/d3/d3-format';

// input choices & options
const D3_TIME_FORMAT_OPTIONS = [
  ['.3s', '.3s | 12.3k'],
  ['.3%', '.3% | 1234543.210%'],
  ['.4r', '.4r | 12350'],
  ['.3f', '.3f | 12345.432'],
  ['+,', '+, | +12,345.4321'],
  ['$,.2f', '$,.2f | $12,345.43'],
];

const ROW_LIMIT_OPTIONS = [10, 50, 100, 250, 500, 1000, 5000, 10000, 50000];

const SERIES_LIMITS = [0, 5, 10, 25, 50, 100, 500];

export const TIME_STAMP_OPTIONS = [
  ['smart_date', 'Adaptative formating'],
  ['%m/%d/%Y', '%m/%d/%Y | 01/14/2019'],
  ['%Y-%m-%d', '%Y-%m-%d | 2019-01-14'],
  ['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S | 2019-01-14 01:32:10'],
  ['%H:%M:%S', '%H:%M:%S | 01:32:10'],
];

export const fields = {
  datasource: {
    type: 'SelectField',
    label: 'Datasource',
    isLoading: true,
    clearable: false,
    default: null,
    mapStateToProps: (state) => {
      const datasources = state.datasources || [];
      return {
        choices: datasources,
        isLoading: datasources.length === 0,
        rightNode: state.datasource ?
          <a href={state.datasource.edit_url}>edit</a>
          : null,
      };
    },
    description: '',
  },

  viz_type: {
    type: 'SelectField',
    label: 'Visualization Type',
    clearable: false,
    default: 'table',
    choices: Object.keys(visTypes).map(vt => [
      vt,
      visTypes[vt].label,
      `/static/assets/images/viz_thumbnails/${vt}.png`,
    ]),
    description: 'The type of visualization to display',
  },

  metrics: {
    type: 'SelectField',
    multi: true,
    label: 'Metrics',
    validators: [v.nonEmpty],
  default: field => field.choices && field.choices.length > 0 ? [field.choices[0][0]] : null,
    mapStateToProps: (state) => ({
      choices: (state.datasource) ? state.datasource.metrics_combo : [],
    }),
    description: 'One or many metrics to display',
  },

  order_by_cols: {
    type: 'SelectField',
    multi: true,
    label: 'Ordering',
    default: [],
    description: 'One or many metrics to display',
    mapStateToProps: (state) => ({
      choices: (state.datasource) ? state.datasource.order_by_choices : [],
    }),
  },

  metric: {
    type: 'SelectField',
    label: 'Metric',
    clearable: false,
    description: 'Choose the metric',
    default: field => field.choices && field.choices.length > 0 ? field.choices[0][0] : null,
    mapStateToProps: (state) => ({
      choices: (state.datasource) ? state.datasource.metrics_combo : null,
    }),
  },

{'fraction_non_alphanumeric': 0.19759168035030103, 'fraction_numerical': 0.052727604451742384, 'mean_word_length': 3.048744460856721, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 2, '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': '5625265', 'n_tokens_mistral': 2198, 'n_tokens_neox': 1967, 'n_words': 427}