diff --git a/src/components/widgets/kubernetes/node.jsx b/src/components/widgets/kubernetes/node.jsx index ba8f8b77..84371487 100644 --- a/src/components/widgets/kubernetes/node.jsx +++ b/src/components/widgets/kubernetes/node.jsx @@ -1,13 +1,9 @@ -import { FaMemory } from "react-icons/fa"; -import { FiAlertTriangle, FiCpu, FiServer } from "react-icons/fi"; +import { FiAlertTriangle, FiServer } from "react-icons/fi"; import { SiKubernetes } from "react-icons/si"; -import { useTranslation } from "next-i18next"; -import UsageBar from "../resources/usage-bar"; +import ServiceResource from "../resources/serviceResource"; export default function Node({ type, options, data }) { - const { t } = useTranslation(); - function icon() { if (type === "cluster") { return ; @@ -19,42 +15,13 @@ export default function Node({ type, options, data }) { } return ( -
-
-
- {icon()} -
-
-
- {t("common.number", { - value: data?.cpu?.percent ?? 0, - style: "unit", - unit: "percent", - maximumFractionDigits: 0, - })} -
- -
- -
-
- {t("common.bytes", { - value: data?.memory?.free ?? 0, - maximumFractionDigits: 0, - binary: true, - })} -
- -
- - {options.showLabel && ( -
- {type === "cluster" ? options.label : data.name} -
- )} -
-
-
-
+ ); } diff --git a/src/components/widgets/resources/serviceResource.jsx b/src/components/widgets/resources/serviceResource.jsx new file mode 100644 index 00000000..7e88e3c2 --- /dev/null +++ b/src/components/widgets/resources/serviceResource.jsx @@ -0,0 +1,66 @@ +import { useTranslation } from "next-i18next"; +import { FiCpu, FiServer } from "react-icons/fi"; +import { FaMemory } from "react-icons/fa"; + +import Error from "../widget/error"; + +import UsageBar from "./usage-bar"; + +/** + * Represents a service resource with optional details. + * + * @param {Object} props - The properties of the service resource. + * @param {JSX.Element} [props.icon] - The JSX element representing the icon. + * @param {string} [props.label] - The label describing the service resource. + * @param {number} [props.cpuPercent] - The CPU usage percentage. + * @param {number} [props.memFree] - The amount of free memory. + * @param {number} [props.memPercent] - The memory usage percentage. + * @param {any} [props.error] - Any additional error information. + * + * @returns {JSX.Element} - The JSX element representing the service resource. + */ +export default function ServiceResource({ icon, label, cpuPercent, memFree, memPercent, error }) { + const { t } = useTranslation(); + + const widgetIcon = icon ?? ; + + if (error) { + return ; + } + + return ( +
+
+
+
{widgetIcon}
+
+
+
+ {t("common.number", { + value: cpuPercent ?? 0, + style: "unit", + unit: "percent", + maximumFractionDigits: 0, + })} +
+ +
+ +
+
+ {t("common.bytes", { + value: memFree ?? 0, + maximumFractionDigits: 0, + binary: true, + })} +
+ +
+ + {label &&
{label}
} +
+
+
+
+ ); +}