<commit_before>import { createAction } from 'redux-actions';
import { createThunkAction } from 'utils/redux';

export const fetchDataExplorerInit = createAction('fetchDataExplorerInit');
export const fetchDataExplorerReady = createAction('fetchDataExplorerReady');
export const fetchDataExplorerFail = createAction('fetchDataExplorerFail');

const SECTION_NAMES = {
  'historical-emissions': 'historical_emissions',
  'ndc-sdg-linkages': 'ndc_sdg',
  'emission-pathways': 'emission_pathways',
  'ndc-content': 'ndc_content'
};
export const fetchDataExplorer = createThunkAction(
  'fetchDataExplorer',
  section => dispatch => {
    dispatch(fetchDataExplorerInit());
    fetch(`/api/v1/data/${SECTION_NAMES[section]}`)
      .then(response => {
        if (response.ok) {
          return response.json();
        }
        throw Error(response.statusText);
      })
      .then(data => {
        if (data) {
          dispatch(fetchDataExplorerReady({ data, section }));
        } else {
          dispatch(fetchDataExplorerReady({}));
        }
      })
      .catch(error => {
        console.warn(error);
        dispatch(fetchDataExplorerFail());
      });
  }
);

export default {
  fetchDataExplorer,
  fetchDataExplorerInit,
  fetchDataExplorerReady,
  fetchDataExplorerFail<commit_msg>Dont reload always the data of the different sections<commit_after>import { createAction } from 'redux-actions';
import { createThunkAction } from 'utils/redux';
import { DATA_EXPLORER_SECTION_NAMES } from 'data/constants';
import isEmpty from 'lodash/isEmpty';

export const fetchDataExplorerInit = createAction('fetchDataExplorerInit');
export const fetchDataExplorerReady = createAction('fetchDataExplorerReady');
export const fetchDataExplorerFail = createAction('fetchDataExplorerFail');

export const fetchDataExplorer = createThunkAction(
  'fetchDataExplorer',
  section => (dispatch, state) => {
    const { dataExplorer } = state();
    if (
      dataExplorer &&
      (isEmpty(dataExplorer) ||
        !dataExplorer.data[section] ||
        (isEmpty(dataExplorer.data[section].data) && !dataExplorer.loading))
    ) {
      dispatch(fetchDataExplorerInit());
      fetch(`/api/v1/data/${DATA_EXPLORER_SECTION_NAMES[section]}`)
        .then(response => {
          if (response.ok) {
            return response.json();
          }
          throw Error(response.statusText);
        })
        .then(data => {
          if (data) {
            dispatch(fetchDataExplorerReady({ data, section }));
          } else {
            dispatch(fetchDataExplorerReady({}));
          }
        })
        .catch(error => {
          console.warn(error);
          dispatch(fetchDataExplorerFail());
        });
    }
  }
);

export default {
  fetchDataExplorer,
  fetchDataExplorerInit,
  fetchDataExplorerReady,
  fetchDataExplorerFail
{'fraction_non_alphanumeric': 0.1223123017271766, 'fraction_numerical': 0.0007049700387733521, 'mean_word_length': 3.3394495412844036, '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': '1569752', 'n_tokens_mistral': 867, 'n_tokens_neox': 827, 'n_words': 141}