import { useState, useEffect } from "react"; import { Box } from "lucide-react"; import { useTranslation } from "@termix/plugin-sdk/frontend"; import { DockerWidgetEditForm } from "./DockerWidgetEditForm"; import type { DockerWidgetConfig, WidgetComponentProps, WidgetTypeDefinition, } from "@/types/homepage-types"; import { GRID_SIZE } from "@/types/homepage-types"; import { getSSHHosts } from "@/api/ssh-host-management-api"; import type { SSHHostWithStatus } from "@/main-axios"; import { DockerManager } from "./DockerManager"; import type { SSHHost } from "@/types/index"; import { WidgetTitle } from "@/features/homepage/widgets/WidgetTitle"; function DockerWidget({ widget, config, }: WidgetComponentProps) { const { t } = useTranslation(); const [host, setHost] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (!config.hostId) { setLoading(false); return; } getSSHHosts() .then((hosts) => { const found = hosts.find( (h) => h.id === config.hostId && h.enableDocker, ); setHost(found ?? null); }) .catch(() => {}) .finally(() => setLoading(false)); }, [config.hostId]); if (!config.hostId) { return (
{t("homepage.widgetNoHostSelected")}
); } if (loading) { return (
{t("homepage.loading")}
); } if (!host) { return (
{t("homepage.widgetNoHostSelected")}
); } return (
} />
e.stopPropagation()} >
); } /** Registered by the plugin while it runs. */ export const dockerWidget: WidgetTypeDefinition = { id: "docker_widget", name: "Docker Manager", description: "Embedded Docker container manager for a configured host", category: "system", icon: , defaultConfig: { hostId: 0 }, defaultSize: { w: GRID_SIZE * 20, h: GRID_SIZE * 14 }, minSize: { w: GRID_SIZE * 10, h: GRID_SIZE * 8 }, component: DockerWidget, editFormComponent: DockerWidgetEditForm, };