All files / ee/app/assets/javascripts/analytics/productivity_analytics/store/modules/table actions.js

100% Statements 30/30
75% Branches 3/4
100% Functions 10/10
100% Lines 28/28

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          4x 3x   3x   3x             3x     2x 2x   1x     4x   4x 11x 11x   11x     4x 1x 1x     4x 2x     2x 1x     2x     4x 1x   1x     4x   4x 1x   1x    
import axios from '~/lib/utils/axios_utils';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { daysToMergeMetric } from '../../../constants';
import * as types from './mutation_types';
 
export const fetchMergeRequests = ({ dispatch, state, rootState, rootGetters }) => {
  dispatch('requestMergeRequests');
 
  const { sortField, sortOrder, pageInfo } = state;
 
  const params = {
    ...rootGetters['filters/getCommonFilterParams'](),
    days_to_merge: rootState.charts.charts.main.selected,
    sort: `${sortField}_${sortOrder}`,
    page: pageInfo ? pageInfo.page : null,
  };
 
  return axios
    .get(rootState.endpoint, { params })
    .then((response) => {
      const { headers, data } = response;
      dispatch('receiveMergeRequestsSuccess', { headers, data });
    })
    .catch((err) => dispatch('receiveMergeRequestsError', err));
};
 
export const requestMergeRequests = ({ commit }) => commit(types.REQUEST_MERGE_REQUESTS);
 
export const receiveMergeRequestsSuccess = ({ commit }, { headers, data: mergeRequests }) => {
  const normalizedHeaders = normalizeHeaders(headers);
  const pageInfo = parseIntPagination(normalizedHeaders);
 
  commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, { pageInfo, mergeRequests });
};
 
export const receiveMergeRequestsError = ({ commit }, { response }) => {
  const { status } = response;
  commit(types.RECEIVE_MERGE_REQUESTS_ERROR, status);
};
 
export const setSortField = ({ commit, dispatch }, data) => {
  commit(types.SET_SORT_FIELD, data);
 
  // let's make sure we update the column that we sort on (except for 'days_to_merge')
  if (data !== daysToMergeMetric.key) {
    dispatch('setColumnMetric', data);
  }
 
  dispatch('fetchMergeRequests');
};
 
export const toggleSortOrder = ({ commit, dispatch }) => {
  commit(types.TOGGLE_SORT_ORDER);
 
  dispatch('fetchMergeRequests');
};
 
export const setColumnMetric = ({ commit }, data) => commit(types.SET_COLUMN_METRIC, data);
 
export const setPage = ({ commit, dispatch }, data) => {
  commit(types.SET_PAGE, data);
 
  dispatch('fetchMergeRequests');
};