diff options
Diffstat (limited to 'app/assets/javascripts/deploy_freeze/store')
3 files changed, 49 insertions, 4 deletions
diff --git a/app/assets/javascripts/deploy_freeze/store/actions.js b/app/assets/javascripts/deploy_freeze/store/actions.js index fed80b46eda..1ac6781a0e3 100644 --- a/app/assets/javascripts/deploy_freeze/store/actions.js +++ b/app/assets/javascripts/deploy_freeze/store/actions.js @@ -1,5 +1,6 @@ import Api from '~/api'; import createFlash from '~/flash'; +import { logError } from '~/lib/logger'; import { __ } from '~/locale'; import * as types from './mutation_types'; @@ -52,6 +53,21 @@ export const updateFreezePeriod = (store) => }), ); +export const deleteFreezePeriod = ({ state, commit }, { id }) => { + commit(types.REQUEST_DELETE_FREEZE_PERIOD, id); + + return Api.deleteFreezePeriod(state.projectId, id) + .then(() => commit(types.RECEIVE_DELETE_FREEZE_PERIOD_SUCCESS, id)) + .catch((e) => { + createFlash({ + message: __('Error: Unable to delete deploy freeze'), + }); + commit(types.RECEIVE_DELETE_FREEZE_PERIOD_ERROR, id); + + logError(`Unable to delete deploy freeze`, e); + }); +}; + export const fetchFreezePeriods = ({ commit, state }) => { commit(types.REQUEST_FREEZE_PERIODS); diff --git a/app/assets/javascripts/deploy_freeze/store/mutation_types.js b/app/assets/javascripts/deploy_freeze/store/mutation_types.js index 8e6fdfd4443..0fec96e2e4c 100644 --- a/app/assets/javascripts/deploy_freeze/store/mutation_types.js +++ b/app/assets/javascripts/deploy_freeze/store/mutation_types.js @@ -10,4 +10,8 @@ export const SET_SELECTED_ID = 'SET_SELECTED_ID'; export const SET_FREEZE_START_CRON = 'SET_FREEZE_START_CRON'; export const SET_FREEZE_END_CRON = 'SET_FREEZE_END_CRON'; +export const REQUEST_DELETE_FREEZE_PERIOD = 'REQUEST_DELETE_FREEZE_PERIOD'; +export const RECEIVE_DELETE_FREEZE_PERIOD_SUCCESS = 'RECEIVE_DELETE_FREEZE_PERIOD_SUCCESS'; +export const RECEIVE_DELETE_FREEZE_PERIOD_ERROR = 'RECEIVE_DELETE_FREEZE_PERIOD_ERROR'; + export const RESET_MODAL = 'RESET_MODAL'; diff --git a/app/assets/javascripts/deploy_freeze/store/mutations.js b/app/assets/javascripts/deploy_freeze/store/mutations.js index fdd1ea6e32e..151f7f39f5a 100644 --- a/app/assets/javascripts/deploy_freeze/store/mutations.js +++ b/app/assets/javascripts/deploy_freeze/store/mutations.js @@ -1,15 +1,28 @@ +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) => - convertObjectPropsToCamelCase({ +const formatTimezoneName = (freezePeriod, timezoneList) => { + const tz = timezoneList.find((timezone) => timezone.identifier === freezePeriod.cron_timezone); + return convertObjectPropsToCamelCase({ ...freezePeriod, cron_timezone: { - formattedTimezone: timezoneList.find((tz) => tz.identifier === freezePeriod.cron_timezone) - ?.name, + 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) { @@ -53,6 +66,18 @@ export default { 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 = ''; |