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

79 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-12-04 20:38:33 +05:30
import axios from '~/lib/utils/axios_utils';
2020-04-08 14:13:33 +05:30
import createGqClient, { fetchPolicies } from '~/lib/graphql';
import sidebarDetailsQuery from 'ee_else_ce/sidebar/queries/sidebarDetails.query.graphql';
import sidebarDetailsForHealthStatusFeatureFlagQuery from 'ee_else_ce/sidebar/queries/sidebarDetailsForHealthStatusFeatureFlag.query.graphql';
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;
2017-08-17 22:00:37 +05:30
SidebarService.singleton = this;
}
return SidebarService.singleton;
}
get() {
2020-04-08 14:13:33 +05:30
const hasHealthStatusFeatureFlag = gon.features && gon.features.saveIssuableHealthStatus;
return Promise.all([
axios.get(this.endpoint),
gqClient.query({
query: hasHealthStatusFeatureFlag
? sidebarDetailsForHealthStatusFeatureFlagQuery
: sidebarDetailsQuery,
variables: {
fullPath: this.fullPath,
iid: this.iid.toString(),
},
}),
]);
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,
});
}
2017-08-17 22:00:37 +05:30
}