-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathHealthScorecard.jsx
More file actions
321 lines (300 loc) · 16.2 KB
/
Copy pathHealthScorecard.jsx
File metadata and controls
321 lines (300 loc) · 16.2 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import React, { useState, useMemo } from 'react'
import { FiAlertTriangle, FiCheckCircle, FiInfo, FiExternalLink, FiShield, FiTrendingUp, FiUsers, FiFileText } from 'react-icons/fi'
import { C, EmptyOk } from './UI'
import { computeOrgHealthSummary } from '../services/healthScorecard'
import { classifyRepositoryRisk, generateRiskRecommendations } from '../services/riskAdvisor'
export default function HealthScorecard({ model, issuesData = {}, hasAudit = false, onRunAudit, govLoading = false }) {
const [filter, setFilter] = useState('all') // 'all' | 'critical' | 'warning' | 'healthy'
const summary = useMemo(() => computeOrgHealthSummary(model, issuesData, hasAudit), [model, issuesData, hasAudit])
const recommendations = useMemo(() => generateRiskRecommendations(model, issuesData), [model, issuesData])
// Classify all repositories
const repoRisks = useMemo(() => {
if (!model || !model.allRepos) return []
return model.allRepos.map(repo => {
const risk = classifyRepositoryRisk(repo, issuesData)
return {
...repo,
riskTier: risk.tier,
mainIssue: risk.mainIssue,
score: repo.healthScore ?? 50,
}
})
}, [model, issuesData])
const counts = useMemo(() => {
const crit = repoRisks.filter(r => r.riskTier === 'critical').length
const warn = repoRisks.filter(r => r.riskTier === 'warning').length
const heal = repoRisks.filter(r => r.riskTier === 'healthy').length
return { critical: crit, warning: warn, healthy: heal }
}, [repoRisks])
const filteredRepos = useMemo(() => {
if (filter === 'all') return repoRisks
return repoRisks.filter(r => r.riskTier === filter)
}, [repoRisks, filter])
if (!model || !model.allRepos || model.allRepos.length === 0) {
return <EmptyOk msg="No repository data available" sub="Please select an organization to view health scorecard." />
}
// Grade color map
const gradeColors = {
'A+': { color: 'var(--green)', bg: 'rgba(34,197,94,.15)', border: 'rgba(34,197,94,.4)' },
'A': { color: 'var(--green)', bg: 'rgba(34,197,94,.12)', border: 'rgba(34,197,94,.3)' },
'B': { color: 'var(--blue)', bg: 'rgba(59,130,246,.12)', border: 'rgba(59,130,246,.3)' },
'C': { color: 'var(--amber)', bg: 'rgba(245,158,11,.12)', border: 'rgba(245,158,11,.3)' },
'D': { color: 'var(--orange)', bg: 'rgba(249,115,22,.12)', border: 'rgba(249,115,22,.3)' },
'F': { color: 'var(--red)', bg: 'rgba(239,68,68,.12)', border: 'rgba(239,68,68,.3)' },
}
const currentGradeStyle = gradeColors[summary.grade] || gradeColors['C']
const DimensionBar = ({ label, score, icon: Icon, isPendingAudit = false }) => (
<div style={{ marginBottom: 14 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 13, fontWeight: 500 }}>
<Icon size={14} style={{ color: 'var(--accent)' }} />
<span>{label}</span>
</div>
<div>
{isPendingAudit ? (
<span style={{ fontSize: 11, color: 'var(--amber)', background: 'rgba(245,158,11,.12)', padding: '2px 8px', borderRadius: 4 }}>
Insufficient Data (Audit Pending)
</span>
) : (
<span style={{ fontSize: 13, fontWeight: 600, color: score >= 70 ? 'var(--green)' : score >= 50 ? 'var(--amber)' : 'var(--red)' }}>
{score} / 100
</span>
)}
</div>
</div>
<div style={{ height: 6, background: 'var(--border)', borderRadius: 4, overflow: 'hidden' }}>
{!isPendingAudit && (
<div
style={{
width: `${score}%`,
height: '100%',
background: score >= 70 ? 'var(--green)' : score >= 50 ? 'var(--amber)' : 'var(--red)',
borderRadius: 4,
transition: 'width 0.4s ease',
}}
/>
)}
</div>
</div>
)
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
{/* 1. Header Card: Grade & Risk Counter Chips */}
<div style={{ ...C.card, padding: 24, display: 'grid', gridTemplateColumns: '1fr 2fr', gap: 24, alignItems: 'center' }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 18, borderRight: '1px solid var(--border)', paddingRight: 20 }}>
<div style={{
width: 80, height: 80, borderRadius: 16,
background: currentGradeStyle.bg,
border: `2px solid ${currentGradeStyle.border}`,
display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
flexShrink: 0
}}>
<span style={{ fontSize: 36, fontWeight: 800, color: currentGradeStyle.color, lineHeight: 1 }}>{summary.grade}</span>
<span style={{ fontSize: 10, fontWeight: 600, color: 'var(--text2)', marginTop: 2 }}>GRADE</span>
</div>
<div>
<div style={{ fontSize: 12, color: 'var(--text2)', textTransform: 'uppercase', letterSpacing: '.05em', fontWeight: 600 }}>
Organization Health
</div>
<div style={{ fontSize: 32, fontWeight: 700, margin: '2px 0' }}>
{summary.score} <span style={{ fontSize: 16, color: 'var(--text3)', fontWeight: 400 }}>/ 100</span>
</div>
<div style={{ fontSize: 12, color: 'var(--text3)' }}>
Evaluated across {summary.totalRepos} repositories
</div>
</div>
</div>
{/* Risk Counter Chips */}
<div>
<div style={{ fontSize: 12, color: 'var(--text2)', fontWeight: 600, marginBottom: 12 }}>
ORGANIZATION RISK CLASSIFICATION
</div>
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
<button
type="button"
aria-pressed={filter === 'critical'}
onClick={() => setFilter('critical')}
style={{
flex: 1, minWidth: 110, padding: '12px 14px', borderRadius: 8, cursor: 'pointer', textAlign: 'left', fontFamily: 'inherit',
background: filter === 'critical' ? 'rgba(239,68,68,.2)' : 'var(--surface2)',
border: filter === 'critical' ? '1px solid var(--red)' : '1px solid var(--border)',
transition: 'all 0.2s ease',
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 12, color: 'var(--red)', fontWeight: 600 }}>
<FiAlertTriangle size={13} /> Critical
</div>
<div style={{ fontSize: 24, fontWeight: 700, marginTop: 4, color: 'var(--red)' }}>{counts.critical}</div>
</button>
<button
type="button"
aria-pressed={filter === 'warning'}
onClick={() => setFilter('warning')}
style={{
flex: 1, minWidth: 110, padding: '12px 14px', borderRadius: 8, cursor: 'pointer', textAlign: 'left', fontFamily: 'inherit',
background: filter === 'warning' ? 'rgba(245,158,11,.2)' : 'var(--surface2)',
border: filter === 'warning' ? '1px solid var(--amber)' : '1px solid var(--border)',
transition: 'all 0.2s ease',
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 12, color: 'var(--amber)', fontWeight: 600 }}>
<FiInfo size={13} /> Warning
</div>
<div style={{ fontSize: 24, fontWeight: 700, marginTop: 4, color: 'var(--amber)' }}>{counts.warning}</div>
</button>
<button
type="button"
aria-pressed={filter === 'healthy'}
onClick={() => setFilter('healthy')}
style={{
flex: 1, minWidth: 110, padding: '12px 14px', borderRadius: 8, cursor: 'pointer', textAlign: 'left', fontFamily: 'inherit',
background: filter === 'healthy' ? 'rgba(34,197,94,.2)' : 'var(--surface2)',
border: filter === 'healthy' ? '1px solid var(--green)' : '1px solid var(--border)',
transition: 'all 0.2s ease',
}}
>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 12, color: 'var(--green)', fontWeight: 600 }}>
<FiCheckCircle size={13} /> Healthy
</div>
<div style={{ fontSize: 24, fontWeight: 700, marginTop: 4, color: 'var(--green)' }}>{counts.healthy}</div>
</button>
</div>
</div>
</div>
{/* 2. Health Dimensions Panel */}
<div style={C.card}>
<div style={{ fontWeight: 600, fontSize: 15, marginBottom: 4 }}>Health Dimensions</div>
<div style={{ ...C.label, marginBottom: 16 }}>Key performance factors shaping the organization score</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '12px 24px' }}>
<DimensionBar label="Activity & Push Velocity" score={summary.dimensions.activity} icon={FiTrendingUp} />
<DimensionBar label="Maintainer Diversity" score={summary.dimensions.diversity} icon={FiUsers} />
<DimensionBar label="License Compliance" score={summary.dimensions.compliance} icon={FiFileText} />
<DimensionBar label="Issue & PR Resolution Health" score={summary.dimensions.issueHealth || 0} icon={FiShield} isPendingAudit={!summary.dimensions.hasAudit} />
</div>
{!hasAudit && onRunAudit && (
<div style={{ marginTop: 12, padding: '10px 14px', background: 'rgba(245,158,11,.08)', borderRadius: 6, border: '1px solid rgba(245,158,11,.2)', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span style={{ fontSize: 12, color: 'var(--text2)' }}>Run issue audit to populate Issue & PR Resolution Health score.</span>
<button onClick={onRunAudit} disabled={govLoading} style={{ ...C.btn('primary'), fontSize: 11, padding: '4px 10px' }}>
Run Audit
</button>
</div>
)}
</div>
{/* 3. ⚡ Risk Advisor Panel */}
<div style={C.card}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, fontWeight: 600, fontSize: 15, marginBottom: 4 }}>
<span>⚡ Risk Advisor</span>
</div>
<div style={{ ...C.label, marginBottom: 16 }}>Automated priority recommendations for org maintainers</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
{recommendations.map(rec => {
const isCrit = rec.severity === 'critical'
const isWarn = rec.severity === 'warning'
const borderColor = isCrit ? 'var(--red)' : isWarn ? 'var(--amber)' : 'var(--green)'
const bg = isCrit ? 'rgba(239,68,68,.06)' : isWarn ? 'rgba(245,158,11,.06)' : 'rgba(34,197,94,.06)'
return (
<div key={rec.id} style={{ padding: '14px 16px', background: bg, borderLeft: `4px solid ${borderColor}`, borderRadius: 6 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 4 }}>
<div style={{ fontWeight: 600, fontSize: 13, display: 'flex', alignItems: 'center', gap: 6 }}>
{isCrit && <FiAlertTriangle color="var(--red)" size={14} />}
{isWarn && <FiInfo color="var(--amber)" size={14} />}
{!isCrit && !isWarn && <FiCheckCircle color="var(--green)" size={14} />}
<span>{rec.title}</span>
</div>
{rec.htmlUrl && (
<a href={rec.htmlUrl} target="_blank" rel="noreferrer" style={{ fontSize: 11, color: 'var(--text2)', display: 'flex', alignItems: 'center', gap: 3 }}>
<FiExternalLink size={11} /> {rec.action}
</a>
)}
</div>
<div style={{ fontSize: 12, color: 'var(--text2)', lineHeight: 1.5 }}>
{rec.description}
</div>
</div>
)
})}
</div>
</div>
{/* 4. Repository Risk Table */}
<div style={C.card}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16, flexWrap: 'wrap', gap: 10 }}>
<div>
<div style={{ fontWeight: 600, fontSize: 15 }}>Repository Risk Classification</div>
<div style={{ ...C.label, marginTop: 2 }}>Breakdown of repositories filtered by risk signals</div>
</div>
<div style={{ display: 'flex', gap: 6 }}>
{[
{ key: 'all', label: `All (${repoRisks.length})` },
{ key: 'critical', label: `Critical (${counts.critical})` },
{ key: 'warning', label: `Warning (${counts.warning})` },
{ key: 'healthy', label: `Healthy (${counts.healthy})` },
].map(tab => (
<button
key={tab.key}
onClick={() => setFilter(tab.key)}
style={{
background: filter === tab.key ? 'var(--surface2)' : 'none',
border: filter === tab.key ? '1px solid var(--accent)' : '1px solid var(--border)',
color: filter === tab.key ? 'var(--text)' : 'var(--text2)',
fontSize: 12, fontWeight: filter === tab.key ? 600 : 400,
padding: '5px 10px', borderRadius: 6, cursor: 'pointer',
}}
>
{tab.label}
</button>
))}
</div>
</div>
{filteredRepos.length > 0 ? (
<div style={{ overflowX: 'auto' }}>
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
<thead>
<tr>
{['REPOSITORY', 'HEALTH SCORE', 'RISK TIER', 'MAIN RISK SIGNAL', 'ACTION'].map(h => (
<th key={h} style={{ padding: '8px 14px', textAlign: 'left', fontSize: 11, color: 'var(--text2)', fontWeight: 600, borderBottom: '1px solid var(--border)', background: 'var(--surface2)' }}>
{h}
</th>
))}
</tr>
</thead>
<tbody>
{filteredRepos.map((repo, i) => {
const isCrit = repo.riskTier === 'critical'
const isWarn = repo.riskTier === 'warning'
const badgeColor = isCrit ? 'var(--red)' : isWarn ? 'var(--amber)' : 'var(--green)'
const badgeBg = isCrit ? 'rgba(239,68,68,.12)' : isWarn ? 'rgba(245,158,11,.12)' : 'rgba(34,197,94,.12)'
return (
<tr key={repo.id || repo.name} style={{ borderBottom: '1px solid var(--border)', background: i % 2 ? 'var(--surface2)' : 'transparent' }}>
<td style={{ padding: '10px 14px' }}>
<div style={{ fontSize: 13, fontWeight: 600 }}>{repo.name}</div>
<div style={{ fontSize: 11, color: 'var(--text2)' }}>{repo.orgLogin}</div>
</td>
<td style={{ padding: '10px 14px' }}>
<div style={{ fontSize: 13, fontWeight: 600 }}>{repo.score}</div>
</td>
<td style={{ padding: '10px 14px' }}>
<span style={C.pill(badgeColor, badgeBg)}>
{repo.riskTier.toUpperCase()}
</span>
</td>
<td style={{ padding: '10px 14px', fontSize: 12, color: 'var(--text2)' }}>
{repo.mainIssue}
</td>
<td style={{ padding: '10px 14px' }}>
<a href={repo.html_url || `https://github.com/${repo.orgLogin}/${repo.name}`} target="_blank" rel="noreferrer" style={{ fontSize: 12, color: 'var(--text2)', display: 'flex', alignItems: 'center', gap: 4 }}>
<FiExternalLink size={12} /> GitHub
</a>
</td>
</tr>
)
})}
</tbody>
</table>
</div>
) : (
<EmptyOk msg={`No ${filter} repositories found`} sub="All checked repositories are operating smoothly." />
)}
</div>
</div>
)
}