All files / app/assets/javascripts/deploy_freeze/store mutations.js

71.88% Statements 23/32
50% Branches 2/4
68.42% Functions 13/19
75.86% Lines 22/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 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          5x 1194x 18x                 5x                       2x       6x 6x 18x         2x       2x       2x 2x       1x 1x       1x       1x       1x                               3x 3x 3x 3x 3x      
import Vue from 'vue';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { secondsToHours } from '~/lib/utils/datetime_utility';
import * as types from './mutation_types';
 
const formatTimezoneName = (freezePeriod, timezoneList) => {
  const tz = timezoneList.find((timezone) => timezone.identifier === freezePeriod.cron_timezone);
  return convertObjectPropsToCamelCase({
    ...freezePeriod,
    cron_timezone: {
      formattedTimezone: tz && `[UTC ${secondsToHours(tz.offset)}] ${tz.name}`,
      identifier: freezePeriod.cron_timezone,
    },
  });
};
 
const setFreezePeriodIsDeleting = (state, id, isDeleting) => {
  const freezePeriod = state.freezePeriods.find((f) => f.id === id);
 
  if (!freezePeriod) {
    return;
  }
 
  Vue.set(freezePeriod, 'isDeleting', isDeleting);
};
 
export default {
  [types.REQUEST_FREEZE_PERIODS](state) {
    state.isLoading = true;
  },
 
  [types.RECEIVE_FREEZE_PERIODS_SUCCESS](state, freezePeriods) {
    state.isLoading = false;
    state.freezePeriods = freezePeriods.map((freezePeriod) =>
      formatTimezoneName(freezePeriod, state.timezoneData),
    );
  },
 
  [types.REQUEST_ADD_FREEZE_PERIOD](state) {
    state.isLoading = true;
  },
 
  [types.RECEIVE_ADD_FREEZE_PERIOD_SUCCESS](state) {
    state.isLoading = false;
  },
 
  [types.RECEIVE_ADD_FREEZE_PERIOD_ERROR](state, error) {
    state.isLoading = false;
    state.error = error;
  },
 
  [types.SET_SELECTED_TIMEZONE](state, timezone) {
    state.selectedTimezone = timezone.formattedTimezone;
    state.selectedTimezoneIdentifier = timezone.identifier;
  },
 
  [types.SET_FREEZE_START_CRON](state, freezeStartCron) {
    state.freezeStartCron = freezeStartCron;
  },
 
  [types.SET_FREEZE_END_CRON](state, freezeEndCron) {
    state.freezeEndCron = freezeEndCron;
  },
 
  [types.SET_SELECTED_ID](state, id) {
    state.selectedId = id;
  },
 
  [types.REQUEST_DELETE_FREEZE_PERIOD](state, id) {
    setFreezePeriodIsDeleting(state, id, true);
  },
 
  [types.RECEIVE_DELETE_FREEZE_PERIOD_SUCCESS](state, id) {
    state.freezePeriods = state.freezePeriods.filter((f) => f.id !== id);
  },
 
  [types.RECEIVE_DELETE_FREEZE_PERIOD_ERROR](state, id) {
    setFreezePeriodIsDeleting(state, id, false);
  },
 
  [types.RESET_MODAL](state) {
    state.freezeStartCron = '';
    state.freezeEndCron = '';
    state.selectedTimezone = '';
    state.selectedTimezoneIdentifier = '';
    state.selectedId = '';
  },
};