2022-11-18 18:02:23 -06:00
|
|
|
import { useTranslation } from "next-i18next";
|
2025-03-30 21:40:03 -07:00
|
|
|
import useSWR from "swr";
|
2023-04-16 00:05:50 +01:00
|
|
|
|
2023-06-03 01:10:15 +01:00
|
|
|
import Container from "../widget/container";
|
2025-03-30 21:40:03 -07:00
|
|
|
import Error from "../widget/error";
|
2023-06-03 01:10:15 +01:00
|
|
|
import Raw from "../widget/raw";
|
2023-04-16 00:05:50 +01:00
|
|
|
|
2022-11-18 18:02:23 -06:00
|
|
|
import Node from "./node";
|
|
|
|
|
|
|
|
export default function Widget({ options }) {
|
|
|
|
const { cluster, nodes } = options;
|
2023-04-16 00:05:50 +01:00
|
|
|
const { i18n } = useTranslation();
|
2022-11-18 18:02:23 -06:00
|
|
|
|
|
|
|
const defaultData = {
|
|
|
|
cpu: {
|
|
|
|
load: 0,
|
|
|
|
total: 0,
|
2023-10-17 23:26:55 -07:00
|
|
|
percent: 0,
|
2022-11-18 18:02:23 -06:00
|
|
|
},
|
|
|
|
memory: {
|
|
|
|
used: 0,
|
|
|
|
total: 0,
|
|
|
|
free: 0,
|
2023-10-17 23:26:55 -07:00
|
|
|
percent: 0,
|
|
|
|
},
|
2022-11-18 18:02:23 -06:00
|
|
|
};
|
|
|
|
|
2023-10-18 11:44:26 -07:00
|
|
|
const { data, error } = useSWR(`/api/widgets/kubernetes?${new URLSearchParams({ lang: i18n.language }).toString()}`, {
|
2023-10-17 23:26:55 -07:00
|
|
|
refreshInterval: 1500,
|
|
|
|
});
|
2022-11-18 18:02:23 -06:00
|
|
|
|
|
|
|
if (error || data?.error) {
|
2023-10-17 23:26:55 -07:00
|
|
|
return <Error options={options} />;
|
2022-11-18 18:02:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!data) {
|
2023-10-17 23:26:55 -07:00
|
|
|
return (
|
|
|
|
<Container options={options} additionalClassNames="information-widget-kubernetes">
|
|
|
|
<Raw>
|
|
|
|
<div className="flex flex-row self-center flex-wrap justify-between">
|
|
|
|
{cluster.show && <Node type="cluster" key="cluster" options={options.cluster} data={defaultData} />}
|
|
|
|
{nodes.show && <Node type="node" key="nodes" options={options.nodes} data={defaultData} />}
|
|
|
|
</div>
|
|
|
|
</Raw>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container options={options} additionalClassNames="information-widget-kubernetes">
|
2023-06-03 01:10:15 +01:00
|
|
|
<Raw>
|
2022-11-18 18:02:23 -06:00
|
|
|
<div className="flex flex-row self-center flex-wrap justify-between">
|
2023-10-17 23:26:55 -07:00
|
|
|
{cluster.show && <Node key="cluster" type="cluster" options={options.cluster} data={data.cluster} />}
|
2022-11-18 18:02:23 -06:00
|
|
|
{nodes.show &&
|
2023-10-17 23:26:55 -07:00
|
|
|
data.nodes &&
|
|
|
|
data.nodes.map((node) => <Node key={node.name} type="node" options={options.nodes} data={node} />)}
|
2022-11-18 18:02:23 -06:00
|
|
|
</div>
|
2023-06-03 01:10:15 +01:00
|
|
|
</Raw>
|
2023-10-17 23:26:55 -07:00
|
|
|
</Container>
|
|
|
|
);
|
2022-11-18 18:02:23 -06:00
|
|
|
}
|