Merge pull request #2074 from LucaDev/ping-indicators

New ping-indicator styles
pull/2087/head
Ben Phelps 1 year ago committed by GitHub
commit 8893e0b1df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,8 +29,6 @@ export default function Item({ service, group }) {
} }
}; };
return ( return (
<li key={service.name} id={service.id} className="service" data-name={service.name || ""}> <li key={service.name} id={service.id} className="service" data-name={service.name || ""}>
<div <div
@ -81,7 +79,7 @@ export default function Item({ service, group }) {
<div className="absolute top-0 right-0 flex flex-row justify-end gap-2 mr-2 z-30 service-tags"> <div className="absolute top-0 right-0 flex flex-row justify-end gap-2 mr-2 z-30 service-tags">
{service.ping && ( {service.ping && (
<div className="flex-shrink-0 flex items-center justify-center service-tag service-ping"> <div className="flex-shrink-0 flex items-center justify-center service-tag service-ping">
<Ping group={group} service={service.name} /> <Ping group={group} service={service.name} style={service.statusStyle} />
<span className="sr-only">Ping status</span> <span className="sr-only">Ping status</span>
</div> </div>
)} )}

@ -1,42 +1,58 @@
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import useSWR from "swr"; import useSWR from "swr";
export default function Ping({ group, service }) { export default function Ping({ group, service, style }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ group, service }).toString()}`, { const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ group, service }).toString()}`, {
refreshInterval: 30000 refreshInterval: 30000
}); });
let textSize = "text-[8px]";
let colorClass = ""
let backgroundClass = "bg-theme-500/10 dark:bg-theme-900/50";
let statusTitle = "HTTP status";
let statusText;
if (error) { if (error) {
return ( colorClass = "text-rose-500"
<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 ping-error"> statusText = t("ping.error")
<div className="text-[8px] font-bold text-rose-500 uppercase">{t("ping.error")}</div> statusTitle += " error"
</div> } else if (!data) {
); colorClass = "text-black/20 dark:text-white/40"
} statusText = t("ping.ping")
statusTitle += " not available"
if (!data) { } else if (data.status > 403) {
return ( colorClass = "text-rose-500/80"
<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 ping-ping"> statusTitle += ` ${data.status}`
<div className="text-[8px] font-bold text-black/20 dark:text-white/40 uppercase">{t("ping.ping")}</div>
</div>
);
}
const statusText = `${service}: HTTP status ${data.status}`; if (style === "basic") {
statusText = t("docker.offline")
if (data.status > 403) { } else if (style === "dot") {
return ( statusText = "◉"
<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 ping-status-invalid" title={statusText}> textSize = "text-[14px]"
<div className="text-[8px] font-bold text-rose-500/80">{data.status}</div> backgroundClass = ""
</div> } else {
); statusText = data.status
}
} else {
const ping = t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", maximumFractionDigits: 0 })
statusTitle += ` ${data.status} (${ping})`;
colorClass = "text-emerald-500/80"
if (style === "basic") {
statusText = t("docker.running")
} else if (style === "dot") {
statusText = "◉"
textSize = "text-[14px]"
backgroundClass = ""
} else {
statusText = ping
}
} }
return ( 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 ping-status-valid" title={statusText}> <div className={`w-auto px-1.5 py-0.5 text-center rounded-b-[3px] overflow-hidden ping-status-invalid ${backgroundClass}`} title={statusTitle}>
<div className="text-[8px] font-bold text-emerald-500/80">{t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", maximumFractionDigits: 0 })}</div> <div className={`font-bold uppercase ${textSize} ${colorClass}`}>{statusText}</div>
</div> </div>
); );
} }

Loading…
Cancel
Save