Welcome to mirror list, hosted at ThFree Co, Russian Federation.

actions.js « store « settings « registry « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d0379d0516466972ebe96455b81fb0ed26b7607f (plain)
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
import Api from '~/api';
import * as types from './mutation_types';

export const setInitialState = ({ commit }, data) => commit(types.SET_INITIAL_STATE, data);
export const updateSettings = ({ commit }, data) => commit(types.UPDATE_SETTINGS, data);
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_LOADING);
export const receiveSettingsSuccess = ({ commit }, data) => {
  if (data) {
    commit(types.SET_SETTINGS, data);
  } else {
    commit(types.SET_IS_DISABLED, true);
  }
};
export const resetSettings = ({ commit }) => commit(types.RESET_SETTINGS);

export const fetchSettings = ({ dispatch, state }) => {
  dispatch('toggleLoading');
  return Api.project(state.projectId)
    .then(({ data: { container_expiration_policy } }) =>
      dispatch('receiveSettingsSuccess', container_expiration_policy),
    )
    .finally(() => dispatch('toggleLoading'));
};

export const saveSettings = ({ dispatch, state }) => {
  dispatch('toggleLoading');
  return Api.updateProject(state.projectId, {
    container_expiration_policy_attributes: state.settings,
  })
    .then(({ data: { container_expiration_policy } }) =>
      dispatch('receiveSettingsSuccess', container_expiration_policy),
    )
    .finally(() => dispatch('toggleLoading'));
};

// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};