|
1 | 1 | import { useEffect, useState } from "react"; |
2 | 2 | import { DataTable } from "primereact/datatable"; |
3 | 3 | import { Column } from "primereact/column"; |
4 | | -import Image from "next/image"; |
5 | | -import { basePath } from "../next.config.js"; |
| 4 | +import { weatherTemplate, getWeatherIndex } from "../components/weatherTemplate"; |
| 5 | + |
6 | 6 |
|
7 | 7 | export default function Home() { |
8 | 8 | const [loading, setLoading] = useState(true); |
9 | 9 | const [jobs, setJobs] = useState([]); |
10 | 10 | const [rows, setRows] = useState([]); |
11 | 11 | const [expandedRows, setExpandedRows] = useState([]); |
12 | 12 |
|
13 | | - const icons = [ |
14 | | - "sunny.svg", |
15 | | - "partially-sunny.svg", |
16 | | - "cloudy.svg", |
17 | | - "rainy.svg", |
18 | | - "stormy.svg", |
19 | | - ]; |
20 | | - |
21 | 13 | useEffect(() => { |
22 | 14 | const fetchData = async () => { |
23 | 15 | let data = {}; |
@@ -56,46 +48,6 @@ export default function Home() { |
56 | 48 | setLoading(false); |
57 | 49 | }, [jobs]); |
58 | 50 |
|
59 | | - const getWeatherIndex = (stat) => { |
60 | | - let fail_rate = 0; |
61 | | - fail_rate = (stat["fails"] + stat["skips"]) / stat["runs"]; |
62 | | - // e.g. failing 3/9 runs is .33, or idx=1 |
63 | | - var idx = Math.floor((fail_rate * 10) / 2); |
64 | | - if (idx == icons.length) { |
65 | | - // edge case: if 100% failures, then we go past the end of icons[] |
66 | | - // back the idx down by 1 |
67 | | - console.assert(fail_rate == 1.0); |
68 | | - idx -= 1; |
69 | | - } |
70 | | - |
71 | | - // This error checks if there are zero runs. |
72 | | - // Currently, will display stormy weather. |
73 | | - if (isNaN(idx)) { |
74 | | - idx = 4; |
75 | | - } |
76 | | - return idx; |
77 | | - }; |
78 | | - |
79 | | - const getWeatherIcon = (stat) => { |
80 | | - const idx = getWeatherIndex(stat); |
81 | | - return icons[idx]; |
82 | | - }; |
83 | | - |
84 | | - const weatherTemplate = (data) => { |
85 | | - const icon = getWeatherIcon(data); |
86 | | - return ( |
87 | | - <div> |
88 | | - <Image |
89 | | - src={`${basePath}/${icon}`} |
90 | | - alt="weather" |
91 | | - width={32} |
92 | | - height={32} |
93 | | - // priority |
94 | | - /> |
95 | | - </div> |
96 | | - ); |
97 | | - }; |
98 | | - |
99 | 51 | const toggleRow = (rowData) => { |
100 | 52 | const isRowExpanded = expandedRows.includes(rowData); |
101 | 53 |
|
|
0 commit comments