2022-08-25 14:32:53 +03:00
|
|
|
import Image from "next/future/image";
|
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-09-26 02:23:02 +03:00
|
|
|
import Docker from "widgets/docker/component";
|
2022-09-26 12:04:37 +03:00
|
|
|
import { SettingsContext } from "utils/contexts/settings";
|
2022-09-21 09:00:57 +03:00
|
|
|
|
2022-08-27 13:49:24 +03:00
|
|
|
function resolveIcon(icon) {
|
2022-10-11 15:02:38 +03:00
|
|
|
// direct or relative URLs
|
|
|
|
if (icon.startsWith("http") || icon.startsWith("/")) {
|
|
|
|
return <Image src={`${icon}`} width={32} height={32} alt="logo" />;
|
2022-09-07 16:53:24 +03:00
|
|
|
}
|
|
|
|
|
2022-10-11 15:02:38 +03:00
|
|
|
// mdi- prefixed, material design icons
|
|
|
|
if (icon.startsWith("mdi-")) {
|
|
|
|
const iconName = icon.replace("mdi-", "").replace(".svg", "");
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
|
|
|
background: "linear-gradient(180deg, rgb(var(--color-logo-start)), rgb(var(--color-logo-stop)))",
|
|
|
|
mask: `url(https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/${iconName}.svg) no-repeat center / contain`,
|
|
|
|
WebkitMask: `url(https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/${iconName}.svg) no-repeat center / contain`,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2022-09-07 16:53:24 +03:00
|
|
|
}
|
|
|
|
|
2022-10-11 15:02:38 +03:00
|
|
|
// fallback to dashboard-icons
|
|
|
|
const iconName = icon.replace(".png", "");
|
|
|
|
return (
|
|
|
|
<Image
|
|
|
|
src={`https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${iconName}.png`}
|
|
|
|
width={32}
|
|
|
|
height={32}
|
|
|
|
alt="logo"
|
|
|
|
/>
|
|
|
|
);
|
2022-08-27 13:49:24 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 09:00:57 +03:00
|
|
|
export default function Item({ service }) {
|
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);
|
2022-09-25 19:38:02 +03:00
|
|
|
const [statsOpen, setStatsOpen] = useState(false);
|
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 (
|
2022-09-02 10:55:19 +03:00
|
|
|
<li key={service.name}>
|
2022-09-25 19:38:02 +03:00
|
|
|
<div
|
|
|
|
className={`${
|
|
|
|
hasLink ? "cursor-pointer " : " "
|
2022-09-26 16:56:20 +03:00
|
|
|
}transition-all h-15 mb-3 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`}
|
2022-09-25 19:38:02 +03:00
|
|
|
>
|
|
|
|
<div className="flex select-none">
|
|
|
|
{service.icon &&
|
|
|
|
(hasLink ? (
|
2022-09-18 18:49:50 +03:00
|
|
|
<a
|
2022-09-18 16:41:01 +03:00
|
|
|
href={service.href}
|
2022-09-21 09:00:57 +03:00
|
|
|
target={settings.target ?? "_blank"}
|
2022-09-18 18:49:50 +03:00
|
|
|
rel="noreferrer"
|
2022-09-25 19:38:02 +03:00
|
|
|
className="flex-shrink-0 flex items-center justify-center w-12 "
|
2022-08-27 13:49:24 +03:00
|
|
|
>
|
2022-10-11 15:02:38 +03:00
|
|
|
{resolveIcon(service.icon)}
|
2022-09-18 18:49:50 +03:00
|
|
|
</a>
|
2022-09-12 11:55:01 +03:00
|
|
|
) : (
|
2022-10-11 15:02:38 +03:00
|
|
|
<div className="flex-shrink-0 flex items-center justify-center w-12 ">{resolveIcon(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}
|
|
|
|
target={settings.target ?? "_blank"}
|
|
|
|
rel="noreferrer"
|
|
|
|
className="flex-1 flex items-center justify-between rounded-r-md "
|
|
|
|
>
|
|
|
|
<div className="flex-1 px-2 py-2 text-sm text-left">
|
|
|
|
{service.name}
|
2022-09-26 15:25:10 +03:00
|
|
|
<p className="text-theme-500 dark:text-theme-300 text-xs font-light">{service.description}</p>
|
2022-09-25 19:38:02 +03:00
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<div className="flex-1 flex items-center justify-between rounded-r-md ">
|
|
|
|
<div className="flex-1 px-2 py-2 text-sm text-left">
|
|
|
|
{service.name}
|
2022-09-26 15:25:10 +03:00
|
|
|
<p className="text-theme-500 dark:text-theme-300 text-xs font-light">{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
|
|
|
)}
|
|
|
|
|
|
|
|
{service.container && (
|
|
|
|
<button
|
|
|
|
type="button"
|
2022-09-26 14:42:40 +03:00
|
|
|
onClick={() => (statsOpen ? closeStats() : setStatsOpen(true))}
|
2022-09-25 19:38:02 +03:00
|
|
|
className="flex-shrink-0 flex items-center justify-center w-12 cursor-pointer"
|
|
|
|
>
|
|
|
|
<Status service={service} />
|
2022-09-26 15:03:02 +03:00
|
|
|
<span className="sr-only">View container stats</span>
|
2022-09-25 19:38:02 +03:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-08-24 10:44:35 +03:00
|
|
|
|
2022-09-26 12:04:37 +03:00
|
|
|
{service.container && service.server && (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-09-26 14:42:40 +03:00
|
|
|
statsOpen && !statsClosing ? "max-h-[55px] opacity-100" : " max-h-[0] opacity-0",
|
2022-09-26 12:04:37 +03:00
|
|
|
"w-full overflow-hidden transition-all duration-300 ease-in-out"
|
|
|
|
)}
|
|
|
|
>
|
2022-09-26 14:42:40 +03:00
|
|
|
{statsOpen && <Docker service={{ widget: { container: service.container, server: service.server } }} />}
|
2022-09-26 12:04:37 +03: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>
|
|
|
|
);
|
|
|
|
}
|