All files / ee/app/assets/javascripts/analytics/cycle_analytics/store/modules/type_of_work mutations.js

96.55% Statements 28/29
75% Branches 6/8
100% Functions 8/8
96.55% Lines 28/29

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              103x 103x     89x 89x 89x 89x 89x     87x 87x 87x 87x 87x     3x 3x 3x 3x 3x 3x     85x     2x     85x 85x     3x 3x   2x 2x     1x 1x              
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { TASKS_BY_TYPE_FILTERS } from '../../../constants';
import { transformRawTasksByTypeData, toggleSelectedLabel } from '../../../utils';
import * as types from './mutation_types';
 
export default {
  [types.SET_LOADING](state, loading) {
    state.isLoadingTasksByTypeChartTopLabels = loading;
    state.isLoadingTasksByTypeChart = loading;
  },
  [types.REQUEST_TOP_RANKED_GROUP_LABELS](state) {
    state.isLoadingTasksByTypeChartTopLabels = true;
    state.topRankedLabels = [];
    state.selectedLabels = [];
    state.errorCode = null;
    state.errorMessage = '';
  },
  [types.RECEIVE_TOP_RANKED_GROUP_LABELS_SUCCESS](state, data = []) {
    state.isLoadingTasksByTypeChartTopLabels = false;
    state.topRankedLabels = data.map(convertObjectPropsToCamelCase);
    state.selectedLabels = data.map(convertObjectPropsToCamelCase);
    state.errorCode = null;
    state.errorMessage = '';
  },
  [types.RECEIVE_TOP_RANKED_GROUP_LABELS_ERROR](state, { errorCode = null, message = '' } = {}) {
    state.isLoadingTasksByTypeChartTopLabels = false;
    state.isLoadingTasksByTypeChart = false;
    state.topRankedLabels = [];
    state.selectedLabels = [];
    state.errorCode = errorCode;
    state.errorMessage = message;
  },
  [types.REQUEST_TASKS_BY_TYPE_DATA](state) {
    state.isLoadingTasksByTypeChart = true;
  },
  [types.RECEIVE_TASKS_BY_TYPE_DATA_ERROR](state) {
    state.isLoadingTasksByTypeChart = false;
  },
  [types.RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS](state, data = []) {
    state.isLoadingTasksByTypeChart = false;
    state.data = transformRawTasksByTypeData(data);
  },
  [types.SET_TASKS_BY_TYPE_FILTERS](state, { filter, value }) {
    const { selectedLabels } = state;
    switch (filter) {
      case TASKS_BY_TYPE_FILTERS.LABEL: {
        state.selectedLabels = toggleSelectedLabel({ selectedLabels, value });
        break;
      }
      case TASKS_BY_TYPE_FILTERS.SUBJECT: {
        state.subject = value;
        break;
      }
      default:
        break;
    }
  },
};