debian-mirror-gitlab/app/assets/javascripts/ref/stores/actions.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-07-28 23:09:34 +05:30
import Api from '~/api';
2021-04-17 20:07:23 +05:30
import { REF_TYPE_BRANCHES, REF_TYPE_TAGS, REF_TYPE_COMMITS } from '../constants';
2020-07-28 23:09:34 +05:30
import * as types from './mutation_types';
2021-04-17 20:07:23 +05:30
export const setEnabledRefTypes = ({ commit }, refTypes) =>
commit(types.SET_ENABLED_REF_TYPES, refTypes);
2022-05-07 20:08:51 +05:30
export const setUseSymbolicRefNames = ({ commit }, useSymbolicRefNames) =>
commit(types.SET_USE_SYMBOLIC_REF_NAMES, useSymbolicRefNames);
2020-07-28 23:09:34 +05:30
export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId);
export const setSelectedRef = ({ commit }, selectedRef) =>
commit(types.SET_SELECTED_REF, selectedRef);
2021-04-17 20:07:23 +05:30
export const search = ({ state, dispatch, commit }, query) => {
2020-07-28 23:09:34 +05:30
commit(types.SET_QUERY, query);
2021-04-17 20:07:23 +05:30
const dispatchIfRefTypeEnabled = (refType, action) => {
if (state.enabledRefTypes.includes(refType)) {
dispatch(action);
}
};
dispatchIfRefTypeEnabled(REF_TYPE_BRANCHES, 'searchBranches');
dispatchIfRefTypeEnabled(REF_TYPE_TAGS, 'searchTags');
dispatchIfRefTypeEnabled(REF_TYPE_COMMITS, 'searchCommits');
2020-07-28 23:09:34 +05:30
};
export const searchBranches = ({ commit, state }) => {
commit(types.REQUEST_START);
Api.branches(state.projectId, state.query)
2021-03-08 18:12:59 +05:30
.then((response) => {
2020-07-28 23:09:34 +05:30
commit(types.RECEIVE_BRANCHES_SUCCESS, response);
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2020-07-28 23:09:34 +05:30
commit(types.RECEIVE_BRANCHES_ERROR, error);
})
.finally(() => {
commit(types.REQUEST_FINISH);
});
};
export const searchTags = ({ commit, state }) => {
commit(types.REQUEST_START);
Api.tags(state.projectId, state.query)
2021-03-08 18:12:59 +05:30
.then((response) => {
2020-07-28 23:09:34 +05:30
commit(types.RECEIVE_TAGS_SUCCESS, response);
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2020-07-28 23:09:34 +05:30
commit(types.RECEIVE_TAGS_ERROR, error);
})
.finally(() => {
commit(types.REQUEST_FINISH);
});
};
export const searchCommits = ({ commit, state, getters }) => {
// Only query the Commit API if the search query looks like a commit SHA
if (getters.isQueryPossiblyASha) {
commit(types.REQUEST_START);
Api.commit(state.projectId, state.query)
2021-03-08 18:12:59 +05:30
.then((response) => {
2020-07-28 23:09:34 +05:30
commit(types.RECEIVE_COMMITS_SUCCESS, response);
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2020-07-28 23:09:34 +05:30
commit(types.RECEIVE_COMMITS_ERROR, error);
})
.finally(() => {
commit(types.REQUEST_FINISH);
});
} else {
commit(types.RESET_COMMIT_MATCHES);
}
};