|
1 | 1 | import React, { useEffect, useState } from "react";
|
2 | 2 | import logo from "../../../assets/images/logos/logo.png";
|
3 |
| -import { |
4 |
| - Button, |
5 |
| - Table, |
6 |
| - Container, |
7 |
| - OverlayTrigger, |
8 |
| - Tooltip, |
9 |
| -} from "react-bootstrap"; |
10 |
| -import { |
11 |
| - callBackendHealth, |
12 |
| - DataIntegrity, |
13 |
| - SystemHealthData, |
14 |
| -} from "../../../background/api/api"; |
| 3 | +import { Container, OverlayTrigger, Table, Tooltip } from "react-bootstrap"; |
| 4 | +import { callBackendHealth, DataIntegrity, SystemHealthData } from "../../../background/api/api"; |
15 | 5 | import { audioOnOff, setAudioVolumeByID } from "../../../background/methods/sound";
|
16 |
| -import { logout } from "../../../background/api/auth"; |
17 | 6 | import { getDurationAsString } from "../../../background/methods/dataTypes/time";
|
18 | 7 | import { hasKey } from "../../../background/methods/dataTypes/objects/ObjectKeysTS";
|
19 | 8 | import { formatBytes } from "../../../background/methods/dataTypes/bytes";
|
20 | 9 | import { FFLoading } from "../../basicElements/Loading";
|
21 | 10 | import traffic_light from "../../../assets/images/icons/material.io/traffic_light.svg";
|
22 | 11 |
|
23 | 12 | export default function Health() {
|
24 |
| - const [systemHealthData, setSystemHealthData] = useState< |
25 |
| - SystemHealthData | null | "loading" |
26 |
| - >("loading"); |
27 |
| - const errorMsg = "not reachable"; |
| 13 | + const [systemHealthData, setSystemHealthData] = useState<SystemHealthData | null | "loading">("loading"); |
| 14 | + const errorMsg = "not reachable"; |
28 | 15 |
|
29 |
| - useEffect(() => { |
30 |
| - updateVariables(); |
31 |
| - }, []); |
| 16 | + useEffect(() => { |
| 17 | + updateVariables(); |
| 18 | + }, []); |
32 | 19 |
|
33 |
| - useEffect(() => { |
34 |
| - const timer = setTimeout(() => { |
35 |
| - updateVariables(); |
36 |
| - }, 60000); |
37 |
| - // Clear timeout if the component is unmounted |
38 |
| - return () => clearTimeout(timer); |
39 |
| - }); |
| 20 | + useEffect(() => { |
| 21 | + const timer = setTimeout(() => { |
| 22 | + updateVariables(); |
| 23 | + }, 60000); |
| 24 | + // Clear timeout if the component is unmounted |
| 25 | + return () => clearTimeout(timer); |
| 26 | + }); |
40 | 27 |
|
41 |
| - function updateVariables(): void { |
42 |
| - Promise.all([callBackendHealth()]) |
43 |
| - .then(([data]) => { |
44 |
| - setSystemHealthData(data); |
45 |
| - }) |
46 |
| - .catch(() => { |
47 |
| - setSystemHealthData(null); |
48 |
| - }); |
49 |
| - } |
50 |
| - |
51 |
| - function getPathOfDataIntegrity(dataIntegrity: string): string { |
52 |
| - if (hasKey(DataIntegrity, dataIntegrity)) { |
53 |
| - return DataIntegrity[dataIntegrity]; |
| 28 | + function updateVariables(): void { |
| 29 | + Promise.all([callBackendHealth()]) |
| 30 | + .then(([data]) => { |
| 31 | + setSystemHealthData(data); |
| 32 | + }) |
| 33 | + .catch(() => { |
| 34 | + setSystemHealthData(null); |
| 35 | + }); |
54 | 36 | }
|
55 |
| - console.log("[HEALTH] Couldn't parse SystemHealth string to enum."); |
56 |
| - return errorMsg; |
57 |
| - } |
58 | 37 |
|
59 |
| - function HealthContainer(): JSX.Element { |
60 |
| - if (systemHealthData === null) { |
61 |
| - return <p>{errorMsg}</p>; |
| 38 | + function getPathOfDataIntegrity(dataIntegrity: string): string { |
| 39 | + if (hasKey(DataIntegrity, dataIntegrity)) { |
| 40 | + return DataIntegrity[dataIntegrity]; |
| 41 | + } |
| 42 | + console.log("[HEALTH] Couldn't parse SystemHealth string to enum."); |
| 43 | + return errorMsg; |
62 | 44 | }
|
63 |
| - if (systemHealthData === "loading") { |
64 |
| - return <FFLoading />; |
65 |
| - } else { |
66 |
| - return ( |
67 |
| - <Container> |
68 |
| - <div> |
69 |
| - <Table striped bordered hover id={"ff-heath-table"}> |
70 |
| - <thead> |
71 |
| - <tr> |
72 |
| - <th>System Health</th> |
73 |
| - </tr> |
74 |
| - </thead> |
75 |
| - <tbody> |
76 |
| - <tr> |
77 |
| - <td>Deployment Type</td> |
78 |
| - <td>{systemHealthData.deployment}</td> |
79 |
| - </tr> |
80 |
| - <tr> |
81 |
| - <td>Version</td> |
82 |
| - <td>{systemHealthData.version}</td> |
83 |
| - </tr> |
84 |
| - <tr> |
85 |
| - <td>Uptime</td> |
86 |
| - <td> |
87 |
| - {getDurationAsString(systemHealthData.uptimeInSeconds)} |
88 |
| - </td> |
89 |
| - </tr> |
90 |
| - <tr> |
91 |
| - <td>Usercount</td> |
92 |
| - <td>{systemHealthData.userCount}</td> |
93 |
| - </tr> |
94 |
| - <tr> |
95 |
| - <td>Used Storage</td> |
96 |
| - <td>{formatBytes(systemHealthData.usedStorageInBytes)}</td> |
97 |
| - </tr> |
98 |
| - <tr> |
99 |
| - <td>Data Integrity</td> |
100 |
| - <td> |
101 |
| - <OverlayTrigger |
102 |
| - placement="right" |
103 |
| - delay={{ show: 250, hide: 400 }} |
104 |
| - overlay={ |
105 |
| - <Tooltip id="button-tooltip" className={"pl-3"}> |
106 |
| - {systemHealthData.dataIntegrity} |
107 |
| - </Tooltip> |
108 |
| - } |
109 |
| - > |
110 |
| - <img |
111 |
| - className={getPathOfDataIntegrity( |
112 |
| - systemHealthData.dataIntegrity |
113 |
| - )} |
114 |
| - src={traffic_light} |
115 |
| - alt={systemHealthData.dataIntegrity} |
116 |
| - /> |
117 |
| - </OverlayTrigger> |
118 |
| - </td> |
119 |
| - </tr> |
120 |
| - </tbody> |
121 |
| - </Table> |
122 |
| - </div> |
123 |
| - <Button onClick={() => logout()}>Logout</Button> |
124 |
| - </Container> |
125 |
| - ); |
| 45 | + |
| 46 | + function HealthContainer(): JSX.Element { |
| 47 | + if (systemHealthData === null) { |
| 48 | + return <p>{errorMsg}</p>; |
| 49 | + } |
| 50 | + if (systemHealthData === "loading") { |
| 51 | + return <FFLoading />; |
| 52 | + } else { |
| 53 | + return ( |
| 54 | + <Container> |
| 55 | + <Table striped bordered hover id={"ff-heath-table"}> |
| 56 | + <thead> |
| 57 | + <tr> |
| 58 | + <th>System Health</th> |
| 59 | + </tr> |
| 60 | + </thead> |
| 61 | + <tbody> |
| 62 | + <tr> |
| 63 | + <td>Deployment Type</td> |
| 64 | + <td>{systemHealthData.deployment}</td> |
| 65 | + </tr> |
| 66 | + <tr> |
| 67 | + <td>Version</td> |
| 68 | + <td>{systemHealthData.version}</td> |
| 69 | + </tr> |
| 70 | + <tr> |
| 71 | + <td>Uptime</td> |
| 72 | + <td> |
| 73 | + {getDurationAsString(systemHealthData.uptimeInSeconds)} |
| 74 | + </td> |
| 75 | + </tr> |
| 76 | + <tr> |
| 77 | + <td>Usercount</td> |
| 78 | + <td>{systemHealthData.userCount}</td> |
| 79 | + </tr> |
| 80 | + <tr> |
| 81 | + <td>Used Storage</td> |
| 82 | + <td>{formatBytes(systemHealthData.usedStorageInBytes)}</td> |
| 83 | + </tr> |
| 84 | + <tr> |
| 85 | + <td>Data Integrity</td> |
| 86 | + <td> |
| 87 | + <OverlayTrigger |
| 88 | + placement="right" |
| 89 | + delay={{ show: 250, hide: 400 }} |
| 90 | + overlay={ |
| 91 | + <Tooltip id="button-tooltip" className={"pl-3"}> |
| 92 | + {systemHealthData.dataIntegrity} |
| 93 | + </Tooltip> |
| 94 | + } |
| 95 | + > |
| 96 | + <img |
| 97 | + className={getPathOfDataIntegrity( |
| 98 | + systemHealthData.dataIntegrity |
| 99 | + )} |
| 100 | + src={traffic_light} |
| 101 | + alt={systemHealthData.dataIntegrity} |
| 102 | + /> |
| 103 | + </OverlayTrigger> |
| 104 | + </td> |
| 105 | + </tr> |
| 106 | + </tbody> |
| 107 | + </Table> |
| 108 | + </Container> |
| 109 | + ); |
| 110 | + } |
126 | 111 | }
|
127 |
| - } |
128 | 112 |
|
129 |
| - return ( |
130 |
| - <Container> |
131 |
| - <h1>FileFighter</h1> |
| 113 | + return ( |
| 114 | + <Container> |
| 115 | + <h1>FileFighter</h1> |
132 | 116 |
|
133 |
| - <img |
134 |
| - src={logo} |
135 |
| - alt="Logo FileFighter" |
136 |
| - onClick={() => { |
137 |
| - setAudioVolumeByID("audio_viking", 0.5); |
138 |
| - audioOnOff("audio_viking"); |
139 |
| - }} |
140 |
| - /> |
| 117 | + <img |
| 118 | + src={logo} |
| 119 | + alt="Logo FileFighter" |
| 120 | + onClick={() => { |
| 121 | + setAudioVolumeByID("audio_viking", 0.5); |
| 122 | + audioOnOff("audio_viking"); |
| 123 | + }} |
| 124 | + /> |
141 | 125 |
|
142 |
| - <HealthContainer /> |
143 |
| - </Container> |
144 |
| - ); |
| 126 | + <HealthContainer /> |
| 127 | + </Container> |
| 128 | + ); |
145 | 129 | }
|
0 commit comments