import { useEffect, useState } from "react"; import type { ApiSettings } from "@govoplan/core-webui"; import { fetchAdminOverview, type AdminOverview } from "../../api/admin"; import { Card, MetricCard } from "@govoplan/core-webui"; import { Button } from "@govoplan/core-webui"; import { AdminPageLayout, DocumentationHelpLink, adminErrorMessage } from "@govoplan/core-webui"; import { ADMIN_INTERFACE_I18N, ADMIN_WORKSPACE_DOCUMENTATION } from "./interfacePatterns"; export default function AdminOverviewPanel({ settings, onSelect, availableSections }: {settings: ApiSettings;onSelect: (section: string) => void;availableSections: ReadonlySet;}) { const [overview, setOverview] = useState(null); const [error, setError] = useState(""); const [loading, setLoading] = useState(true); async function load() { setLoading(true); setError(""); try {setOverview(await fetchAdminOverview(settings));} catch (err) {setError(adminErrorMessage(err));} finally {setLoading(false);} } useEffect(() => {void load();}, [settings.accessToken, settings.apiBaseUrl]); const hasSystemMetrics = Boolean(overview && [ overview.tenant_count, overview.system_account_count, overview.system_group_template_count, overview.system_role_template_count]. some((value) => value !== null && value !== undefined)); return ( }> {overview && <> {hasSystemMetrics && <>
i18n:govoplan-admin.system.bc0792d8
} {hasAnySection(availableSections, platformSectionIds) &&
{availableSections.has("system-modules") && onSelect("system-modules")} />} {availableSections.has("system-configuration-packages") && onSelect("system-configuration-packages")} />} {availableSections.has("system-settings") && onSelect("system-settings")} />} {availableSections.has("system-configuration-changes") && onSelect("system-configuration-changes")} />} {availableSections.has("system-audit") && onSelect("system-audit")} />}
} {hasAnySection(availableSections, globalSectionIds) &&
{availableSections.has("system-tenants") && onSelect("system-tenants")} />} {availableSections.has("system-roles") && onSelect("system-roles")} />} {availableSections.has("system-role-templates") && onSelect("system-role-templates")} />} {availableSections.has("system-groups") && onSelect("system-groups")} />} {availableSections.has("system-users") && onSelect("system-users")} />} {availableSections.has("system-file-connectors") && onSelect("system-file-connectors")} />} {availableSections.has("system-mail-servers") && onSelect("system-mail-servers")} />} {availableSections.has("system-retention") && onSelect("system-retention")} />}
}
i18n:govoplan-admin.active_tenant.dfadf0aa {overview.active_tenant_name}
{hasAnySection(availableSections, tenantSectionIds) &&
{availableSections.has("tenant-roles") && onSelect("tenant-roles")} />} {availableSections.has("tenant-groups") && onSelect("tenant-groups")} />} {availableSections.has("tenant-users") && onSelect("tenant-users")} />} {availableSections.has("tenant-file-connectors") && onSelect("tenant-file-connectors")} />} {availableSections.has("tenant-mail-servers") && onSelect("tenant-mail-servers")} />} {availableSections.has("tenant-api-keys") && onSelect("tenant-api-keys")} />} {availableSections.has("tenant-retention") && onSelect("tenant-retention")} />} {availableSections.has("tenant-settings") && onSelect("tenant-settings")} />} {availableSections.has("tenant-audit") && onSelect("tenant-audit")} />}
} {hasAnySection(availableSections, groupSectionIds) &&
{availableSections.has("tenant-group-file-connectors") && onSelect("tenant-group-file-connectors")} />} {availableSections.has("tenant-group-mail-servers") && onSelect("tenant-group-mail-servers")} />} {availableSections.has("tenant-group-retention") && onSelect("tenant-group-retention")} />}
} {hasAnySection(availableSections, userSectionIds) &&
{availableSections.has("tenant-user-file-connectors") && onSelect("tenant-user-file-connectors")} />} {availableSections.has("tenant-user-mail-servers") && onSelect("tenant-user-mail-servers")} />} {availableSections.has("tenant-user-retention") && onSelect("tenant-user-retention")} />}
} }
); } const platformSectionIds = ["system-modules", "system-configuration-packages", "system-settings", "system-configuration-changes", "system-audit"]; const globalSectionIds = ["system-tenants", "system-roles", "system-role-templates", "system-groups", "system-users", "system-file-connectors", "system-mail-servers", "system-retention"]; const tenantSectionIds = ["tenant-roles", "tenant-groups", "tenant-users", "tenant-file-connectors", "tenant-mail-servers", "tenant-api-keys", "tenant-retention", "tenant-settings", "tenant-audit"]; const groupSectionIds = ["tenant-group-file-connectors", "tenant-group-mail-servers", "tenant-group-retention"]; const userSectionIds = ["tenant-user-file-connectors", "tenant-user-mail-servers", "tenant-user-retention"]; function hasAnySection(sections: ReadonlySet, candidates: readonly string[]): boolean { return candidates.some((section) => sections.has(section)); } function Metric({ title, value, text }: {title: string;value: string | number;text: string;}) { return ; } function AreaLink({ title, text, onClick }: {title: string;text: string;onClick: () => void;}) { return ; }