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

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

100 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-07-28 23:09:34 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import httpStatusCodes from '~/lib/utils/http_status';
2021-03-11 19:13:27 +05:30
import { X_TOTAL_HEADER } from '../constants';
import * as types from './mutation_types';
2020-07-28 23:09:34 +05:30
export default {
2021-04-17 20:07:23 +05:30
[types.SET_ENABLED_REF_TYPES](state, refTypes) {
state.enabledRefTypes = refTypes;
},
2022-05-07 20:08:51 +05:30
[types.SET_USE_SYMBOLIC_REF_NAMES](state, useSymbolicRefNames) {
state.useSymbolicRefNames = useSymbolicRefNames;
},
2020-07-28 23:09:34 +05:30
[types.SET_PROJECT_ID](state, projectId) {
state.projectId = projectId;
},
[types.SET_SELECTED_REF](state, selectedRef) {
state.selectedRef = selectedRef;
},
[types.SET_QUERY](state, query) {
state.query = query;
},
[types.REQUEST_START](state) {
state.requestCount += 1;
},
[types.REQUEST_FINISH](state) {
state.requestCount -= 1;
},
[types.RECEIVE_BRANCHES_SUCCESS](state, response) {
state.matches.branches = {
2021-03-08 18:12:59 +05:30
list: convertObjectPropsToCamelCase(response.data).map((b) => ({
2020-07-28 23:09:34 +05:30
name: b.name,
2022-05-07 20:08:51 +05:30
value: state.useSymbolicRefNames ? `refs/heads/${b.name}` : undefined,
2020-07-28 23:09:34 +05:30
default: b.default,
})),
totalCount: parseInt(response.headers[X_TOTAL_HEADER], 10),
error: null,
};
},
[types.RECEIVE_BRANCHES_ERROR](state, error) {
state.matches.branches = {
list: [],
totalCount: 0,
error,
};
},
[types.RECEIVE_TAGS_SUCCESS](state, response) {
state.matches.tags = {
2021-03-08 18:12:59 +05:30
list: convertObjectPropsToCamelCase(response.data).map((b) => ({
2020-07-28 23:09:34 +05:30
name: b.name,
2022-05-07 20:08:51 +05:30
value: state.useSymbolicRefNames ? `refs/tags/${b.name}` : undefined,
2020-07-28 23:09:34 +05:30
})),
totalCount: parseInt(response.headers[X_TOTAL_HEADER], 10),
error: null,
};
},
[types.RECEIVE_TAGS_ERROR](state, error) {
state.matches.tags = {
list: [],
totalCount: 0,
error,
};
},
[types.RECEIVE_COMMITS_SUCCESS](state, response) {
const commit = convertObjectPropsToCamelCase(response.data);
state.matches.commits = {
list: [
{
name: commit.shortId,
value: commit.id,
subtitle: commit.title,
},
],
totalCount: 1,
error: null,
};
},
[types.RECEIVE_COMMITS_ERROR](state, error) {
state.matches.commits = {
list: [],
totalCount: 0,
// 404's are expected when the search query doesn't match any commits
// and shouldn't be treated as an actual error
error: error.response?.status !== httpStatusCodes.NOT_FOUND ? error : null,
};
},
[types.RESET_COMMIT_MATCHES](state) {
state.matches.commits = {
list: [],
totalCount: 0,
error: null,
};
},
};