Skip to content

Commit 69fad3f

Browse files
authored
Improvements to Drives list UI (#3395)
1 parent e3864b6 commit 69fad3f

File tree

1 file changed

+158
-117
lines changed

1 file changed

+158
-117
lines changed

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

Lines changed: 158 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =
35+
totalSpace !== 0 ? Math.max((usedSpace / totalSpace) * 100, 0) : 0;
36+
const availableSpace = drive.availableSpace ?? 0;
37+
const availablePercentage =
38+
totalSpace !== 0 ? Math.max((availableSpace / totalSpace) * 100, 0) : 0;
6539

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

7062
return (
7163
<Box
7264
withBorders
7365
sx={{
7466
display: "flex",
75-
flex: 1,
67+
flexFlow: "row",
68+
padding: 12,
69+
gap: 24,
7670
alignItems: "center",
77-
paddingBottom: "10px",
78-
padding: "20px",
71+
[`@media (max-width: ${breakPoints.xs}px)`]: {
72+
flexFlow: "column",
73+
alignItems: "start",
74+
},
75+
"& .info-label": {
76+
color: get(theme, "mutedText", "#87888d"),
77+
fontSize: 12,
78+
},
79+
"& .info-value": {
80+
fontSize: 18,
81+
color: get(theme, "signalColors.main", "#07193E"),
82+
display: "flex",
83+
fontWeight: 500,
84+
overflow: "hidden",
85+
textOverflow: "ellipsis",
86+
whiteSpace: "nowrap",
87+
},
88+
"& .drive-endpoint": {
89+
overflow: "hidden",
90+
textOverflow: "ellipsis",
91+
whiteSpace: "normal",
92+
wordBreak: "break-all",
93+
fontWeight: 600,
94+
fontSize: 16,
95+
[`@media (max-width: ${breakPoints.sm}px)`]: {
96+
fontSize: 10,
97+
},
98+
},
99+
"& .percentage-row": {
100+
display: "flex",
101+
gap: 4,
102+
alignItems: "center",
103+
fontSize: 12,
104+
"& .percentage-value": {
105+
fontWeight: 700,
106+
},
107+
},
79108
}}
80109
>
110+
<SizeChart
111+
chartLabel="Used Capacity"
112+
label={true}
113+
usedBytes={usedSpace}
114+
totalBytes={totalSpace}
115+
width={"153"}
116+
height={"153"}
117+
/>
81118
<Box
82119
sx={{
83120
display: "flex",
84121
flexFlow: "column",
85-
marginLeft: "10px",
122+
gap: 12,
86123
flex: 1,
87124
}}
88125
>
89126
<Box
90127
sx={{
91-
fontSize: "14px",
92-
fontWeight: 400,
93128
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-
},
129+
flexFlow: "row",
130+
gap: 8,
131+
[`@media (max-width: ${breakPoints.xs}px)`]: {
132+
flexFlow: "column",
115133
},
116134
}}
117135
>
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-
/>
136+
<Box
137+
sx={{
138+
flex: "1 1 60%",
139+
[`@media (max-width: ${breakPoints.xs}px)`]: {
140+
flex: "1 1 100%",
141+
},
142+
}}
143+
>
144+
<label className="info-label">Drive Name</label>
145+
<Box className="drive-endpoint">{drive.endpoint ?? ""}</Box>
131146
</Box>
132-
133147
<Box
134148
sx={{
135-
display: "flex",
136-
gap: "5%",
137-
alignItems: "center",
138-
flex: 2,
139-
flexGrow: 1,
149+
flex: "1 1 20%",
150+
[`@media (max-width: ${breakPoints.xs}px)`]: {
151+
flex: "1 1 100%",
152+
},
140153
}}
141154
>
155+
<label className="info-label">Drive Status</label>
142156
<Box
143157
sx={{
144158
display: "flex",
145-
flexFlow: "column",
159+
flexFlow: "row",
160+
alignItems: "center",
161+
fontSize: 12,
162+
fontWeight: 600,
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)