mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-07 09:35:54 -08:00
Enhancement: Add enablePools option to TrueNAS service widget (#2908)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { useTranslation } from "next-i18next";
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
import Pool from "widgets/truenas/pool";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
@@ -11,9 +12,10 @@ export default function Component({ service }) {
|
||||
|
||||
const { data: alertData, error: alertError } = useWidgetAPI(widget, "alerts");
|
||||
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
|
||||
const { data: poolsData, error: poolsError } = useWidgetAPI(widget, "pools");
|
||||
|
||||
if (alertError || statusError) {
|
||||
const finalError = alertError ?? statusError;
|
||||
if (alertError || statusError || poolsError) {
|
||||
const finalError = alertError ?? statusError ?? poolsError;
|
||||
return <Container service={service} error={finalError} />;
|
||||
}
|
||||
|
||||
@@ -27,11 +29,19 @@ export default function Component({ service }) {
|
||||
);
|
||||
}
|
||||
|
||||
const enablePools = widget?.enablePools && Array.isArray(poolsData) && poolsData.length > 0;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="truenas.load" value={t("common.number", { value: statusData.loadavg[0] })} />
|
||||
<Block label="truenas.uptime" value={t("common.uptime", { value: statusData.uptime_seconds })} />
|
||||
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
|
||||
</Container>
|
||||
<>
|
||||
<Container service={service}>
|
||||
<Block label="truenas.load" value={t("common.number", { value: statusData.loadavg[0] })} />
|
||||
<Block label="truenas.uptime" value={t("common.uptime", { value: statusData.uptime_seconds })} />
|
||||
<Block label="truenas.alerts" value={t("common.number", { value: alertData.pending })} />
|
||||
</Container>
|
||||
{enablePools &&
|
||||
poolsData.map((pool) => (
|
||||
<Pool key={pool.id} name={pool.name} healthy={pool.healthy} allocated={pool.allocated} free={pool.free} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user