All files / ee/app/assets/javascripts/analytics/cycle_analytics/store actions.js

97.91% Statements 47/48
76.19% Branches 16/21
100% Functions 17/17
97.82% Lines 45/46

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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140                          4x         96x           96x               4x   4x 2x 2x 1x 1x     95x   4x         88x   88x 86x       4x 21x   21x 21x 11x           4x 98x   98x 98x 98x 88x   11x         11x 9x     11x       4x 95x   4x 108x                     108x 108x   108x 108x                     108x 102x     108x 2x   106x     108x   108x         108x          
import { getGroupLabels } from 'ee/api/analytics_api';
import { removeFlash } from '~/analytics/shared/utils';
import { createAlert } from '~/alert';
import { constructPathWithNamespace } from '~/analytics/cycle_analytics/utils';
import { LABELS_ENDPOINT, MILESTONES_ENDPOINT } from '~/analytics/cycle_analytics/constants';
import { HTTP_STATUS_FORBIDDEN, HTTP_STATUS_INTERNAL_SERVER_ERROR } from '~/lib/utils/http_status';
import { __ } from '~/locale';
import * as types from './mutation_types';
 
export * from './actions/filters';
export * from './actions/stages';
export * from './actions/value_streams';
 
export const setPaths = ({
  dispatch,
  state: { namespace, groupPath },
  getters: { isProjectNamespace },
}) => {
  const projectPaths = isProjectNamespace
    ? {
        projectEndpoint: namespace.fullPath,
      }
    : {};
 
  return dispatch('filters/setEndpoints', {
    labelsEndpoint: constructPathWithNamespace(namespace, LABELS_ENDPOINT),
    milestonesEndpoint: constructPathWithNamespace(namespace, MILESTONES_ENDPOINT),
    groupEndpoint: groupPath,
    ...projectPaths,
  });
};
 
export const setFeatures = ({ commit }, features) => commit(types.SET_FEATURES, features);
 
export const fetchGroupLabels = ({ commit, getters: { namespacePath } }) => {
  commit(types.REQUEST_GROUP_LABELS);
  return getGroupLabels(namespacePath, { only_group_labels: true })
    .then(({ data = [] }) => commit(types.RECEIVE_GROUP_LABELS_SUCCESS, data))
    .catch(() => commit(types.RECEIVE_GROUP_LABELS_ERROR));
};
 
export const requestCycleAnalyticsData = ({ commit }) => commit(types.REQUEST_VALUE_STREAM_DATA);
 
export const receiveCycleAnalyticsDataSuccess = ({
  commit,
  dispatch,
  state: { enableTasksByTypeChart },
}) => {
  commit(types.RECEIVE_VALUE_STREAM_DATA_SUCCESS);
 
  if (enableTasksByTypeChart) {
    dispatch('typeOfWork/fetchTopRankedGroupLabels');
  }
};
 
export const receiveCycleAnalyticsDataError = ({ commit }, { response = {} }) => {
  const { status = HTTP_STATUS_INTERNAL_SERVER_ERROR } = response;
 
  commit(types.RECEIVE_VALUE_STREAM_DATA_ERROR, status);
  if (status !== HTTP_STATUS_FORBIDDEN) {
    createAlert({
      message: __('There was an error while fetching value stream analytics data.'),
    });
  }
};
 
export const fetchCycleAnalyticsData = ({ dispatch, state: { enableTasksByTypeChart } }) => {
  removeFlash();
 
  return Promise.resolve()
    .then(() => dispatch('requestCycleAnalyticsData'))
    .then(() => dispatch('fetchValueStreams'))
    .then(() => dispatch('receiveCycleAnalyticsDataSuccess'))
    .catch((error) => {
      const promises = [
        dispatch('receiveCycleAnalyticsDataError', error),
        dispatch('durationChart/setLoading', false),
      ];
 
      if (enableTasksByTypeChart) {
        promises.push(dispatch('typeOfWork/setLoading', false));
      }
 
      return Promise.all(promises);
    });
};
 
export const initializeCycleAnalyticsSuccess = ({ commit }) =>
  commit(types.INITIALIZE_VALUE_STREAM_SUCCESS);
 
export const initializeCycleAnalytics = ({ dispatch, commit }, initialData = {}) => {
  commit(types.INITIALIZE_VSA, initialData);
 
  const {
    features = {},
    selectedAuthor,
    selectedMilestone,
    selectedAssigneeList,
    selectedLabelList,
    stage: selectedStage,
    namespace,
    enableTasksByTypeChart,
  } = initialData;
  commit(types.SET_FEATURES, features);
 
  Eif (namespace?.fullPath) {
    let promises = [
      dispatch('setPaths', { namespacePath: namespace.fullPath }),
      dispatch('filters/initialize', {
        selectedAuthor,
        selectedMilestone,
        selectedAssigneeList,
        selectedLabelList,
      }),
      dispatch('durationChart/setLoading', true),
    ];
 
    if (enableTasksByTypeChart) {
      promises = [...promises, dispatch('typeOfWork/setLoading', true)];
    }
 
    if (selectedStage) {
      promises = [dispatch('setSelectedStage', selectedStage), ...promises];
    } else {
      promises = [dispatch('setDefaultSelectedStage'), ...promises];
    }
 
    return Promise.all(promises)
      .then(() =>
        Promise.all([
          selectedStage?.id ? dispatch('fetchStageData', selectedStage.id) : Promise.resolve(),
          dispatch('fetchCycleAnalyticsData'),
        ]),
      )
      .then(() => dispatch('initializeCycleAnalyticsSuccess'));
  }
 
  return dispatch('initializeCycleAnalyticsSuccess');
};