Skip to content

Commit ba80feb

Browse files
committed
Show percentages in Drives list UI
1 parent e3864b6 commit ba80feb

File tree

1 file changed

+159
-118
lines changed

1 file changed

+159
-118
lines changed

web-app/src/screens/Console/Dashboard/BasicDashboard/DriveInfoItem.tsx

Lines changed: 159 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This file is part of MinIO Console Server
2-
// Copyright (c) 2022 MinIO, Inc.
2+
// Copyright (c) 2024 MinIO, Inc.
33
//
44
// This program is free software: you can redistribute it and/or modify
55
// it under the terms of the GNU Affero General Public License as published by
@@ -14,9 +14,9 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import React from "react";
17+
import { useMemo } from "react";
1818
import get from "lodash/get";
19-
import styled from "styled-components";
19+
import { useTheme } from "styled-components";
2020
import { niceBytes } from "../../../../common/utils";
2121
import { Box, breakPoints, CircleIcon, SizeChart } from "mds";
2222
import { ServerDrives } from "api/consoleApi";
@@ -26,159 +26,200 @@ interface ICardProps {
2626
drive: ServerDrives;
2727
}
2828

29-
const driveStatusColor = (health_status: string) => {
30-
switch (health_status) {
31-
case "offline":
32-
return STATUS_COLORS.RED;
33-
case "ok":
34-
return STATUS_COLORS.GREEN;
35-
default:
36-
return STATUS_COLORS.YELLOW;
37-
}
38-
};
29+
const DriveInfoItem = ({ drive }: ICardProps) => {
30+
const theme = useTheme();
3931

40-
const DataContainerMain = styled.div(({ theme }) => ({
41-
flex: 1,
42-
display: "flex",
43-
alignItems: "center",
44-
paddingLeft: "20px",
45-
marginTop: "10px",
46-
flexFlow: "row",
47-
"& .info-label": {
48-
color: get(theme, "mutedText", "#87888d"),
49-
fontSize: "12px",
50-
textAlign: "center",
51-
},
52-
"& .info-value": {
53-
fontSize: "18px",
54-
color: get(theme, "signalColors.main", "#07193E"),
55-
display: "flex",
56-
fontWeight: 500,
57-
overflow: "hidden",
58-
textOverflow: "ellipsis",
59-
whiteSpace: "nowrap",
60-
},
61-
[`@media (max-width: ${breakPoints.sm}px)`]: {
62-
flexFlow: "column",
63-
},
64-
}));
32+
const totalSpace = drive.totalSpace ?? 0;
33+
const usedSpace = drive.usedSpace ?? 0;
34+
const usedPercentage = (usedSpace / totalSpace) * 100;
35+
const availableSpace = drive.availableSpace ?? 0;
36+
const availablePercentage = (availableSpace / totalSpace) * 100;
6537

66-
const DriveInfoItem = ({ drive }: ICardProps) => {
67-
const totalSpace = drive.totalSpace || 0;
68-
const usedSpace = drive.usedSpace || 0;
38+
const driveStatusColor = useMemo(() => {
39+
switch (drive.state) {
40+
case "offline":
41+
return STATUS_COLORS.RED;
42+
case "ok":
43+
return STATUS_COLORS.GREEN;
44+
default:
45+
return STATUS_COLORS.YELLOW;
46+
}
47+
}, [drive.state]);
48+
49+
const driveStatusText = useMemo(() => {
50+
switch (drive.state) {
51+
case "offline":
52+
return "Offline Drive";
53+
case "ok":
54+
return "Online Drive";
55+
default:
56+
return "Unknown";
57+
}
58+
}, [drive.state]);
6959

7060
return (
7161
<Box
7262
withBorders
7363
sx={{
7464
display: "flex",
75-
flex: 1,
65+
flexFlow: "row",
66+
padding: 12,
67+
gap: 24,
7668
alignItems: "center",
77-
paddingBottom: "10px",
78-
padding: "20px",
69+
[`@media (max-width: ${breakPoints.sm}px)`]: {
70+
padding: 24,
71+
},
72+
[`@media (max-width: ${breakPoints.xs}px)`]: {
73+
flexFlow: "column",
74+
alignItems: "start",
75+
},
76+
"& .info-label": {
77+
color: get(theme, "mutedText", "#87888d"),
78+
fontSize: 12,
79+
},
80+
"& .info-value": {
81+
fontSize: 18,
82+
color: get(theme, "signalColors.main", "#07193E"),
83+
display: "flex",
84+
fontWeight: 500,
85+
overflow: "hidden",
86+
textOverflow: "ellipsis",
87+
whiteSpace: "nowrap",
88+
},
89+
"& .drive-endpoint": {
90+
overflow: "hidden",
91+
textOverflow: "ellipsis",
92+
whiteSpace: "normal",
93+
wordBreak: "break-all",
94+
fontWeight: 600,
95+
fontSize: 16,
96+
[`@media (max-width: ${breakPoints.sm}px)`]: {
97+
fontSize: 10,
98+
},
99+
},
100+
"& .percentage-row": {
101+
display: "flex",
102+
gap: 4,
103+
alignItems: "center",
104+
fontSize: 12,
105+
"& .percentage-value": {
106+
fontWeight: 700,
107+
},
108+
},
79109
}}
80110
>
111+
<SizeChart
112+
chartLabel="Used Capacity"
113+
label={true}
114+
usedBytes={usedSpace}
115+
totalBytes={totalSpace}
116+
width={"153"}
117+
height={"153"}
118+
/>
81119
<Box
82120
sx={{
83121
display: "flex",
84122
flexFlow: "column",
85-
marginLeft: "10px",
123+
gap: 12,
86124
flex: 1,
87125
}}
88126
>
89127
<Box
90128
sx={{
91-
fontSize: "14px",
92-
fontWeight: 400,
93129
display: "flex",
94-
alignItems: "center",
95-
96-
"& .min-icon": {
97-
marginRight: "10px",
98-
height: "10px",
99-
width: "10px",
100-
fill: driveStatusColor(drive.state || ""),
101-
flexShrink: 0,
102-
},
103-
104-
"& .drive-endpoint": {
105-
overflow: "hidden",
106-
textOverflow: "ellipsis",
107-
whiteSpace: "normal",
108-
wordBreak: "break-all",
109-
marginRight: "8px",
110-
fontWeight: 600,
111-
fontSize: 16,
112-
[`@media (max-width: ${breakPoints.sm}px)`]: {
113-
fontSize: 10,
114-
},
130+
flexFlow: "row",
131+
gap: 8,
132+
[`@media (max-width: ${breakPoints.xs}px)`]: {
133+
flexFlow: "column",
115134
},
116135
}}
117136
>
118-
<div className="drive-endpoint">{drive.endpoint || ""}</div>
119-
{drive.state && <CircleIcon />}
120-
</Box>
121-
122-
<DataContainerMain>
123-
<Box sx={{ flex: 1 }}>
124-
<SizeChart
125-
label={true}
126-
usedBytes={usedSpace}
127-
totalBytes={totalSpace}
128-
width={"120"}
129-
height={"120"}
130-
/>
137+
<Box
138+
sx={{
139+
flex: "1 1 60%",
140+
[`@media (max-width: ${breakPoints.xs}px)`]: {
141+
flex: "1 1 100%",
142+
},
143+
}}
144+
>
145+
<label className="info-label">Drive Name</label>
146+
<Box className="drive-endpoint">{drive.endpoint ?? ""}</Box>
131147
</Box>
132-
133148
<Box
134149
sx={{
135-
display: "flex",
136-
gap: "5%",
137-
alignItems: "center",
138-
flex: 2,
139-
flexGrow: 1,
150+
flex: "1 1 20%",
151+
[`@media (max-width: ${breakPoints.xs}px)`]: {
152+
flex: "1 1 100%",
153+
},
140154
}}
141155
>
156+
<label className="info-label">Drive Status</label>
142157
<Box
143158
sx={{
144159
display: "flex",
145-
flexFlow: "column",
160+
flexFlow: "row",
161+
alignItems: "center",
162+
fontSize: 12,
163+
gap: 4,
164+
color: driveStatusColor,
165+
"& .min-icon": {
166+
height: 8,
167+
width: 8,
168+
flexShrink: 0,
169+
},
146170
}}
147171
>
148-
<div className="info-value">
149-
{niceBytes(
150-
drive.totalSpace ? drive.totalSpace.toString() : "0",
151-
)}
152-
</div>
153-
<label className="info-label">Capacity</label>
172+
<CircleIcon />
173+
{driveStatusText}
154174
</Box>
155-
156-
<Box
157-
sx={{
158-
display: "flex",
159-
flexFlow: "column",
160-
}}
161-
>
162-
<div className="info-value">
163-
{niceBytes(drive.usedSpace ? drive.usedSpace.toString() : "0")}
164-
</div>
165-
<label className="info-label">Used</label>
175+
</Box>
176+
</Box>
177+
<Box
178+
sx={{
179+
display: "flex",
180+
flexFlow: "row",
181+
gap: 36,
182+
}}
183+
>
184+
<Box
185+
sx={{
186+
display: "flex",
187+
flexFlow: "column",
188+
}}
189+
>
190+
<label className="info-label">Used Capacity</label>
191+
<Box className="info-value">{niceBytes(usedSpace.toString())}</Box>
192+
<Box className="percentage-row">
193+
<Box className="percentage-value">
194+
{usedPercentage.toFixed(2)}%
195+
</Box>
196+
<Box>of {niceBytes(totalSpace.toString())}</Box>
166197
</Box>
167-
<Box
168-
sx={{
169-
display: "flex",
170-
flexFlow: "column",
171-
}}
172-
>
173-
<div className="info-value">
174-
{niceBytes(
175-
drive.availableSpace ? drive.availableSpace.toString() : "0",
176-
)}
177-
</div>
178-
<label className="info-label">Available</label>
198+
</Box>
199+
<Box
200+
sx={{
201+
width: 1,
202+
backgroundColor: get(theme, "borderColor", "#BBBBBB"),
203+
}}
204+
/>
205+
<Box
206+
sx={{
207+
display: "flex",
208+
flexFlow: "column",
209+
}}
210+
>
211+
<label className="info-label">Available Capacity</label>
212+
<Box className="info-value">
213+
{niceBytes(availableSpace.toString())}
214+
</Box>
215+
<Box className="percentage-row">
216+
<Box className="percentage-value">
217+
{availablePercentage.toFixed(2)}%
218+
</Box>
219+
<Box>of {niceBytes(totalSpace.toString())}</Box>
179220
</Box>
180221
</Box>
181-
</DataContainerMain>
222+
</Box>
182223
</Box>
183224
</Box>
184225
);

0 commit comments

Comments
 (0)