debian-mirror-gitlab/app/assets/javascripts/sidebar/services/sidebar_service.js

98 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-04-17 20:07:23 +05:30
import sidebarDetailsIssueQuery from 'ee_else_ce/sidebar/queries/sidebarDetails.query.graphql';
2021-03-11 19:13:27 +05:30
import { convertToGraphQLId } from '~/graphql_shared/utils';
2020-10-24 23:57:45 +05:30
import createGqClient, { fetchPolicies } from '~/lib/graphql';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
import reviewerRereviewMutation from '../queries/reviewer_rereview.mutation.graphql';
2021-04-17 20:07:23 +05:30
import sidebarDetailsMRQuery from '../queries/sidebarDetailsMR.query.graphql';
const queries = {
merge_request: sidebarDetailsMRQuery,
issue: sidebarDetailsIssueQuery,
};
2020-04-08 14:13:33 +05:30
export const gqClient = createGqClient(
{},
{
fetchPolicy: fetchPolicies.NO_CACHE,
},
);
2017-08-17 22:00:37 +05:30
export default class SidebarService {
2018-03-17 18:26:18 +05:30
constructor(endpointMap) {
2017-08-17 22:00:37 +05:30
if (!SidebarService.singleton) {
2018-03-17 18:26:18 +05:30
this.endpoint = endpointMap.endpoint;
this.toggleSubscriptionEndpoint = endpointMap.toggleSubscriptionEndpoint;
this.moveIssueEndpoint = endpointMap.moveIssueEndpoint;
this.projectsAutocompleteEndpoint = endpointMap.projectsAutocompleteEndpoint;
2020-04-08 14:13:33 +05:30
this.fullPath = endpointMap.fullPath;
this.iid = endpointMap.iid;
2021-04-17 20:07:23 +05:30
this.issuableType = endpointMap.issuableType;
2017-08-17 22:00:37 +05:30
SidebarService.singleton = this;
}
return SidebarService.singleton;
}
get() {
2020-04-08 14:13:33 +05:30
return Promise.all([
axios.get(this.endpoint),
gqClient.query({
2021-04-17 20:07:23 +05:30
query: this.sidebarDetailsQuery(),
2020-04-08 14:13:33 +05:30
variables: {
fullPath: this.fullPath,
iid: this.iid.toString(),
},
}),
]);
2017-08-17 22:00:37 +05:30
}
2021-04-17 20:07:23 +05:30
sidebarDetailsQuery() {
return queries[this.issuableType];
}
2017-08-17 22:00:37 +05:30
update(key, data) {
2019-12-04 20:38:33 +05:30
return axios.put(this.endpoint, { [key]: data });
2017-08-17 22:00:37 +05:30
}
2018-03-17 18:26:18 +05:30
2020-04-08 14:13:33 +05:30
updateWithGraphQl(mutation, variables) {
return gqClient.mutate({
mutation,
variables: {
...variables,
projectPath: this.fullPath,
iid: this.iid.toString(),
},
});
}
2018-03-17 18:26:18 +05:30
getProjectsAutocomplete(searchTerm) {
2019-12-04 20:38:33 +05:30
return axios.get(this.projectsAutocompleteEndpoint, {
2018-03-17 18:26:18 +05:30
params: {
search: searchTerm,
},
});
}
toggleSubscription() {
2019-12-04 20:38:33 +05:30
return axios.post(this.toggleSubscriptionEndpoint);
2018-03-17 18:26:18 +05:30
}
moveIssue(moveToProjectId) {
2019-12-04 20:38:33 +05:30
return axios.post(this.moveIssueEndpoint, {
2018-03-17 18:26:18 +05:30
move_to_project_id: moveToProjectId,
});
}
2021-03-11 19:13:27 +05:30
requestReview(userId) {
return gqClient.mutate({
mutation: reviewerRereviewMutation,
variables: {
userId: convertToGraphQLId('User', `${userId}`), // eslint-disable-line @gitlab/require-i18n-strings
projectPath: this.fullPath,
iid: this.iid.toString(),
},
});
}
2017-08-17 22:00:37 +05:30
}