All files / javascripts/explorev2/stores store.js

100% Statements 14/14
80% Branches 16/20
100% Functions 6/6
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52  1x 1x   10x 5x           5x 5x 26x 63x 97x       5x     3x 3x                             6x 3x                        
/* eslint camelcase: 0 */
import { sectionsToRender } from './visTypes';
import fields from './fields';
 
export function defaultFormData(vizType = 'table', datasourceType = 'table') {
  const data = {
    slice_name: null,
    slice_id: null,
    datasource_name: null,
    filters: [],
  };
  const sections = sectionsToRender(vizType, datasourceType);
  sections.forEach((section) => {
    section.fieldSetRows.forEach((fieldSetRow) => {
      fieldSetRow.forEach((k) => {
        data[k] = fields[k].default;
      });
    });
  });
  return data;
}
 
export function defaultViz(vizType, datasourceType = 'table') {
  return {
    cached_key: null,
    cached_timeout: null,
    cached_dttm: null,
    column_formats: null,
    csv_endpoint: null,
    is_cached: false,
    data: [],
    form_data: defaultFormData(vizType, datasourceType),
    json_endpoint: null,
    query: null,
    standalone_endpoint: null,
  };
}
 
export function initialState(vizType = 'table', datasourceType = 'table') {
  return {
    dashboards: [],
    isDatasourceMetaLoading: false,
    datasources: null,
    datasource_type: null,
    filterColumnOpts: [],
    fields,
    viz: defaultViz(vizType, datasourceType),
    isStarred: false,
  };
}