From 69fad3f55f5f6d6efce61f146f0f30253ae8b9fa Mon Sep 17 00:00:00 2001 From: Victor Bayas Date: Mon, 1 Jul 2024 18:27:33 -0500 Subject: [PATCH] Improvements to Drives list UI (#3395) --- .../BasicDashboard/DriveInfoItem.tsx | 289 ++++++++++-------- 1 file changed, 165 insertions(+), 124 deletions(-) diff --git a/web-app/src/screens/Console/Dashboard/BasicDashboard/DriveInfoItem.tsx b/web-app/src/screens/Console/Dashboard/BasicDashboard/DriveInfoItem.tsx index e4f310a26..7948ba758 100644 --- a/web-app/src/screens/Console/Dashboard/BasicDashboard/DriveInfoItem.tsx +++ b/web-app/src/screens/Console/Dashboard/BasicDashboard/DriveInfoItem.tsx @@ -14,9 +14,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -import React from "react"; +import { useMemo } from "react"; import get from "lodash/get"; -import styled from "styled-components"; +import { useTheme } from "styled-components"; import { niceBytes } from "../../../../common/utils"; import { Box, breakPoints, CircleIcon, SizeChart } from "mds"; import { ServerDrives } from "api/consoleApi"; @@ -26,159 +26,200 @@ interface ICardProps { drive: ServerDrives; } -const driveStatusColor = (health_status: string) => { - switch (health_status) { - case "offline": - return STATUS_COLORS.RED; - case "ok": - return STATUS_COLORS.GREEN; - default: - return STATUS_COLORS.YELLOW; - } -}; - -const DataContainerMain = styled.div(({ theme }) => ({ - flex: 1, - display: "flex", - alignItems: "center", - paddingLeft: "20px", - marginTop: "10px", - flexFlow: "row", - "& .info-label": { - color: get(theme, "mutedText", "#87888d"), - fontSize: "12px", - textAlign: "center", - }, - "& .info-value": { - fontSize: "18px", - color: get(theme, "signalColors.main", "#07193E"), - display: "flex", - fontWeight: 500, - overflow: "hidden", - textOverflow: "ellipsis", - whiteSpace: "nowrap", - }, - [`@media (max-width: ${breakPoints.sm}px)`]: { - flexFlow: "column", - }, -})); - const DriveInfoItem = ({ drive }: ICardProps) => { - const totalSpace = drive.totalSpace || 0; - const usedSpace = drive.usedSpace || 0; + const theme = useTheme(); + + const totalSpace = drive.totalSpace ?? 0; + const usedSpace = drive.usedSpace ?? 0; + const usedPercentage = + totalSpace !== 0 ? Math.max((usedSpace / totalSpace) * 100, 0) : 0; + const availableSpace = drive.availableSpace ?? 0; + const availablePercentage = + totalSpace !== 0 ? Math.max((availableSpace / totalSpace) * 100, 0) : 0; + + const driveStatusColor = useMemo(() => { + switch (drive.state) { + case "offline": + return STATUS_COLORS.RED; + case "ok": + return STATUS_COLORS.GREEN; + default: + return STATUS_COLORS.YELLOW; + } + }, [drive.state]); + + const driveStatusText = useMemo(() => { + switch (drive.state) { + case "offline": + return "Offline Drive"; + case "ok": + return "Online Drive"; + default: + return "Unknown"; + } + }, [drive.state]); return ( + -
{drive.endpoint || ""}
- {drive.state && } -
- - - - + + + {drive.endpoint ?? ""} - + + + + + {driveStatusText} + + + + - -
- {niceBytes( - drive.totalSpace ? drive.totalSpace.toString() : "0", - )} -
- -
- - -
- {niceBytes(drive.usedSpace ? drive.usedSpace.toString() : "0")} -
- -
- -
- {niceBytes( - drive.availableSpace ? drive.availableSpace.toString() : "0", - )} -
- + + {niceBytes(usedSpace.toString())} + + + {usedPercentage.toFixed(2)}% + + of {niceBytes(totalSpace.toString())}
-
+ + + + + {niceBytes(availableSpace.toString())} + + + + {availablePercentage.toFixed(2)}% + + of {niceBytes(totalSpace.toString())} + + +
);