forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiPipelineGraph.tsx
More file actions
70 lines (60 loc) · 1.88 KB
/
MultiPipelineGraph.tsx
File metadata and controls
70 lines (60 loc) · 1.88 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
import { useContext, useEffect, useState } from "react";
import { I18NContext, LocaleContext } from "../../../common/i18n/index.ts";
import { RunInfo } from "./MultiPipelineGraphModel.ts";
import SingleRun from "./SingleRun.tsx";
import startPollingRunsStatus from "./support/startPollingRunsStatus.ts";
export const MultiPipelineGraph = () => {
const [runs, setRuns] = useState<Array<RunInfo>>([]);
const [poll, setPoll] = useState(false);
const rootElement = document.getElementById("multiple-pipeline-root");
const currentJobPath = rootElement!.dataset.currentJobPath!;
useEffect(() => {
if (!poll) {
setPoll(true);
startPollingRunsStatus(currentJobPath, setRuns, (err) => {
console.log(err);
});
}
}, [runs, poll]);
const locale = useContext(LocaleContext);
const groupedRuns: Record<string, RunInfo[]> = runs.reduce(
(acc: Record<string, RunInfo[]>, run) => {
const date = new Date(run.timestamp).toLocaleDateString(locale, {
year: "numeric",
month: "long",
day: "numeric",
});
if (!acc[date]) {
acc[date] = [];
}
acc[date].push(run);
return acc;
},
{},
);
const messages = useContext(I18NContext);
return (
<>
{Object.keys(groupedRuns).length === 0 ? (
<div className="pgv-stages__group">
<div className="pgv-stages__heading">
{messages.format("noBuilds")}
</div>
</div>
) : (
Object.entries(groupedRuns).map(([date, runsOnDate]) => (
<div className={"pgv-stages__group"} key={date}>
<p className="pgv-stages__heading">{date}</p>
{runsOnDate.map((run) => (
<SingleRun
key={run.id}
run={run}
currentJobPath={currentJobPath}
/>
))}
</div>
))
)}
</>
);
};