-
Notifications
You must be signed in to change notification settings - Fork 11
/
MergeRequestsStatus.js
110 lines (103 loc) · 3.53 KB
/
MergeRequestsStatus.js
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
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Widget, WidgetHeader, WidgetBody } from '@mozaik/ui'
export default class MergeRequestsStatus extends Component {
static propTypes = {
project: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
status: PropTypes.string,
thresholds: PropTypes.arrayOf(
PropTypes.shape({
threshold: PropTypes.number.isRequired,
textColor: PropTypes.string.isRequired,
bgColor: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
})
).isRequired,
apiData: PropTypes.number.isRequired,
apiError: PropTypes.object,
theme: PropTypes.object.isRequired,
}
static defaultProps = {
thresholds: [
{
threshold: 0,
textColor: 'text',
bgColor: 'success',
message: 'good job!',
},
{
threshold: 3,
textColor: 'text',
bgColor: 'warning',
message: 'you should consider reviewing',
},
{
threshold: 5,
textColor: 'text',
bgColor: 'failure',
message: 'merge requests overflow',
},
],
apiData: 0,
}
static getApiRequest({ project, status = 'opened' }) {
return {
id: `gitlab.projectMergeRequestsStatus.${project}.${status}`,
params: {
project,
query: {
state: status,
},
},
}
}
render() {
const { thresholds, apiData: mergeRequestCount, theme } = this.props
let currentThreshold
let count = 0
thresholds.map((threshold, index) => {
if (mergeRequestCount >= threshold.threshold) {
count = index
}
return null
})
currentThreshold = thresholds[count]
const backgroundColor = theme.colors[currentThreshold.bgColor]
? theme.colors[currentThreshold.bgColor]
: ''
const fontColor = theme.colors[currentThreshold.textColor]
? theme.colors[currentThreshold.textColor]
: theme.colors.text
return (
<Widget>
<WidgetHeader title="Pending Merge Requests" icon="dashboard" />
<WidgetBody
style={{
background: backgroundColor,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: fontColor,
fontWeight: 'bolder',
}}
>
<div>
<div
style={{
fontSize: '3rem',
lineHeight: '3.5rem',
width: '100%',
textAlign: 'center',
}}
>
{parseInt(mergeRequestCount, 10)}
</div>
<div style={{ width: '100%', textAlign: 'center' }}>
{currentThreshold.message}
</div>
</div>
</WidgetBody>
</Widget>
)
}
}