Refactored information widgets, improve widget-boxed style

Signed-off-by: Denis Papec <denis.papec@gmail.com>
This commit is contained in:
Denis Papec
2023-06-03 01:10:15 +01:00
parent c5b6dcc1e0
commit cd5162e39c
37 changed files with 701 additions and 858 deletions

View File

@@ -1,7 +1,8 @@
import useSWR from "swr";
import classNames from "classnames";
import Error from "../error";
import Error from "../widget/error";
import Container from "../widget/container";
import Raw from "../widget/raw";
import Node from "./node";
@@ -16,21 +17,15 @@ export default function Longhorn({ options }) {
}
if (!data) {
return (
<div className={classNames(
"flex flex-col max-w:full sm:basis-auto self-center grow-0 flex-wrap",
options?.styleBoxed === true && " ml-4 mt-2 m:mb-0 rounded-md shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 dark:bg-white/5 p-3",
)}>
return <Container options={options}>
<Raw>
<div className="flex flex-row self-center flex-wrap justify-between" />
</div>
);
</Raw>
</Container>;
}
return (
<div className={classNames(
"flex flex-col max-w:full sm:basis-auto self-center grow-0 flex-wrap",
options?.styleBoxed === true && " ml-4 mt-2 m:mb-0 rounded-md shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 dark:bg-white/5 p-3",
)}>
return <Container options={options}>
<Raw>
<div className="flex flex-row self-center flex-wrap justify-between">
{data.nodes
.filter((node) => {
@@ -51,6 +46,6 @@ export default function Longhorn({ options }) {
</div>
)}
</div>
</div>
);
</Raw>
</Container>;
}

View File

@@ -1,32 +1,23 @@
import { FiHardDrive } from "react-icons/fi";
import { useTranslation } from "next-i18next";
import { FaThermometerHalf } from "react-icons/fa";
import UsageBar from "../resources/usage-bar";
import SingleResource from "../widget/single_resource";
import WidgetIcon from "../widget/widget_icon";
import ResourceValue from "../widget/resource_value";
import ResourceLabel from "../widget/resource_label";
import WidgetLabel from "../widget/widget_label";
export default function Node({ data, expanded, labels }) {
const { t } = useTranslation();
return (
<>
<div className="flex-none flex flex-row items-center mr-3 py-1.5">
<FiHardDrive className="text-theme-800 dark:text-theme-200 w-5 h-5" />
<div className="flex flex-col ml-3 text-left min-w-[85px]">
<span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between">
<div className="pl-0.5">{t("common.bytes", { value: data.node.available })}</div>
<div className="pr-1">{t("resources.free")}</div>
</span>
{expanded && (
<span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between">
<div className="pl-0.5">{t("common.bytes", { value: data.node.maximum })}</div>
<div className="pr-1">{t("resources.total")}</div>
</span>
)}
<UsageBar percent={Math.round(((data.node.maximum - data.node.available) / data.node.maximum) * 100)} />
</div>
</div>
{labels && (
<div className="ml-6 pt-1 text-center text-theme-800 dark:text-theme-200 text-xs">{data.node.id}</div>
)}
</>
);
return <SingleResource expanded={expanded}>
<WidgetIcon icon={FaThermometerHalf} />
<ResourceValue>{t("common.bytes", { value: data.node.available })}</ResourceValue>
<ResourceLabel>{t("resources.free")}</ResourceLabel>
<ResourceValue>{t("common.bytes", { value: data.node.maximum })}</ResourceValue>
<ResourceLabel>{t("resources.total")}</ResourceLabel>
<UsageBar percent={Math.round(((data.node.maximum - data.node.available) / data.node.maximum) * 100)} />
{ labels && <WidgetLabel label={data.node.id} /> }
</SingleResource>
}