All files / app/assets/javascripts/user_lists/store/index mutations.js

94.74% Statements 18/19
40% Branches 2/5
88.89% Functions 8/9
100% Lines 17/17

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          14x     14x     14x 14x 14x   14x 14x 14x 14x     4x 4x     1x     2x 2x 2x 2x     2x      
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import * as types from './mutation_types';
 
export default {
  [types.SET_USER_LISTS_OPTIONS](state, options = {}) {
    state.options = options;
  },
  [types.REQUEST_USER_LISTS](state) {
    state.isLoading = true;
  },
  [types.RECEIVE_USER_LISTS_SUCCESS](state, { data, headers }) {
    state.isLoading = false;
    state.hasError = false;
    state.userLists = data || [];
 
    const normalizedHeaders = normalizeHeaders(headers);
    const paginationInfo = parseIntPagination(normalizedHeaders);
    state.count = paginationInfo?.total ?? state.userLists.length;
    state.pageInfo = paginationInfo;
  },
  [types.RECEIVE_USER_LISTS_ERROR](state) {
    state.isLoading = false;
    state.hasError = true;
  },
  [types.REQUEST_DELETE_USER_LIST](state, list) {
    state.userLists = state.userLists.filter((l) => l !== list);
  },
  [types.RECEIVE_DELETE_USER_LIST_ERROR](state, { error, list }) {
    state.isLoading = false;
    state.hasError = false;
    state.alerts = [].concat(error.message);
    state.userLists = state.userLists.concat(list).sort((l1, l2) => l1.iid - l2.iid);
  },
  [types.RECEIVE_CLEAR_ALERT](state, index) {
    state.alerts.splice(index, 1);
  },
};