All files / ee/app/assets/javascripts/insights/stores/modules/insights actions.js

97.36% Statements 37/38
83.33% Branches 10/12
100% Functions 13/13
97.22% Lines 35/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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            4x 4x 1x 4x 2x 2x 2x     2x     4x 3x   3x     2x 1x   1x       1x       4x 1x 4x 1x   4x 2x     1x           1x   1x     1x     1x     4x 3x   3x 2x   2x 1x 1x   1x             4x  
import { createAlert } from '~/alert';
import axios from '~/lib/utils/axios_utils';
import { __ } from '~/locale';
 
import * as types from './mutation_types';
 
export const requestConfig = ({ commit }) => commit(types.REQUEST_CONFIG);
export const receiveConfigSuccess = ({ commit }, data) =>
  commit(types.RECEIVE_CONFIG_SUCCESS, data);
export const receiveConfigError = ({ commit }, errorMessage) => {
  const error = errorMessage || __('Unknown Error');
  const message = `${__('There was an error fetching configuration for charts')}: ${error}`;
  createAlert({
    message,
  });
  commit(types.RECEIVE_CONFIG_ERROR);
};
 
export const fetchConfigData = ({ dispatch }, endpoint) => {
  dispatch('requestConfig');
 
  return axios
    .get(endpoint)
    .then(({ data }) => {
      if (data) {
        dispatch('receiveConfigSuccess', data);
      } else {
        dispatch('receiveConfigError');
      }
    })
    .catch((error) => {
      dispatch('receiveConfigError', error.response.data.message);
    });
};
 
export const receiveChartDataSuccess = ({ commit }, { chart, data }) =>
  commit(types.RECEIVE_CHART_SUCCESS, { chart, data });
export const receiveChartDataError = ({ commit }, { chart, error }) =>
  commit(types.RECEIVE_CHART_ERROR, { chart, error });
 
export const fetchChartData = ({ dispatch }, { endpoint, chart }) =>
  axios
    .post(endpoint, chart)
    .then(({ data }) =>
      dispatch('receiveChartDataSuccess', {
        chart,
        data,
      }),
    )
    .catch((error) => {
      let message = `${__('There was an error gathering the chart data')}`;
 
      Iif (error.response.data && error.response.data.message) {
        message += `: ${error.response.data.message}`;
      }
      createAlert({
        message,
      });
      dispatch('receiveChartDataError', { chart, error: message });
    });
 
export const setActiveTab = ({ commit, state }, key) => {
  const { configData } = state;
 
  if (configData) {
    const page = configData[key];
 
    if (page) {
      commit(types.SET_ACTIVE_TAB, key);
      commit(types.SET_ACTIVE_PAGE, page);
    } else {
      createAlert({
        message: __('The specified tab is invalid, please select another'),
      });
    }
  }
};
 
export const initChartData = ({ commit }, keys) => commit(types.INIT_CHART_DATA, keys);