-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcreateCommitsTableData.tsx
96 lines (86 loc) · 2.5 KB
/
createCommitsTableData.tsx
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
import isArray from 'lodash/isArray'
import isEmpty from 'lodash/isEmpty'
import {
Commit,
COMMIT_STATUS_COMPLETED,
COMMIT_STATUS_ERROR,
COMMIT_STATUS_PENDING,
} from 'services/commits/useCommits'
import { formatSizeToString } from 'shared/utils/bundleAnalysis'
import TotalsNumber from 'ui/TotalsNumber'
import Title from './Title'
export const ErroredUpload = () => (
<p>
Upload: <span aria-label="Errored upload">❌</span>
</p>
)
export const PendingUpload = () => (
<p>
Upload: <span aria-label="Pending upload">⏳</span>
</p>
)
interface CommitsTableData {
pages?: Array<{ commits: Array<Commit | null> }>
}
export const createCommitsTableData = ({ pages }: CommitsTableData) => {
if (!isArray(pages)) {
return []
}
const commits = pages?.map((page) => page?.commits).flat()
if (isEmpty(commits)) {
return []
}
return commits.filter(Boolean).map((commit) => {
let patch = <p>-</p>
if (commit?.coverageStatus === COMMIT_STATUS_ERROR) {
patch = <ErroredUpload />
} else if (commit?.coverageStatus === COMMIT_STATUS_PENDING) {
patch = <PendingUpload />
} else if (
commit?.coverageStatus === COMMIT_STATUS_COMPLETED &&
commit?.compareWithParent?.__typename === 'Comparison'
) {
const percent =
commit?.compareWithParent?.patchTotals?.percentCovered ?? NaN
patch = (
<TotalsNumber
plain={true}
large={false}
light={false}
value={percent}
showChange={false}
/>
)
}
let bundleAnalysis = <p>-</p>
if (commit?.bundleStatus === COMMIT_STATUS_ERROR) {
bundleAnalysis = <ErroredUpload />
} else if (commit?.bundleStatus === COMMIT_STATUS_PENDING) {
bundleAnalysis = <PendingUpload />
} else if (
commit?.bundleStatus === COMMIT_STATUS_COMPLETED &&
commit?.bundleAnalysis?.bundleAnalysisCompareWithParent?.__typename ===
'BundleAnalysisComparison'
) {
const change =
commit?.bundleAnalysis?.bundleAnalysisCompareWithParent?.bundleChange
?.size?.uncompress
const content = `${change > 0 ? '+' : ''}${formatSizeToString(change)}`
bundleAnalysis = <p>{content}</p>
}
// arbitrary change
console.log('hello')
return {
name: (
<Title
message={commit?.message}
author={commit?.author}
commitid={commit?.commitid}
createdAt={commit?.createdAt}
/>
),
patch,
bundleAnalysis,
}
})
}