-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.tsx
More file actions
426 lines (402 loc) · 24.4 KB
/
Copy pathindex.tsx
File metadata and controls
426 lines (402 loc) · 24.4 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
import { Spinner } from 'flowbite-react'
import Image from 'next/image'
import Link from 'next/link'
import { useRouter } from 'next/router'
import React from 'react'
import { CiFilter } from 'react-icons/ci'
import { FiExternalLink } from 'react-icons/fi'
import { ClearableLabel } from '../components/Labels/ClearableLabel'
import { WorkflowStatusButton } from '../components/StatusButton'
import { StatsDashboard } from '../components/StatsDashboard'
import { Surface, SectionTitle } from '../components/Surface'
import { BrandSelect } from '../components/Inputs'
import { Pager } from '../components/Pager'
import analytic from '../global/mixpanel'
import { useGetBranch, useGetGitcommit, WorkflowRunStatus } from '../src/api/generated'
import { formatDuration } from '../utils/format'
import { StatusToColor, StatusToHumanText } from './workflow/[id]'
const DEFAULT_REPO = 'comfyanonymous/ComfyUI'
// Status filter options. The /gitcommit API has no status param, so this filters
// the rows already loaded for the current page (see note rendered below the table).
const STATUS_OPTIONS: { label: string; value: string }[] = [
{ label: 'Failed', value: WorkflowRunStatus.WorkflowRunStatusFailed },
{ label: 'In Progress', value: WorkflowRunStatus.WorkflowRunStatusStarted },
{ label: 'Success', value: WorkflowRunStatus.WorkflowRunStatusCompleted },
]
function GitCommitsList() {
const [currentPage, setCurrentPage] = React.useState(1)
const onPageChange = (page: number) => setCurrentPage(page)
const router = useRouter();
const [filterOS, setFilterOS] = React.useState<string>('Select OS')
const [repoFilter, setRepoFilter] = React.useState<string>(DEFAULT_REPO)
const [branchFilter, setBranchFilter] = React.useState<string>('Select Branch')
const [commitId, setCommitId] = React.useState<string>('')
const [workflowNameFilter, setWorkflowFilter] = React.useState<string>('')
// Client-side only (the API has no status param) — not synced to the URL.
const [statusFilter, setStatusFilter] = React.useState<string>('')
const prevFilters = React.useRef({ filterOS, repoFilter, branchFilter, commitId, workflowNameFilter, currentPage });
const { data: filteredJobResults, isLoading } = useGetGitcommit({
operatingSystem: filterOS == 'Select OS' ? undefined : filterOS,
commitId: commitId == '' ? undefined : commitId,
workflowName: workflowNameFilter == '' ? undefined : workflowNameFilter,
branch: branchFilter == 'Select Branch' ? undefined : branchFilter,
page: currentPage,
repoName: repoFilter,
pageSize: 30,
})
// Update the URL parameters when filters change
React.useEffect(() => {
// Only update the URL if the filters have actually changed
if (filterOS !== prevFilters.current.filterOS ||
repoFilter !== prevFilters.current.repoFilter ||
branchFilter !== prevFilters.current.branchFilter ||
commitId !== prevFilters.current.commitId ||
workflowNameFilter !== prevFilters.current.workflowNameFilter ||
currentPage !== prevFilters.current.currentPage) {
const query = {
os: filterOS || undefined,
repo: repoFilter || undefined,
branch: branchFilter || undefined,
commitId: commitId || undefined,
workflowName: workflowNameFilter || undefined,
page: currentPage.toString(),
};
router.push({ pathname: router.pathname, query }, undefined, { shallow: true });
// Update the ref with the new values
prevFilters.current = { filterOS, repoFilter, branchFilter, commitId, workflowNameFilter, currentPage };
}
}, [filterOS, repoFilter, branchFilter, commitId, workflowNameFilter, currentPage, router, prevFilters]);
// Initialize filters from URL on component mount or when URL changes
React.useEffect(() => {
const query = router.query;
// Ensure all parameters are treated as strings, even if they are arrays
setFilterOS(typeof query.os === 'string' ? query.os : query.os?.[0] || 'Select OS');
setRepoFilter(typeof query.repo === 'string' ? query.repo : query.repo?.[0] || DEFAULT_REPO);
setBranchFilter(typeof query.branch === 'string' ? query.branch : query.branch?.[0] || 'Select Branch');
setCommitId(typeof query.commitId === 'string' ? query.commitId : query.commitId?.[0] || '');
setWorkflowFilter(typeof query.workflowName === 'string' ? query.workflowName : query.workflowName?.[0] || '');
setCurrentPage(parseInt(typeof query.page === 'string' ? query.page : query.page?.[0] || '1'));
}, [router.query]);
const { data: branchesQueryResults, isLoading: loadingBranchs } = useGetBranch({
repo_name: repoFilter
})
React.useEffect(() => {
const repo = router.query.repo;
if (typeof repo === 'string') {
setRepoFilter(repo);
}
}, [router.query.repo]);
const jobResults = filteredJobResults?.jobResults ?? []
const visibleResults = statusFilter
? jobResults.filter((r) => r.status === statusFilter)
: jobResults
const hasActiveFilters =
filterOS !== 'Select OS' ||
branchFilter !== 'Select Branch' ||
commitId !== '' ||
workflowNameFilter !== '' ||
statusFilter !== ''
const clearAll = () => {
setFilterOS('Select OS')
setBranchFilter('Select Branch')
setCommitId('')
setWorkflowFilter('')
setStatusFilter('')
setCurrentPage(1)
}
return (
<div className="pt-8">
{/* Page heading */}
<div className="mb-6 flex flex-wrap items-end justify-between gap-3">
<div>
<h1 className="text-2xl font-extrabold tracking-tight text-charcoal-800 dark:text-white">
Workflow Results
</h1>
<p className="mt-1 text-sm text-ash-500 dark:text-smoke-800">
Individual CI runs across commits, branches and platforms.
</p>
</div>
<a
href={`https://github.com/${repoFilter}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 rounded-full border border-smoke-300 dark:border-charcoal-400/60 bg-smoke-200/60 dark:bg-charcoal-700/60 px-3 py-1.5 text-sm font-medium text-charcoal-800 dark:text-smoke-200 hover:border-electric/50 hover:text-charcoal-900 dark:hover:text-electric"
>
{repoFilter}
<FiExternalLink className="h-3.5 w-3.5" />
</a>
</div>
{/* Dashboard */}
<StatsDashboard results={jobResults} />
{/* Filters */}
<Surface className="mb-6 p-4">
<div className="mb-3 flex items-center justify-between">
<SectionTitle>Filters</SectionTitle>
{hasActiveFilters && (
<button
onClick={clearAll}
className="text-xs font-semibold text-ash-500 hover:text-electric"
>
Clear all
</button>
)}
</div>
<div className="flex flex-wrap items-center gap-3">
<BrandSelect
id="branch-select"
value={branchFilter}
onChange={(e) => {
setBranchFilter(e.target.value);
analytic.track('Change Branch Filter', { branch: e.target.value });
setCurrentPage(1);
}}
className="w-56"
>
<option value="">Select Branch</option>
{branchesQueryResults?.branches?.map((branch, index) => (
<option key={index} value={branch}>
{branch}
</option>
))}
</BrandSelect>
<BrandSelect
id="os-select"
value={filterOS}
onChange={(e) => setFilterOS(e.target.value)}
className="w-40"
>
<option value="">Select OS</option>
<option value="linux">linux</option>
<option value="macos">macos</option>
<option value="windows">windows</option>
</BrandSelect>
<BrandSelect
id="status-select"
value={statusFilter}
onChange={(e) => {
setStatusFilter(e.target.value)
analytic.track('Change Status Filter', { status: e.target.value })
}}
className="w-44"
>
<option value="">Select Status</option>
{STATUS_OPTIONS.map((s) => (
<option key={s.value} value={s.value}>
{s.label}
</option>
))}
</BrandSelect>
<ClearableLabel
id="commit-id-input"
label="Commit ID"
value={commitId}
onChange={(s) => {
setCommitId(s);
setCurrentPage(1);
}}
onClear={() => setCommitId('')}
/>
<ClearableLabel
id="workflow-id-input"
label="Workflow Name"
value={workflowNameFilter}
onChange={(s) => {
setWorkflowFilter(s);
setCurrentPage(1);
}}
onClear={() => setWorkflowFilter('')}
/>
</div>
</Surface>
{(isLoading || loadingBranchs) ? (
<div className="flex justify-center items-center py-24">
<Spinner size="xl" />
</div>
) : jobResults.length === 0 ? (
<Surface className="flex flex-col items-center justify-center gap-2 py-24 text-center">
<span className="text-lg font-semibold">No results found</span>
<span className="text-sm text-ash-500 dark:text-smoke-800">
Try adjusting or clearing your filters.
</span>
</Surface>
) : (
<>
{statusFilter && (
<p className="mb-2 text-xs text-ash-500 dark:text-smoke-800">
Showing {visibleResults.length} of {jobResults.length} run{jobResults.length === 1 ? '' : 's'} on this page matching{' '}
<span className="font-semibold">{StatusToHumanText(statusFilter as WorkflowRunStatus)}</span>.
</p>
)}
<Surface className="overflow-hidden">
<div className="overflow-x-auto scrollbar-thin">
<table className="w-full text-left text-sm">
<thead>
<tr className="border-b border-smoke-300 dark:border-charcoal-400/60 text-[11px] uppercase tracking-wider text-ash-500 dark:text-smoke-800">
<th className="px-5 py-3 font-semibold">Workflow</th>
<th className="px-5 py-3 font-semibold">Status</th>
<th className="px-5 py-3 font-semibold">Commit</th>
<th className="px-5 py-3 font-semibold">Environment</th>
<th className="px-5 py-3 font-semibold">Output</th>
<th className="px-5 py-3 font-semibold">Run Time</th>
<th className="px-5 py-3 font-semibold text-right">Action</th>
</tr>
</thead>
<tbody className="divide-y divide-smoke-200 dark:divide-charcoal-400/40">
{visibleResults.length === 0 && (
<tr>
<td colSpan={7} className="px-5 py-10 text-center text-sm text-ash-500 dark:text-smoke-800">
No runs match the selected status on this page.
</td>
</tr>
)}
{visibleResults.map((result, index) => (
<tr
key={result.id || index}
className={`group transition-colors hover:bg-smoke-200/60 dark:hover:bg-charcoal-700/40 ${result.status === WorkflowRunStatus.WorkflowRunStatusFailed
? 'bg-red-500/[0.06] dark:bg-red-500/[0.08]'
: ''
}`}
>
{/* Workflow */}
<td className="px-5 py-4 align-top">
<div className="flex items-center gap-2">
<Link
href={`/workflow/${result.id}`}
target="_blank"
rel="noopener noreferrer"
className="font-semibold text-charcoal-800 dark:text-smoke-100 hover:text-sapphire-700 dark:hover:text-electric"
>
{result.workflow_name}
</Link>
<button
title="Filter by this workflow"
className="opacity-0 group-hover:opacity-100 transition-opacity rounded-md p-1 text-ash-500 hover:bg-smoke-300 dark:hover:bg-charcoal-400/60 hover:text-electric"
onClick={() => {
setWorkflowFilter(result.workflow_name || '')
setCurrentPage(1)
}}
>
<CiFilter />
</button>
</div>
</td>
{/* Status */}
<td className="px-5 py-4 align-top">
<WorkflowStatusButton
text={StatusToHumanText(result?.status)}
status={StatusToColor(result.status)}
/>
</td>
{/* Commit */}
<td className="px-5 py-4 align-top">
<div className="flex items-center gap-2">
<Link
href={`https://github.com/${result.git_repo}/commit/${result.commit_hash}`}
target="_blank"
rel="noopener noreferrer"
className="rounded bg-smoke-200 dark:bg-charcoal-700 px-1.5 py-0.5 font-mono text-xs text-sapphire-700 dark:text-plum-300 hover:underline"
>
{result.commit_hash?.slice(0, 7)}
</Link>
<button
title="Filter by this commit"
className="opacity-0 group-hover:opacity-100 transition-opacity rounded-md p-1 text-ash-500 hover:bg-smoke-300 dark:hover:bg-charcoal-400/60 hover:text-electric"
onClick={() => {
setCommitId(result.commit_id || '')
setCurrentPage(1)
}}
>
<CiFilter />
</button>
</div>
<div className="mt-1 max-w-[22rem] truncate text-xs text-ash-500 dark:text-smoke-800" title={result.commit_message}>
{result.commit_message}
</div>
<div className="mt-0.5 text-[11px] text-ash-500/80 dark:text-smoke-800/80">
{result.commit_time !== undefined
? new Date(result.commit_time * 1000).toLocaleString()
: ''}
</div>
</td>
{/* Environment */}
<td className="px-5 py-4 align-top">
<div className="flex items-center gap-2">
<span className="text-sm">
{result.operating_system}
<span className="text-ash-500 dark:text-smoke-800">
{' '}· py{result?.python_version}
</span>
</span>
<button
title="Filter by this OS"
className="opacity-0 group-hover:opacity-100 transition-opacity rounded-md p-1 text-ash-500 hover:bg-smoke-300 dark:hover:bg-charcoal-400/60 hover:text-electric"
onClick={() => {
setFilterOS(result.operating_system || '')
setCurrentPage(1)
}}
>
<CiFilter />
</button>
</div>
</td>
{/* Output */}
<td className="px-5 py-4 align-top">
{result.storage_file?.public_url ? (
<Link
href={`/workflow/${result.id}`}
target="_blank"
rel="noopener noreferrer"
>
<Image
src={result.storage_file.public_url}
alt={result.workflow_name || 'output file'}
width={72}
height={72}
className="h-[72px] w-[72px] rounded-lg border border-smoke-300 dark:border-charcoal-400/60 object-cover transition-transform hover:scale-105"
/>
</Link>
) : (
<div className="flex h-[72px] w-[72px] items-center justify-center rounded-lg border border-dashed border-smoke-400 dark:border-charcoal-400/60 text-[10px] text-ash-500 dark:text-smoke-800">
no output
</div>
)}
</td>
{/* Run time */}
<td className="px-5 py-4 align-top">
<span className="font-mono text-sm tabular-nums">
{result.end_time && result.start_time
? formatDuration(Math.abs(result.end_time - result.start_time))
: 'unknown'}
</span>
</td>
{/* Action */}
<td className="px-5 py-4 align-top text-right">
<Link
href={`https://github.com/${result.git_repo}/actions/runs/${result.action_run_id}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 rounded-lg border border-smoke-300 dark:border-charcoal-400/60 px-2.5 py-1.5 text-xs font-medium text-charcoal-800 dark:text-smoke-200 hover:border-electric/50 hover:text-charcoal-900 dark:hover:text-electric"
>
Action
<FiExternalLink className="h-3 w-3" />
</Link>
</td>
</tr>
))}
</tbody>
</table>
</div>
</Surface>
<div className="mt-6 flex justify-center">
<Pager
currentPage={currentPage}
totalPages={filteredJobResults?.totalNumberOfPages || 1}
onPageChange={onPageChange}
/>
</div>
</>
)}
</div>
);
}
export default GitCommitsList