1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
import mergeRequestApprovalStateUpdated from 'ee_else_ce/vue_merge_request_widget/components/approvals/queries/approvals.subscription.graphql';
import approvedByQuery from 'ee_else_ce/vue_merge_request_widget/components/approvals/queries/approvals.query.graphql';
import { createAlert } from '~/alert';
import { convertToGraphQLId } from '../../graphql_shared/utils';
import { TYPENAME_MERGE_REQUEST } from '../../graphql_shared/constants';
import { FETCH_ERROR } from '../components/approvals/messages';
export default {
apollo: {
approvals: {
query: approvedByQuery,
variables() {
return {
projectPath: this.mr.targetProjectFullPath,
iid: `${this.mr.iid}`,
};
},
update: (data) => data.project?.mergeRequest,
result({ data }) {
// This case can occur when backend returns an empty project due to expired session.
// See https://gitlab.com/gitlab-org/gitlab/-/issues/413627 for more information.
if (!data.project) {
// Needed to suppress several errors.
this.mr.setApprovals({});
return;
}
const { mergeRequest } = data.project;
this.disableCommittersApproval = data.project.mergeRequestsDisableCommittersApproval;
this.mr.setApprovals(mergeRequest);
},
error() {
createAlert({
message: FETCH_ERROR,
});
},
subscribeToMore: {
document: mergeRequestApprovalStateUpdated,
variables() {
return {
issuableId: convertToGraphQLId(TYPENAME_MERGE_REQUEST, this.mr.id),
};
},
skip() {
return !this.mr?.id;
},
updateQuery(
_,
{
subscriptionData: {
data: { mergeRequestApprovalStateUpdated: queryResult },
},
},
) {
if (queryResult) {
this.mr.setApprovals(queryResult);
}
},
},
},
},
data() {
return {
alerts: [],
approvals: {},
disableCommittersApproval: false,
};
},
methods: {
clearError() {
this.$emit('clearError');
this.hasApprovalAuthError = false;
this.alerts.forEach((alert) => alert.dismiss());
this.alerts = [];
},
refreshApprovals() {
return this.service.fetchApprovals().then((data) => {
this.mr.setApprovals(data);
});
},
},
};
|