import { Link, useLocation } from "react-router-dom"; import type { ReactNode } from "react"; import { useQuery } from "@tanstack/react-query"; import { Button, Chip } from "@heroui/react"; import { AppsGridIcon } from "../components/AppsGridIcon"; import { HeaderMenu } from "../components/HeaderMenu"; import { getPageTitleKey, isWorkbenchPath } from "../config/modules"; import { useAppWindowRegistration } from "../hooks/useAppWindowRegistration"; import { useI18n } from "../i18n"; import { fetchOpsTasks } from "../services/api"; import { openOrFocusModule } from "../utils/moduleWindows"; import { returnToWorkbench } from "../utils/workbench"; import { useAuth } from "../auth/AuthContext"; type Props = { children: ReactNode; }; export function AppLayout({ children }: Props) { const { t } = useI18n(); const { pathname } = useLocation(); const { user, logout } = useAuth(); const onWorkbench = isWorkbenchPath(pathname); const pageTitle = t(getPageTitleKey(pathname)); const opsTasksQuery = useQuery({ queryKey: ["opsTasks"], queryFn: fetchOpsTasks, enabled: Boolean(user), // Idle installs: poll slowly; speed up only while tasks are active. refetchInterval: (q) => ((q.state.data?.active ?? 0) > 0 ? 4000 : 20_000), staleTime: 10_000, refetchOnWindowFocus: false, }); const activeTasks = opsTasksQuery.data?.active ?? 0; useAppWindowRegistration(pathname); return (
{onWorkbench ? ( NETX ) : ( NETX )} {!onWorkbench ? ( <> {pageTitle} ) : null}
{user ? (
0 ? "success" : "default"} variant="soft" className="conn-pill conn-pill--on-brand conn-pill--tasks cursor-pointer" onClick={() => openOrFocusModule({ moduleId: "audit", path: "/audit/tasks" })} > {t("layout.activeTasks", { count: activeTasks })} {user.username}
) : ( )}
{children}
); }