gitlab-org--gitlab-foss/app/assets/javascripts/registry/stores/actions.js

49 lines
1.6 KiB
JavaScript
Raw Normal View History

import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
2017-09-15 09:10:08 -04:00
import * as types from './mutation_types';
import { errorMessages, errorMessagesTypes } from '../constants';
2017-09-15 09:10:08 -04:00
export const fetchRepos = ({ commit, state }) => {
commit(types.TOGGLE_MAIN_LOADING);
return axios
2018-05-28 05:47:59 -04:00
.get(state.endpoint)
.then(({ data }) => {
2017-09-15 09:10:08 -04:00
commit(types.TOGGLE_MAIN_LOADING);
commit(types.SET_REPOS_LIST, data);
})
.catch(() => {
commit(types.TOGGLE_MAIN_LOADING);
createFlash(errorMessages[errorMessagesTypes.FETCH_REPOS]);
2017-09-15 09:10:08 -04:00
});
};
2017-09-22 06:46:55 -04:00
export const fetchList = ({ commit }, { repo, page }) => {
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
2017-09-15 09:10:08 -04:00
return axios
.get(repo.tagsPath, { params: { page } })
.then(response => {
const { headers, data } = response;
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
commit(types.SET_REGISTRY_LIST, { repo, resp: data, headers });
})
.catch(() => {
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
createFlash(errorMessages[errorMessagesTypes.FETCH_REGISTRY]);
});
2017-09-15 09:10:08 -04:00
};
2018-05-28 05:53:00 -04:00
// eslint-disable-next-line no-unused-vars
export const deleteRepo = ({ commit }, repo) => axios.delete(repo.destroyPath);
2017-09-15 09:10:08 -04:00
2018-05-28 05:53:00 -04:00
// eslint-disable-next-line no-unused-vars
export const deleteRegistry = ({ commit }, image) => axios.delete(image.destroyPath);
export const setMainEndpoint = ({ commit }, data) => commit(types.SET_MAIN_ENDPOINT, data);
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_MAIN_LOADING);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};