2022-11-18 18:02:23 -06:00
|
|
|
import useSWR from "swr";
|
|
|
|
import { useTranslation } from "next-i18next";
|
2023-04-16 00:05:50 +01:00
|
|
|
import classNames from "classnames";
|
|
|
|
|
|
|
|
import Error from "../error";
|
2022-11-25 10:21:51 -06: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,
|
|
|
|
percent: 0
|
|
|
|
},
|
|
|
|
memory: {
|
|
|
|
used: 0,
|
|
|
|
total: 0,
|
|
|
|
free: 0,
|
|
|
|
precent: 0
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const { data, error } = useSWR(
|
|
|
|
`/api/widgets/kubernetes?${new URLSearchParams({ lang: i18n.language }).toString()}`, {
|
|
|
|
refreshInterval: 1500
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (error || data?.error) {
|
2023-04-16 00:05:50 +01:00
|
|
|
return <Error options={options} />
|
2022-11-18 18:02:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return (
|
2023-04-16 00:05:50 +01:00
|
|
|
<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",
|
|
|
|
)}>
|
2022-11-18 18:02:23 -06:00
|
|
|
<div className="flex flex-row self-center flex-wrap justify-between">
|
|
|
|
{cluster.show &&
|
2022-12-08 16:03:29 -06:00
|
|
|
<Node type="cluster" key="cluster" options={options.cluster} data={defaultData} />
|
2022-11-18 18:02:23 -06:00
|
|
|
}
|
|
|
|
{nodes.show &&
|
2022-12-08 16:03:29 -06:00
|
|
|
<Node type="node" key="nodes" options={options.nodes} data={defaultData} />
|
2022-11-18 18:02:23 -06:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-04-16 00:05:50 +01:00
|
|
|
<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",
|
|
|
|
)}>
|
2022-11-18 18:02:23 -06:00
|
|
|
<div className="flex flex-row self-center flex-wrap justify-between">
|
|
|
|
{cluster.show &&
|
2022-12-08 16:03:29 -06:00
|
|
|
<Node key="cluster" type="cluster" options={options.cluster} data={data.cluster} />
|
2022-11-18 18:02:23 -06:00
|
|
|
}
|
|
|
|
{nodes.show && data.nodes &&
|
|
|
|
data.nodes.map((node) =>
|
2022-12-08 16:03:29 -06:00
|
|
|
<Node key={node.name} type="node" options={options.nodes} data={node} />)
|
2022-11-18 18:02:23 -06:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|