2022-11-07 11:35:13 -08:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-08-24 10:44:35 +03:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
export default function Status({ service }) {
|
2022-11-07 11:35:13 -08:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2022-09-07 16:53:24 +03:00
|
|
|
const { data, error } = useSWR(`/api/docker/status/${service.container}/${service.server || ""}`);
|
2022-08-24 10:44:35 +03:00
|
|
|
|
|
|
|
if (error) {
|
2023-03-25 08:46:42 -07:00
|
|
|
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={t("docker.error")}>
|
2022-11-07 11:35:13 -08:00
|
|
|
<div className="text-[8px] font-bold text-rose-500/80 uppercase">{t("docker.error")}</div>
|
|
|
|
</div>
|
2022-08-24 10:44:35 +03:00
|
|
|
}
|
|
|
|
|
2023-03-25 08:46:42 -07:00
|
|
|
if (data) {
|
|
|
|
let statusLabel = "";
|
|
|
|
|
|
|
|
if (data.status?.includes("running")) {
|
|
|
|
if (data.health === "starting") {
|
|
|
|
return (
|
|
|
|
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={t("docker.starting")}>
|
|
|
|
<div className="text-[8px] font-bold text-blue-500/80 uppercase">{t("docker.starting")}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.health === "unhealthy") {
|
|
|
|
return (
|
|
|
|
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={t("docker.unhealthy")}>
|
|
|
|
<div className="text-[8px] font-bold text-orange-400/50 dark:text-orange-400/80 uppercase">{t("docker.unhealthy")}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data.health) {
|
|
|
|
statusLabel = data.status.replace("running", t("docker.running"))
|
|
|
|
} else {
|
|
|
|
statusLabel = data.health === "healthy" ? t("docker.healthy") : data.health
|
|
|
|
}
|
2023-03-19 22:58:47 -07:00
|
|
|
|
2022-11-27 09:46:18 -08:00
|
|
|
return (
|
2023-03-25 08:46:42 -07:00
|
|
|
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={statusLabel}>
|
|
|
|
<div className="text-[8px] font-bold text-emerald-500/80 uppercase">{statusLabel}</div>
|
2022-11-27 09:46:18 -08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-03-25 08:46:42 -07:00
|
|
|
|
|
|
|
if (data.status === "not found" || data.status === "exited" || data.status?.startsWith("partial")) {
|
|
|
|
if (data.status === "not found") statusLabel = t("docker.not_found")
|
|
|
|
else if (data.status === "exited") statusLabel = t("docker.exited")
|
|
|
|
else statusLabel = data.status.replace("partial", t("docker.partial"))
|
2022-11-27 09:46:18 -08:00
|
|
|
return (
|
2023-03-25 08:46:42 -07:00
|
|
|
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden" title={statusLabel}>
|
|
|
|
<div className="text-[8px] font-bold text-orange-400/50 dark:text-orange-400/80 uppercase">{statusLabel}</div>
|
2022-11-27 09:46:18 -08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-08-24 10:44:35 +03:00
|
|
|
}
|
|
|
|
|
2022-11-07 11:35:13 -08:00
|
|
|
return (
|
|
|
|
<div className="w-auto px-1.5 py-0.5 text-center bg-theme-500/10 dark:bg-theme-900/50 rounded-b-[3px] overflow-hidden">
|
|
|
|
<div className="text-[8px] font-bold text-black/20 dark:text-white/40 uppercase">{t("docker.unknown")}</div>
|
|
|
|
</div>
|
|
|
|
);
|
2022-08-24 10:44:35 +03:00
|
|
|
}
|