2021-10-12 15:12:08 +00:00
|
|
|
import Vue from 'vue';
|
2021-06-11 15:09:58 +00:00
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2021-10-12 15:12:08 +00:00
|
|
|
import { PAGINATION_SORT_FIELD_END_EVENT, PAGINATION_SORT_DIRECTION_DESC } from '../constants';
|
2021-09-07 15:11:06 +00:00
|
|
|
import { formatMedianValues } from '../utils';
|
2021-04-21 09:09:15 +00:00
|
|
|
import * as types from './mutation_types';
|
|
|
|
|
|
|
|
export default {
|
2021-10-12 15:12:08 +00:00
|
|
|
[types.INITIALIZE_VSA](
|
|
|
|
state,
|
|
|
|
{ endpoints, features, createdBefore, createdAfter, pagination = {} },
|
|
|
|
) {
|
2021-08-04 18:09:57 +00:00
|
|
|
state.endpoints = endpoints;
|
2021-09-07 15:11:06 +00:00
|
|
|
state.createdBefore = createdBefore;
|
|
|
|
state.createdAfter = createdAfter;
|
2021-08-16 12:09:17 +00:00
|
|
|
state.features = features;
|
2021-10-12 15:12:08 +00:00
|
|
|
|
|
|
|
Vue.set(state, 'pagination', {
|
|
|
|
page: pagination.page ?? state.pagination.page,
|
|
|
|
sort: pagination.sort ?? state.pagination.sort,
|
|
|
|
direction: pagination.direction ?? state.pagination.direction,
|
|
|
|
});
|
2021-06-11 15:09:58 +00:00
|
|
|
},
|
|
|
|
[types.SET_LOADING](state, loadingState) {
|
|
|
|
state.isLoading = loadingState;
|
|
|
|
},
|
|
|
|
[types.SET_SELECTED_VALUE_STREAM](state, selectedValueStream = {}) {
|
|
|
|
state.selectedValueStream = convertObjectPropsToCamelCase(selectedValueStream, { deep: true });
|
2021-04-21 09:09:15 +00:00
|
|
|
},
|
|
|
|
[types.SET_SELECTED_STAGE](state, stage) {
|
|
|
|
state.selectedStage = stage;
|
|
|
|
},
|
2021-09-07 15:11:06 +00:00
|
|
|
[types.SET_DATE_RANGE](state, { createdAfter, createdBefore }) {
|
|
|
|
state.createdBefore = createdBefore;
|
|
|
|
state.createdAfter = createdAfter;
|
2021-04-21 09:09:15 +00:00
|
|
|
},
|
2021-10-12 15:12:08 +00:00
|
|
|
[types.SET_PAGINATION](state, { page, hasNextPage, sort, direction }) {
|
|
|
|
Vue.set(state, 'pagination', {
|
|
|
|
page,
|
|
|
|
hasNextPage,
|
|
|
|
sort: sort || PAGINATION_SORT_FIELD_END_EVENT,
|
|
|
|
direction: direction || PAGINATION_SORT_DIRECTION_DESC,
|
|
|
|
});
|
|
|
|
},
|
2022-08-09 03:11:51 +00:00
|
|
|
[types.SET_NO_ACCESS_ERROR](state) {
|
|
|
|
state.hasNoAccessError = true;
|
|
|
|
},
|
2021-06-11 15:09:58 +00:00
|
|
|
[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-07-20 09:08:43 +00:00
|
|
|
state.stages = stages.map((s) => convertObjectPropsToCamelCase(s, { deep: true }));
|
2021-06-11 15:09:58 +00:00
|
|
|
},
|
|
|
|
[types.RECEIVE_VALUE_STREAM_STAGES_ERROR](state) {
|
|
|
|
state.stages = [];
|
|
|
|
},
|
2021-04-21 09:09:15 +00:00
|
|
|
[types.REQUEST_STAGE_DATA](state) {
|
|
|
|
state.isLoadingStage = true;
|
|
|
|
state.isEmptyStage = false;
|
|
|
|
state.selectedStageEvents = [];
|
2022-08-09 03:11:51 +00:00
|
|
|
|
|
|
|
state.hasNoAccessError = false;
|
2021-04-21 09:09:15 +00:00
|
|
|
},
|
2021-08-04 18:09:57 +00:00
|
|
|
[types.RECEIVE_STAGE_DATA_SUCCESS](state, events = []) {
|
2021-04-21 09:09:15 +00:00
|
|
|
state.isLoadingStage = false;
|
|
|
|
state.isEmptyStage = !events.length;
|
2021-07-22 09:08:22 +00:00
|
|
|
state.selectedStageEvents = events.map((ev) =>
|
|
|
|
convertObjectPropsToCamelCase(ev, { deep: true }),
|
|
|
|
);
|
2022-08-09 03:11:51 +00:00
|
|
|
|
|
|
|
state.hasNoAccessError = false;
|
2021-04-21 09:09:15 +00:00
|
|
|
},
|
2021-06-07 09:10:26 +00:00
|
|
|
[types.RECEIVE_STAGE_DATA_ERROR](state, error) {
|
2021-04-21 09:09:15 +00:00
|
|
|
state.isLoadingStage = false;
|
|
|
|
state.isEmptyStage = true;
|
|
|
|
state.selectedStageEvents = [];
|
2022-08-09 03:11:51 +00:00
|
|
|
|
2021-06-07 09:10:26 +00:00
|
|
|
state.selectedStageError = error;
|
2021-04-21 09:09:15 +00:00
|
|
|
},
|
2021-07-15 18:09:37 +00:00
|
|
|
[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-08-06 18:09:57 +00:00
|
|
|
[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-04-21 09:09:15 +00:00
|
|
|
};
|