debian-mirror-gitlab/app/assets/javascripts/search/store/actions.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import Api from '~/api';
import createFlash from '~/flash';
import { visitUrl, setUrlParams } from '~/lib/utils/url_utility';
2021-03-11 19:13:27 +05:30
import { __ } from '~/locale';
2021-01-29 00:20:46 +05:30
import * as types from './mutation_types';
export const fetchGroups = ({ commit }, search) => {
commit(types.REQUEST_GROUPS);
Api.groups(search)
2021-03-08 18:12:59 +05:30
.then((data) => {
2021-01-29 00:20:46 +05:30
commit(types.RECEIVE_GROUPS_SUCCESS, data);
})
.catch(() => {
createFlash({ message: __('There was a problem fetching groups.') });
commit(types.RECEIVE_GROUPS_ERROR);
});
};
2021-02-22 17:27:13 +05:30
export const fetchProjects = ({ commit, state }, search) => {
commit(types.REQUEST_PROJECTS);
const groupId = state.query?.group_id;
2021-03-08 18:12:59 +05:30
const callback = (data) => {
2021-02-22 17:27:13 +05:30
if (data) {
commit(types.RECEIVE_PROJECTS_SUCCESS, data);
} else {
createFlash({ message: __('There was an error fetching projects') });
commit(types.RECEIVE_PROJECTS_ERROR);
}
};
if (groupId) {
2021-09-04 01:27:46 +05:30
// TODO (https://gitlab.com/gitlab-org/gitlab/-/issues/323331): For errors `createFlash` is called twice; in `callback` and in `Api.groupProjects`
2021-02-22 17:27:13 +05:30
Api.groupProjects(groupId, search, {}, callback);
} else {
// The .catch() is due to the API method not handling a rejection properly
Api.projects(search, { order_by: 'id' }, callback).catch(() => {
callback();
});
}
};
2021-01-29 00:20:46 +05:30
export const setQuery = ({ commit }, { key, value }) => {
commit(types.SET_QUERY, { key, value });
};
export const applyQuery = ({ state }) => {
visitUrl(setUrlParams({ ...state.query, page: null }));
};
export const resetQuery = ({ state }) => {
visitUrl(setUrlParams({ ...state.query, page: null, state: null, confidential: null }));
};