2022-09-25 19:38:02 +03:00
|
|
|
import classNames from "classnames";
|
|
|
|
import { useContext, useState } from "react";
|
2022-08-24 10:44:35 +03:00
|
|
|
|
|
|
|
import Status from "./status";
|
|
|
|
import Widget from "./widget";
|
2022-11-07 11:35:13 -08:00
|
|
|
import Ping from "./ping";
|
2023-10-20 00:09:33 -07:00
|
|
|
import SiteMonitor from "./site-monitor";
|
2022-10-24 17:03:35 -05:00
|
|
|
import KubernetesStatus from "./kubernetes-status";
|
2022-08-24 10:44:35 +03:00
|
|
|
|
2022-09-26 02:23:02 +03:00
|
|
|
import Docker from "widgets/docker/component";
|
2022-10-24 17:03:35 -05:00
|
|
|
import Kubernetes from "widgets/kubernetes/component";
|
2022-09-26 12:04:37 +03:00
|
|
|
import { SettingsContext } from "utils/contexts/settings";
|
2022-11-04 17:38:33 -04:00
|
|
|
import ResolvedIcon from "components/resolvedicon";
|
2022-08-27 13:49:24 +03:00
|
|
|
|
2023-12-06 22:52:02 +00:00
|
|
|
export default function Item({ service, group, useEqualHeights }) {
|
2022-09-12 11:55:01 +03:00
|
|
|
const hasLink = service.href && service.href !== "#";
|
2022-09-21 09:00:57 +03:00
|
|
|
const { settings } = useContext(SettingsContext);
|
2023-10-17 23:26:55 -07:00
|
|
|
const showStats = service.showStats === false ? false : settings.showStats;
|
|
|
|
const statusStyle = service.statusStyle !== undefined ? service.statusStyle : settings.statusStyle;
|
2023-04-07 20:16:35 -07:00
|
|
|
const [statsOpen, setStatsOpen] = useState(service.showStats);
|
2022-09-26 14:42:40 +03:00
|
|
|
const [statsClosing, setStatsClosing] = useState(false);
|
|
|
|
|
|
|
|
// set stats to closed after 300ms
|
|
|
|
const closeStats = () => {
|
|
|
|
if (statsOpen) {
|
|
|
|
setStatsClosing(true);
|
|
|
|
setTimeout(() => {
|
|
|
|
setStatsOpen(false);
|
|
|
|
setStatsClosing(false);
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
};
|
2022-09-12 11:55:01 +03:00
|
|
|
|
2022-08-24 10:44:35 +03:00
|
|
|
return (
|
2023-09-10 23:36:54 +02:00
|
|
|
<li key={service.name} id={service.id} className="service" data-name={service.name || ""}>
|
2022-09-25 19:38:02 +03:00
|
|
|
<div
|
2023-08-04 06:09:35 +02:00
|
|
|
className={classNames(
|
2023-10-17 23:26:55 -07:00
|
|
|
settings.cardBlur !== undefined && `backdrop-blur${settings.cardBlur.length ? "-" : ""}${settings.cardBlur}`,
|
2023-08-04 06:09:35 +02:00
|
|
|
hasLink && "cursor-pointer",
|
2023-12-06 22:52:02 +00:00
|
|
|
useEqualHeights && "h-[calc(100%-0.5rem)]",
|
|
|
|
"transition-all mb-2 p-1 rounded-md font-medium text-theme-700 dark:text-theme-200 dark:hover:text-theme-300 shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 hover:bg-theme-300/20 dark:bg-white/5 dark:hover:bg-white/10 relative overflow-clip service-card",
|
2023-08-04 06:09:35 +02:00
|
|
|
)}
|
2022-09-25 19:38:02 +03:00
|
|
|
>
|
2023-09-10 23:36:54 +02:00
|
|
|
<div className="flex select-none z-0 service-title">
|
2022-09-25 19:38:02 +03:00
|
|
|
{service.icon &&
|
|
|
|
(hasLink ? (
|
2022-09-18 18:49:50 +03:00
|
|
|
<a
|
2022-09-18 16:41:01 +03:00
|
|
|
href={service.href}
|
2022-10-20 17:52:37 -04:00
|
|
|
target={service.target ?? settings.target ?? "_blank"}
|
2022-09-18 18:49:50 +03:00
|
|
|
rel="noreferrer"
|
2023-09-10 23:36:54 +02:00
|
|
|
className="flex-shrink-0 flex items-center justify-center w-12 service-icon"
|
2022-08-27 13:49:24 +03:00
|
|
|
>
|
2022-11-04 17:38:33 -04:00
|
|
|
<ResolvedIcon icon={service.icon} />
|
2022-09-18 18:49:50 +03:00
|
|
|
</a>
|
2022-09-12 11:55:01 +03:00
|
|
|
) : (
|
2023-09-10 23:36:54 +02:00
|
|
|
<div className="flex-shrink-0 flex items-center justify-center w-12 service-icon">
|
2022-11-04 17:38:33 -04:00
|
|
|
<ResolvedIcon icon={service.icon} />
|
|
|
|
</div>
|
2022-09-25 19:38:02 +03:00
|
|
|
))}
|
2022-08-27 13:49:24 +03:00
|
|
|
|
2022-09-25 19:38:02 +03:00
|
|
|
{hasLink ? (
|
|
|
|
<a
|
|
|
|
href={service.href}
|
2022-10-20 17:52:37 -04:00
|
|
|
target={service.target ?? settings.target ?? "_blank"}
|
2022-09-25 19:38:02 +03:00
|
|
|
rel="noreferrer"
|
2023-09-10 23:36:54 +02:00
|
|
|
className="flex-1 flex items-center justify-between rounded-r-md service-title-text"
|
2022-09-25 19:38:02 +03:00
|
|
|
>
|
2023-09-10 23:36:54 +02:00
|
|
|
<div className="flex-1 px-2 py-2 text-sm text-left z-10 service-name">
|
2022-09-25 19:38:02 +03:00
|
|
|
{service.name}
|
2023-10-17 23:26:55 -07:00
|
|
|
<p className="text-theme-500 dark:text-theme-300 text-xs font-light service-description">
|
|
|
|
{service.description}
|
|
|
|
</p>
|
2022-09-25 19:38:02 +03:00
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
) : (
|
2023-09-10 23:36:54 +02:00
|
|
|
<div className="flex-1 flex items-center justify-between rounded-r-md service-title-text">
|
|
|
|
<div className="flex-1 px-2 py-2 text-sm text-left z-10 service-name">
|
2022-09-25 19:38:02 +03:00
|
|
|
{service.name}
|
2023-10-17 23:26:55 -07:00
|
|
|
<p className="text-theme-500 dark:text-theme-300 text-xs font-light service-description">
|
|
|
|
{service.description}
|
|
|
|
</p>
|
2022-09-25 19:38:02 +03:00
|
|
|
</div>
|
2022-08-24 10:44:35 +03:00
|
|
|
</div>
|
2022-09-25 19:38:02 +03:00
|
|
|
)}
|
|
|
|
|
2023-10-17 23:26:55 -07:00
|
|
|
<div
|
|
|
|
className={`absolute top-0 right-0 flex flex-row justify-end ${
|
|
|
|
statusStyle === "dot" ? "gap-0" : "gap-2 mr-2"
|
|
|
|
} z-30 service-tags`}
|
|
|
|
>
|
|
|
|
{service.ping && (
|
|
|
|
<div className="flex-shrink-0 flex items-center justify-center service-tag service-ping">
|
|
|
|
<Ping group={group} service={service.name} style={statusStyle} />
|
|
|
|
<span className="sr-only">Ping status</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-11-07 11:35:13 -08:00
|
|
|
|
2023-10-20 00:09:33 -07:00
|
|
|
{service.siteMonitor && (
|
|
|
|
<div className="flex-shrink-0 flex items-center justify-center service-tag service-site-monitor">
|
|
|
|
<SiteMonitor group={group} service={service.name} style={statusStyle} />
|
|
|
|
<span className="sr-only">Site monitor status</span>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2023-10-17 23:26:55 -07:00
|
|
|
{service.container && (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => (statsOpen ? closeStats() : setStatsOpen(true))}
|
|
|
|
className="flex-shrink-0 flex items-center justify-center cursor-pointer service-tag service-container-stats"
|
|
|
|
>
|
|
|
|
<Status service={service} style={statusStyle} />
|
|
|
|
<span className="sr-only">View container stats</span>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{service.app && !service.external && (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => (statsOpen ? closeStats() : setStatsOpen(true))}
|
|
|
|
className="flex-shrink-0 flex items-center justify-center cursor-pointer service-tag service-app"
|
|
|
|
>
|
|
|
|
<KubernetesStatus service={service} style={statusStyle} />
|
|
|
|
<span className="sr-only">View container stats</span>
|
|
|
|
</button>
|
|
|
|
)}
|
2022-11-07 11:35:13 -08:00
|
|
|
</div>
|
2022-09-25 19:38:02 +03:00
|
|
|
</div>
|
2022-08-24 10:44:35 +03:00
|
|
|
|
2022-09-26 12:04:37 +03:00
|
|
|
{service.container && service.server && (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2023-04-07 20:16:35 -07:00
|
|
|
showStats || (statsOpen && !statsClosing) ? "max-h-[110px] opacity-100" : " max-h-[0] opacity-0",
|
2023-10-17 23:26:55 -07:00
|
|
|
"w-full overflow-hidden transition-all duration-300 ease-in-out service-stats",
|
2022-09-26 12:04:37 +03:00
|
|
|
)}
|
|
|
|
>
|
2023-10-17 23:26:55 -07:00
|
|
|
{(showStats || statsOpen) && (
|
|
|
|
<Docker service={{ widget: { container: service.container, server: service.server } }} />
|
|
|
|
)}
|
2022-09-26 12:04:37 +03:00
|
|
|
</div>
|
|
|
|
)}
|
2022-10-24 17:03:35 -05:00
|
|
|
{service.app && (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2023-04-07 20:16:35 -07:00
|
|
|
showStats || (statsOpen && !statsClosing) ? "max-h-[55px] opacity-100" : " max-h-[0] opacity-0",
|
2023-10-17 23:26:55 -07:00
|
|
|
"w-full overflow-hidden transition-all duration-300 ease-in-out service-stats",
|
2022-10-24 17:03:35 -05:00
|
|
|
)}
|
|
|
|
>
|
2023-10-17 23:26:55 -07:00
|
|
|
{(showStats || statsOpen) && (
|
|
|
|
<Kubernetes
|
|
|
|
service={{
|
|
|
|
widget: { namespace: service.namespace, app: service.app, podSelector: service.podSelector },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2022-10-24 17:03:35 -05:00
|
|
|
</div>
|
|
|
|
)}
|
2022-09-25 19:38:02 +03:00
|
|
|
|
|
|
|
{service.widget && <Widget service={service} />}
|
|
|
|
</div>
|
2022-08-24 10:44:35 +03:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|