debian-mirror-gitlab/app/assets/javascripts/cycle_analytics/store/mutations.js

105 lines
3.3 KiB
JavaScript
Raw Normal View History

2021-09-04 01:27:46 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2021-09-30 23:02:18 +05:30
import { DEFAULT_DAYS_TO_DISPLAY } from '../constants';
2021-10-27 15:23:28 +05:30
import { formatMedianValues, calculateFormattedDayInPast } from '../utils';
2021-06-08 01:23:25 +05:30
import * as types from './mutation_types';
export default {
2021-10-27 15:23:28 +05:30
[types.INITIALIZE_VSA](state, { endpoints, features }) {
state.endpoints = endpoints;
2021-09-30 23:02:18 +05:30
const { now, past } = calculateFormattedDayInPast(DEFAULT_DAYS_TO_DISPLAY);
state.createdBefore = now;
state.createdAfter = past;
state.features = features;
2021-09-04 01:27:46 +05:30
},
[types.SET_LOADING](state, loadingState) {
state.isLoading = loadingState;
},
[types.SET_SELECTED_VALUE_STREAM](state, selectedValueStream = {}) {
state.selectedValueStream = convertObjectPropsToCamelCase(selectedValueStream, { deep: true });
2021-06-08 01:23:25 +05:30
},
[types.SET_SELECTED_STAGE](state, stage) {
state.selectedStage = stage;
},
2021-10-27 15:23:28 +05:30
[types.SET_DATE_RANGE](state, daysInPast) {
state.daysInPast = daysInPast;
const { now, past } = calculateFormattedDayInPast(daysInPast);
2021-09-30 23:02:18 +05:30
state.createdBefore = now;
state.createdAfter = past;
2021-06-08 01:23:25 +05:30
},
2021-09-04 01:27:46 +05:30
[types.REQUEST_VALUE_STREAMS](state) {
state.valueStreams = [];
},
[types.RECEIVE_VALUE_STREAMS_SUCCESS](state, valueStreams = []) {
state.valueStreams = valueStreams;
},
[types.RECEIVE_VALUE_STREAMS_ERROR](state) {
state.valueStreams = [];
},
[types.REQUEST_VALUE_STREAM_STAGES](state) {
state.stages = [];
},
[types.RECEIVE_VALUE_STREAM_STAGES_SUCCESS](state, { stages = [] }) {
2021-10-27 15:23:28 +05:30
state.stages = stages.map((s) => convertObjectPropsToCamelCase(s, { deep: true }));
2021-09-04 01:27:46 +05:30
},
[types.RECEIVE_VALUE_STREAM_STAGES_ERROR](state) {
state.stages = [];
},
2021-06-08 01:23:25 +05:30
[types.REQUEST_CYCLE_ANALYTICS_DATA](state) {
state.isLoading = true;
state.hasError = false;
},
[types.RECEIVE_CYCLE_ANALYTICS_DATA_SUCCESS](state, data) {
2021-10-27 15:23:28 +05:30
state.permissions = data?.permissions || {};
2021-06-08 01:23:25 +05:30
state.hasError = false;
},
[types.RECEIVE_CYCLE_ANALYTICS_DATA_ERROR](state) {
state.isLoading = false;
state.hasError = true;
},
[types.REQUEST_STAGE_DATA](state) {
state.isLoadingStage = true;
state.isEmptyStage = false;
state.selectedStageEvents = [];
state.hasError = false;
},
2021-10-27 15:23:28 +05:30
[types.RECEIVE_STAGE_DATA_SUCCESS](state, events = []) {
2021-06-08 01:23:25 +05:30
state.isLoadingStage = false;
state.isEmptyStage = !events.length;
2021-10-27 15:23:28 +05:30
state.selectedStageEvents = events.map((ev) =>
convertObjectPropsToCamelCase(ev, { deep: true }),
);
2021-06-08 01:23:25 +05:30
state.hasError = false;
},
2021-09-04 01:27:46 +05:30
[types.RECEIVE_STAGE_DATA_ERROR](state, error) {
2021-06-08 01:23:25 +05:30
state.isLoadingStage = false;
state.isEmptyStage = true;
state.selectedStageEvents = [];
state.hasError = true;
2021-09-04 01:27:46 +05:30
state.selectedStageError = error;
2021-06-08 01:23:25 +05:30
},
2021-09-30 23:02:18 +05:30
[types.REQUEST_STAGE_MEDIANS](state) {
state.medians = {};
},
[types.RECEIVE_STAGE_MEDIANS_SUCCESS](state, medians) {
state.medians = formatMedianValues(medians);
},
[types.RECEIVE_STAGE_MEDIANS_ERROR](state) {
state.medians = {};
},
2021-10-27 15:23:28 +05:30
[types.REQUEST_STAGE_COUNTS](state) {
state.stageCounts = {};
},
[types.RECEIVE_STAGE_COUNTS_SUCCESS](state, stageCounts = []) {
state.stageCounts = stageCounts.reduce(
(acc, { id, count }) => ({
...acc,
[id]: count,
}),
{},
);
},
[types.RECEIVE_STAGE_COUNTS_ERROR](state) {
state.stageCounts = {};
},
2021-06-08 01:23:25 +05:30
};