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
|
<script>
import { stripHtml } from '~/lib/utils/text_utility';
import { sprintf, s__, n__ } from '~/locale';
import eventHub from '../../event_hub';
import StateContainer from '../state_container.vue';
export default {
name: 'MRWidgetFailedToMerge',
components: {
StateContainer,
},
props: {
mr: {
type: Object,
required: true,
},
},
data() {
return {
timer: 10,
isRefreshing: false,
intervalId: null,
};
},
computed: {
mergeError() {
const mergeError = this.prepareMergeError(this.mr.mergeError);
return sprintf(
s__('mrWidget|%{mergeError}.'),
{
mergeError,
},
false,
);
},
timerText() {
return n__(
'Refreshing in a second to show the updated status...',
'Refreshing in %d seconds to show the updated status...',
this.timer,
);
},
actions() {
return [
{
text: s__('mrWidget|Refresh now'),
onClick: () => this.refresh(),
testId: 'merge-request-failed-refresh-button',
dataQaSelector: 'merge_request_error_content',
},
];
},
},
mounted() {
this.intervalId = setInterval(this.updateTimer, 1000);
},
created() {
eventHub.$emit('DisablePolling');
},
beforeDestroy() {
if (this.intervalId) {
clearInterval(this.intervalId);
}
},
methods: {
refresh() {
this.isRefreshing = true;
eventHub.$emit('MRWidgetUpdateRequested');
eventHub.$emit('EnablePolling');
},
updateTimer() {
this.timer -= 1;
if (this.timer === 0) {
this.refresh();
}
},
prepareMergeError(mergeError) {
return mergeError
? stripHtml(mergeError, ' ')
.replace(/(\.$|\s+)/g, ' ')
.trim()
: '';
},
},
};
</script>
<template>
<state-container v-if="isRefreshing" :mr="mr" status="loading">
<span class="gl-font-weight-bold">
{{ s__('mrWidget|Refreshing now') }}
</span>
</state-container>
<state-container v-else :mr="mr" status="failed" :actions="actions">
<span class="gl-font-weight-bold">
<span v-if="mr.mergeError" class="has-error-message" data-testid="merge-error">
{{ mergeError }}
</span>
<span v-else> {{ s__('mrWidget|Merge failed.') }} </span>
<span :class="{ 'has-custom-error': mr.mergeError }"> {{ timerText }} </span>
</span>
</state-container>
</template>
|