Skip to content

Commit dbf7cd0

Browse files
committed
ui: Format all files using prettier
prettier -w .
1 parent 44642c8 commit dbf7cd0

19 files changed

+1047
-772
lines changed

ui/.prettierrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
2+
"arrowParens": "always",
3+
"bracketSpacing": false,
4+
"bracketSameLine": true,
25
"printWidth": 100,
6+
"semi": false,
37
"singleQuote": true,
4-
"bracketSpacing": false,
5-
"arrowParens": "avoid"
8+
"trailingComma": "all",
9+
"useTabs": false
610
}

ui/src/App.tsx

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
import React from 'react';
2-
import {BrowserRouter, Route, Routes} from 'react-router-dom';
1+
import React from 'react'
2+
import {BrowserRouter, Route, Routes} from 'react-router-dom'
33
import List from './pages/List'
44
import Detail from './pages/Detail'
55

66
// @ts-expect-error - this is passed from the HTML template.
7-
export const PATH_PREFIX: string = window.PATH_PREFIX;
7+
export const PATH_PREFIX: string = window.PATH_PREFIX
88
// @ts-expect-error - this is passed from the HTML template.
9-
export const API_BASEPATH: string = window.API_BASEPATH;
9+
export const API_BASEPATH: string = window.API_BASEPATH
1010
// @ts-expect-error - this is passed from the HTML template.
11-
export const PROMETHEUS_URL: string = window.PROMETHEUS_URL;
11+
export const PROMETHEUS_URL: string = window.PROMETHEUS_URL
1212

1313
const App = () => {
1414
const basename = `/${PATH_PREFIX.replace(/^\//, '').replace(/\/$/, '')}`
1515
return (
1616
<BrowserRouter basename={basename}>
1717
<Routes>
18-
<Route path="/" element={<List/>}/>
19-
<Route path="/objectives" element={<Detail/>}/>
18+
<Route path="/" element={<List />} />
19+
<Route path="/objectives" element={<Detail />} />
2020
</Routes>
2121
</BrowserRouter>
2222
)
2323
}
2424

