2021-04-17 20:07:23 +05:30
|
|
|
import sidebarDetailsIssueQuery from 'ee_else_ce/sidebar/queries/sidebarDetails.query.graphql';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { TYPE_USER } from '~/graphql_shared/constants';
|
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';
|
2021-12-11 22:18:48 +05:30
|
|
|
import toggleAttentionRequestedMutation from '../queries/toggle_attention_requested.mutation.graphql';
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
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.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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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: {
|
2021-09-30 23:02:18 +05:30
|
|
|
userId: convertToGraphQLId(TYPE_USER, `${userId}`),
|
2021-03-11 19:13:27 +05:30
|
|
|
projectPath: this.fullPath,
|
|
|
|
iid: this.iid.toString(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
toggleAttentionRequested(userId) {
|
|
|
|
return gqClient.mutate({
|
|
|
|
mutation: toggleAttentionRequestedMutation,
|
|
|
|
variables: {
|
|
|
|
userId: convertToGraphQLId(TYPE_USER, `${userId}`),
|
|
|
|
projectPath: this.fullPath,
|
|
|
|
iid: this.iid.toString(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|