import Block from "components/services/widget/block"; import Container from "components/services/widget/container"; import { useTranslation } from "next-i18next"; import useWidgetAPI from "utils/proxy/use-widget-api"; const MAX_ALLOWED_FIELDS = 4; export default function Component({ service }) { const { t } = useTranslation(); const { widget } = service; const containersEndpoint = !(!widget.showSummary && widget.showStacks) ? "containers" : ""; const { data: containersData, error: containersError } = useWidgetAPI(widget, containersEndpoint); const stacksEndpoint = widget.showSummary || widget.showStacks ? "stacks" : ""; const { data: stacksData, error: stacksError } = useWidgetAPI(widget, stacksEndpoint); const serversEndpoint = widget.showSummary ? "servers" : ""; const { data: serversData, error: serversError } = useWidgetAPI(widget, serversEndpoint); if (containersError || stacksError || serversError) { return ; } if (!widget.fields || widget.fields.length === 0) { widget.fields = widget.showSummary ? ["servers", "stacks", "containers"] : widget.showStacks ? ["total", "running", "down", "unhealthy"] : ["total", "running", "stopped", "unhealthy"]; } else if (widget.fields?.length > MAX_ALLOWED_FIELDS) { widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS); } if ( (!widget.showStacks && !containersData) || (widget.showSummary && (!containersData || !stacksData || !serversData)) || (widget.showStacks && !stacksData) ) { return widget.showSummary ? ( ) : widget.showStacks ? ( ) : ( ); } return widget.showSummary ? ( ) : widget.showStacks ? ( ) : ( ); }