all files / src/explore/ index.jsx

0% Statements 0/38
0% Branches 0/4
0% Functions 0/1
0% Lines 0/34
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85                                                                                                                                                                         
/* eslint camelcase: 0 */
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
 
import shortid from 'shortid';
import { now } from '../modules/dates';
import { initEnhancer } from '../reduxUtils';
import { getChartKey } from './exploreUtils';
import AlertsWrapper from '../components/AlertsWrapper';
import { getControlsState, getFormDataFromControls } from './store';
import { initJQueryAjax } from '../modules/utils';
import ExploreViewContainer from './components/ExploreViewContainer';
import rootReducer from './reducers/index';
 
import { appSetup } from '../common';
import './main.css';
import '../../stylesheets/reactable-pagination.css';
 
appSetup();
initJQueryAjax();
 
const exploreViewContainer = document.getElementById('app');
const bootstrapData = JSON.parse(exploreViewContainer.getAttribute('data-bootstrap'));
const controls = getControlsState(bootstrapData, bootstrapData.form_data);
const rawFormData = { ...bootstrapData.form_data };
delete bootstrapData.form_data;
delete bootstrapData.common.locale;
delete bootstrapData.common.language_pack;
 
// Initial state
const bootstrappedState = Object.assign(
  bootstrapData, {
    rawFormData,
    controls,
    filterColumnOpts: [],
    isDatasourceMetaLoading: false,
    isStarred: false,
  },
);
const slice = bootstrappedState.slice;
const sliceFormData = slice ?
  getFormDataFromControls(getControlsState(bootstrapData, slice.form_data))
  :
  null;
const chartKey = getChartKey(bootstrappedState);
const initState = {
  charts: {
    [chartKey]: {
      chartKey,
      chartAlert: null,
      chartStatus: 'loading',
      chartUpdateEndTime: null,
      chartUpdateStartTime: now(),
      latestQueryFormData: getFormDataFromControls(controls),
      sliceFormData,
      queryRequest: null,
      queryResponse: null,
      triggerQuery: true,
      lastRendered: 0,
    },
  },
  saveModal: {
    dashboards: [],
    saveModalAlert: null,
  },
  explore: bootstrappedState,
  impressionId: shortid.generate(),
};
const store = createStore(rootReducer, initState,
  compose(applyMiddleware(thunk), initEnhancer(false)),
);
 
ReactDOM.render(
  <Provider store={store}>
    <div>
      <ExploreViewContainer />
      <AlertsWrapper initMessages={bootstrappedState.common.flash_messages} />
    </div>
  </Provider>,
  exploreViewContainer,
);