<commit_before>import 'isomorphic-fetch';

// Services
import DatasetService from 'services/DatasetService';

/**
 * CONSTANTS
*/
const GET_SIMILAR_DATASETS_SUCCESS = 'GET_SIMILAR_DATASETS_SUCCESS';
const GET_SIMILAR_DATASETS_ERROR = 'GET_SIMILAR_DATASETS_ERROR';
const GET_SIMILAR_DATASETS_LOADING = 'GET_SIMILAR_DATASETS_LOADING';
const SET_SIMILAR_DATASETS = 'SET_SIMILAR_DATASETS';

/**
 * STORE
 */
const initialState = {
  similarDatasets: {
    data: [], // Similar datasets
    loading: true, // Are we loading the data?
    error: null // An error was produced while loading the data
  }
};

/**
 * REDUCER
 */
export default function (state = initialState, action) {
  switch (action.type) {
    case GET_SIMILAR_DATASETS_LOADING: {
      const similarDatasets = {
        loading: true,
        error: null
      };
      return Object.assign({}, state.similarDatasets, similarDatasets);
    }

    case GET_SIMILAR_DATASETS_SUCCESS: {
      const similarDatasets = {
        loading: false,
        error: null
      };
      return Object.assign({}, state.similarDatasets, similarDatasets);
    }

    case GET_SIMILAR_DATASETS_ERROR: {
      const similarDatasets = {
        loading: false,
        error: action.payload
      };
      return Object.assign({}, state.similarDatasets, similarDatasets);
    }

    case SET_SIMILAR_DATASETS: {
      const similarDatasets = {
        data: action.payload
      };
      return Object.assign({}, state.similarDatasets, similarDatasets);
    }

    default:
      return state;
  }
}

/**
 * ACTIONS
 */

/**
 * Retrieve the set of datasets that are similar to the one provided
 * @param {string} datasetId
 */
export function getSimilarDatasets(datasetId) {
  return (dispatch) => {
    dispatch({ type: GET_SIMILAR_DATASETS_LOADING });
    const service = new DatasetService(datasetId, { apiURL: process.env.WRI_API_URL });
    return service.getSimilarDatasets()
      .then((data) => {
        dispatch({ type: SET_SIMILAR_DATASETS, payload: data });
        return data;
      })
      .then(() => dispatch({ type: GET_SIMILAR_DATASETS_SUCCESS }))
      .catch((err) => {
        dispatch({ type: GET_SIMILAR_DATASETS_ERROR, payload: err.message });
      });
  };
}<commit_msg>fix redux state assignments<commit_after>import 'isomorphic-fetch';

// Services
import DatasetService from 'services/DatasetService';

/**
 * CONSTANTS
*/
const GET_SIMILAR_DATASETS_SUCCESS = 'GET_SIMILAR_DATASETS_SUCCESS';
const GET_SIMILAR_DATASETS_ERROR = 'GET_SIMILAR_DATASETS_ERROR';
const GET_SIMILAR_DATASETS_LOADING = 'GET_SIMILAR_DATASETS_LOADING';
const SET_SIMILAR_DATASETS = 'SET_SIMILAR_DATASETS';

/**
 * STORE
 */
const initialState = {
  similarDatasets: {
    data: [], // Similar datasets
    loading: true, // Are we loading the data?
    error: null // An error was produced while loading the data
  }
};

/**
 * REDUCER
 */
export default function (state = initialState, action) {
  switch (action.type) {
    case GET_SIMILAR_DATASETS_LOADING: {
      const similarDatasets = {
        loading: true,
        error: null
      };
      const newSimilarDatasets = Object.assign({}, state.similarDatasets, similarDatasets);
      return Object.assign(state, { similarDatasets: newSimilarDatasets });
    }

    case GET_SIMILAR_DATASETS_SUCCESS: {
      const similarDatasets = {
        loading: false,
        error: null
      };
      const newSimilarDatasets = Object.assign({}, state.similarDatasets, similarDatasets);
      return Object.assign(state, { similarDatasets: newSimilarDatasets });
    }

    case GET_SIMILAR_DATASETS_ERROR: {
      const similarDatasets = {
        loading: false,
        error: action.payload
      };
      const newSimilarDatasets = Object.assign({}, state.similarDatasets, similarDatasets);
      return Object.assign(state, { similarDatasets: newSimilarDatasets });
    }

    case SET_SIMILAR_DATASETS: {
      const similarDatasets = {
        data: action.payload
      };
      const newSimilarDatasets = Object.assign({}, state.similarDatasets, similarDatasets);
      return Object.assign(state, { similarDatasets: newSimilarDatasets });
    }

    default:
      return state;
  }
}

/**
 * ACTIONS
 */

/**
 * Retrieve the set of datasets that are similar to the one provided
 * @param {string} datasetId
 */
export function getSimilarDatasets(datasetId) {
  return (dispatch) => {
    dispatch({ type: GET_SIMILAR_DATASETS_LOADING });
    const service = new DatasetService(datasetId, { apiURL: process.env.WRI_API_URL, language: 'en' });
    return service.getSimilarDatasets()
      .then((data) => {
        dispatch({ type: SET_SIMILAR_DATASETS, payload: data });
        return data;
      })
      .then(() => dispatch({ type: GET_SIMILAR_DATASETS_SUCCESS }))
      .catch((err) => {
        dispatch({ type: GET_SIMILAR_DATASETS_ERROR, payload: err.message });
      });
  };
}
{'fraction_non_alphanumeric': 0.1109751121991024, 'fraction_numerical': 0.0, 'mean_word_length': 3.256076388888889, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '766405', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1559, 'n_words': 329}