25-
export const dateFormatter = (timeRange: number) => (t: number): string => {
26-
const date = new Date(t * 1000)
27-
const year = date.getUTCFullYear()
28-
const month = date.getUTCMonth() + 1
29-
const day = date.getUTCDate()
30-
const hour = date.getUTCHours()
31-
const minute = date.getUTCMinutes()
32-
33-
const monthLeading = month > 9 ? month : `0${month}`
34-
const dayLeading = day > 9 ? day : `0${day}`
35-
const hourLeading = hour > 9 ? hour : `0${hour}`
36-
const minuteLeading = minute > 9 ? minute : `0${minute}`
25+
export const dateFormatter =
26+
(timeRange: number) =>
27+
(t: number): string => {
28+
const date = new Date(t * 1000)
29+
const year = date.getUTCFullYear()
30+
const month = date.getUTCMonth() + 1
31+
const day = date.getUTCDate()
32+
const hour = date.getUTCHours()
33+
const minute = date.getUTCMinutes()
34+
35+
const monthLeading = month > 9 ? month : `0${month}`
36+
const dayLeading = day > 9 ? day : `0${day}`
37+
const hourLeading = hour > 9 ? hour : `0${hour}`
38+
const minuteLeading = minute > 9 ? minute : `0${minute}`
39+
40+
if (timeRange >= 24 * 3600 * 1000) {
41+
return `${year}-${monthLeading}-${dayLeading} ${hourLeading}:${minuteLeading}`
42+
}
3743

38-
if (timeRange >= 24 * 3600 * 1000) {
39-
return `${year}-${monthLeading}-${dayLeading} ${hourLeading}:${minuteLeading}`
44+
return `${hourLeading}:${minuteLeading}`
4045
}
4146

42-
return `${hourLeading}:${minuteLeading}`
43-
}
44-
4547
export const dateFormatterFull = (t: number): string => {
4648
const date = new Date(t * 1000)
4749
const year = date.getUTCFullYear()
@@ -58,77 +60,77 @@ export const dateFormatterFull = (t: number): string => {
5860
return `${year}-${monthLeading}-${dayLeading} ${hourLeading}:${minuteLeading}`
5961
}
6062

61-
export default App;
62-
63+
export default App
6364

6465
// From prometheus/prometheus
6566

6667
export const formatDuration = (d: number): string => {
67-
let ms = d;
68-
let r = '';
68+
let ms = d
69+
let r = ''
6970
if (ms === 0) {
70-
return '0s';
71+
return '0s'
7172
}
7273

7374
const f = (unit: string, mult: number, exact: boolean) => {
7475
if (exact && ms % mult !== 0) {
75-
return;
76+
return
7677
}
77-
const v = Math.floor(ms / mult);
78+
const v = Math.floor(ms / mult)
7879
if (v > 0) {
79-
r += `${v}${unit}`;
80-
ms -= v * mult;
80+
r += `${v}${unit}`
81+
ms -= v * mult
8182
}
82-
};
83+
}
8384

8485
// Only format years and weeks if the remainder is zero, as it is often
8586
// easier to read 90d than 12w6d.
86-
f('y', 1000 * 60 * 60 * 24 * 365, true);
87-
f('w', 1000 * 60 * 60 * 24 * 7, true);
87+
f('y', 1000 * 60 * 60 * 24 * 365, true)
88+
f('w', 1000 * 60 * 60 * 24 * 7, true)
8889

89-
f('d', 1000 * 60 * 60 * 24, false);
90-
f('h', 1000 * 60 * 60, false);
91-
f('m', 1000 * 60, false);
92-
f('s', 1000, false);
93-
f('ms', 1, false);
90+
f('d', 1000 * 60 * 60 * 24, false)
91+
f('h', 1000 * 60 * 60, false)
92+
f('m', 1000 * 60, false)
93+
f('s', 1000, false)
94+
f('ms', 1, false)
9495

95-
return r;
96-
};
96+
return r
97+
}
9798

9899
export const parseDuration = (durationStr: string): number | null => {
99100
if (durationStr === '') {
100-
return null;
101+
return null
101102
}
102103
if (durationStr === '0') {
103104
// Allow 0 without a unit.
104-
return 0;
105+
return 0
105106
}
106107

107-
const durationRE = /^(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?$/
108-
const matches = durationStr.match(durationRE);
108+
const durationRE =
109+
/^(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?$/
110+
const matches = durationStr.match(durationRE)
109111
if (matches === null) {
110-
return null;
112+
return null
111113
}
112114

113-
let dur = 0;
115+
let dur = 0
114116

115117
// Parse the match at pos `pos` in the regex and use `mult` to turn that
116118
// into ms, then add that value to the total parsed duration.
117119
const m = (pos: number, mult: number) => {
118120
if (matches[pos] === undefined) {
119-
return;
121+
return
120122
}
121-
const n = parseInt(matches[pos]);
122-
dur += n * mult;
123-
};
124-
125-
m(2, 1000 * 60 * 60 * 24 * 365); // y
126-
m(4, 1000 * 60 * 60 * 24 * 7); // w
127-
m(6, 1000 * 60 * 60 * 24); // d
128-
m(8, 1000 * 60 * 60); // h
129-
m(10, 1000 * 60); // m
130-
m(12, 1000); // s
131-
m(14, 1); // ms
132-
133-
return dur;
134-
};
123+
const n = parseInt(matches[pos])
124+
dur += n * mult
125+
}
126+
127+
m(2, 1000 * 60 * 60 * 24 * 365) // y
128+
m(4, 1000 * 60 * 60 * 24 * 7) // w
129+
m(6, 1000 * 60 * 60 * 24) // d
130+
m(8, 1000 * 60 * 60) // h
131+
m(10, 1000 * 60) // m
132+
m(12, 1000) // s
133+
m(14, 1) // ms
134+
135+
return dur
136+
}

0 commit comments

Comments
 (0)