-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRrdpTable.tsx
79 lines (73 loc) · 2.19 KB
/
RrdpTable.tsx
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
import React, { useContext, useState } from 'react';
import { t, tryFormatNumber } from '../../core/util';
import { Rrdp } from '../../types';
import Duration from './Duration';
import { StatusContext } from '../../hooks/useStatus';
type RrdpKey = keyof Rrdp;
const RRDP_FIELDS: RrdpKey[] = [
'duration',
'status',
'notifyStatus',
'payloadStatus',
'serial',
'delta',
'snapshot_reason',
'session',
];
export default function RrdpTable() {
const { status } = useContext(StatusContext);
const [sort, setSort] = useState<RrdpKey | null>(null);
let values = Object.entries(status.rrdp);
values = values.sort((a, b) => {
if (sort === null) {
return a[0].localeCompare(b[0]);
} else if (typeof a[1][sort] === "number") {
return ((b[1][sort] as number) || 0) - ((a[1][sort] as number) || 0);
} else {
return ("" + a[1][sort]).localeCompare("" + b[1][sort])
}
});
const maxDuration = Object.values(status.rrdp).reduce(
(acc, i) => Math.max(acc, i.duration),
0
);
return (
<div id="rrdp" className="scroll-table">
<div>
<table>
<thead>
<tr>
<th
onClick={() => setSort(null)}
className={`${sort === null ? 'active' : ''}`}
>URL</th>
{RRDP_FIELDS.map((key) => (
<th key={key}
onClick={() => setSort(key)}
className={`${sort === key ? 'active' : ''}`}
>{t(`connections.${key}`)}</th>
))}
</tr>
</thead>
<tbody>
{values.map(([key, rrdp]: [string, Rrdp]) => (
<tr key={key}>
<th role="column" title={key}>
<a href={key} target="_blank" rel="noreferrer">
{key}
</a>
</th>
<td>
<Duration value={rrdp.duration} max={maxDuration} />
</td>
{RRDP_FIELDS.slice(1).map((key: RrdpKey) => (
<td key={key}>{tryFormatNumber(rrdp[key])}</td>
))}
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}