From 58c7fb15ea2bfa27167189f221f72a350ab37049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20Kr=C3=B6ger?= Date: Wed, 27 Sep 2023 13:24:10 +0200 Subject: [PATCH] add ping indicator style setting --- src/components/services/item.jsx | 4 +--- src/components/services/ping.jsx | 35 +++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/components/services/item.jsx b/src/components/services/item.jsx index 6528a7b5c..aaee81cd1 100644 --- a/src/components/services/item.jsx +++ b/src/components/services/item.jsx @@ -29,8 +29,6 @@ export default function Item({ service, group }) { } }; - - return (
  • {service.ping && (
    - + Ping status
    )} diff --git a/src/components/services/ping.jsx b/src/components/services/ping.jsx index 27ea92eff..a14fa6602 100644 --- a/src/components/services/ping.jsx +++ b/src/components/services/ping.jsx @@ -1,7 +1,7 @@ import { useTranslation } from "react-i18next"; import useSWR from "swr"; -export default function Ping({ group, service }) { +export default function Ping({ group, service, style }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ group, service }).toString()}`, { refreshInterval: 30000 @@ -23,20 +23,41 @@ export default function Ping({ group, service }) { ); } - const statusText = `${service}: HTTP status ${data.status}`; - + var statusText = `HTTP status ${data.status}`; + var status; + if (data.status > 403) { + if (style === "basic") { + status = t("docker.offline") + } else if (style === "dot") { + status = "◉" + } else { + status = data.status + } + return (
    -
    {data.status}
    +
    {status}
    ); } - + + // Sucessful ping + var ping = t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", maximumFractionDigits: 0 }) + + statusText += ` (${ping})`; + + if (style === "basic") { + status = t("docker.running") + } else if (style === "dot") { + status = "◉" + } else { + status = ping + } + return (
    -
    {t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", maximumFractionDigits: 0 })}
    +
    {status}
    ); - }