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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
<script>
import $ from 'jquery';
import { GlButton } from '@gitlab/ui';
import { produce } from 'immer';
import { __ } from '~/locale';
import { deprecatedCreateFlash as createFlash } from '~/flash';
import MergeRequest from '~/merge_request';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import mergeRequestQueryVariablesMixin from '../../mixins/merge_request_query_variables';
import getStateQuery from '../../queries/get_state.query.graphql';
import workInProgressQuery from '../../queries/states/work_in_progress.query.graphql';
import removeWipMutation from '../../queries/toggle_wip.mutation.graphql';
import StatusIcon from '../mr_widget_status_icon.vue';
import eventHub from '../../event_hub';
export default {
name: 'WorkInProgress',
components: {
StatusIcon,
GlButton,
},
mixins: [glFeatureFlagMixin(), mergeRequestQueryVariablesMixin],
apollo: {
userPermissions: {
query: workInProgressQuery,
skip() {
return !this.glFeatures.mergeRequestWidgetGraphql;
},
variables() {
return this.mergeRequestQueryVariables;
},
update: data => data.project.mergeRequest.userPermissions,
},
},
props: {
mr: { type: Object, required: true },
service: { type: Object, required: true },
},
data() {
return {
userPermissions: {},
isMakingRequest: false,
};
},
computed: {
canUpdate() {
if (this.glFeatures.mergeRequestWidgetGraphql) {
return this.userPermissions.updateMergeRequest;
}
return Boolean(this.mr.removeWIPPath);
},
},
methods: {
removeWipMutation() {
const { mergeRequestQueryVariables } = this;
this.isMakingRequest = true;
this.$apollo
.mutate({
mutation: removeWipMutation,
variables: {
...mergeRequestQueryVariables,
wip: false,
},
update(
store,
{
data: {
mergeRequestSetWip: {
errors,
mergeRequest: { workInProgress, title },
},
},
},
) {
if (errors?.length) {
createFlash(__('Something went wrong. Please try again.'));
return;
}
const sourceData = store.readQuery({
query: getStateQuery,
variables: mergeRequestQueryVariables,
});
const data = produce(sourceData, draftState => {
// eslint-disable-next-line no-param-reassign
draftState.project.mergeRequest.workInProgress = workInProgress;
// eslint-disable-next-line no-param-reassign
draftState.project.mergeRequest.title = title;
});
store.writeQuery({
query: getStateQuery,
data,
variables: mergeRequestQueryVariables,
});
},
optimisticResponse: {
// eslint-disable-next-line @gitlab/require-i18n-strings
__typename: 'Mutation',
mergeRequestSetWip: {
__typename: 'MergeRequestSetWipPayload',
errors: [],
mergeRequest: {
__typename: 'MergeRequest',
title: this.mr.title,
workInProgress: false,
},
},
},
})
.then(({ data: { mergeRequestSetWip: { mergeRequest: { title } } } }) => {
createFlash(__('The merge request can now be merged.'), 'notice');
$('.merge-request .detail-page-description .title').text(title);
})
.catch(() => createFlash(__('Something went wrong. Please try again.')))
.finally(() => {
this.isMakingRequest = false;
});
},
handleRemoveWIP() {
if (this.glFeatures.mergeRequestWidgetGraphql) {
this.removeWipMutation();
} else {
this.isMakingRequest = true;
this.service
.removeWIP()
.then(res => res.data)
.then(data => {
eventHub.$emit('UpdateWidgetData', data);
MergeRequest.toggleDraftStatus(this.mr.title, true);
})
.catch(() => {
this.isMakingRequest = false;
createFlash(__('Something went wrong. Please try again.'));
});
}
},
},
};
</script>
<template>
<div class="mr-widget-body media">
<status-icon :show-disabled-button="canUpdate" status="warning" />
<div class="media-body">
<div class="gl-ml-3 float-left">
<span class="gl-font-weight-bold">
{{ __('This merge request is still a draft.') }}
</span>
<span class="gl-display-block text-muted">{{
__("Draft merge requests can't be merged.")
}}</span>
</div>
<gl-button
v-if="canUpdate"
size="small"
:disabled="isMakingRequest"
:loading="isMakingRequest"
class="js-remove-wip gl-ml-3"
@click="handleRemoveWIP"
>
{{ s__('mrWidget|Mark as ready') }}
</gl-button>
</div>
</div>
</template>
|