diff --git a/frontend/src/components/detail/DetailHeaderMeta.jsx b/frontend/src/components/detail/DetailHeaderMeta.jsx new file mode 100644 index 00000000..75ae1779 --- /dev/null +++ b/frontend/src/components/detail/DetailHeaderMeta.jsx @@ -0,0 +1,28 @@ +import InfoTip from '@/components/InfoTip'; +import { StatusDot } from '@/components/ds'; + +// The top-bar meta every entity detail page shares (services, servers): +// [status dot] [(i) with the facts the header used to spell out] [star]. +// Anything page-specific (an "open" link) rides along as children. +// +// status: { kind, label } kind = Pill vocabulary +// rows: [{ label, value }] falsy values are skipped +export default function DetailHeaderMeta({ status, infoTitle, rows, favorite, children }) { + return ( + <> + + +
+ {rows.filter((row) => row.value).map((row) => ( +
+
{row.label}
+
{row.value}
+
+ ))} +
+
+ {favorite} + {children} + + ); +} diff --git a/frontend/src/components/detail/DetailSettings.jsx b/frontend/src/components/detail/DetailSettings.jsx new file mode 100644 index 00000000..45dafd05 --- /dev/null +++ b/frontend/src/components/detail/DetailSettings.jsx @@ -0,0 +1,44 @@ +import { Button } from '@/components/ui/button'; + +// The settings shell every entity detail page shares (services, servers): +// a grouped section nav on the left, the active section's panels on the right. +// Pages keep their own sections, URL state, permissions and mutation handlers. +// +// groups: [{ label, items: [{ id, label, icon }] }] +export function DetailSettings({ groups, value, onValueChange, ariaLabel, children }) { + return ( +
+ +
{children}
+
+ ); +} + +// One section of the content column: a quiet title above its panel(s). +export function DetailSettingsSection({ title, children }) { + return ( +
+

{title}

+ {children} +
+ ); +} diff --git a/frontend/src/components/serverdetail/ServerHeaderMeta.jsx b/frontend/src/components/serverdetail/ServerHeaderMeta.jsx index 1ed9c32d..1c100359 100644 --- a/frontend/src/components/serverdetail/ServerHeaderMeta.jsx +++ b/frontend/src/components/serverdetail/ServerHeaderMeta.jsx @@ -1,8 +1,7 @@ import { useTranslation } from 'react-i18next'; import FavoriteStar from '@/components/FavoriteStar'; -import InfoTip from '@/components/InfoTip'; import CopyButton from '@/components/CopyButton'; -import { StatusDot } from '../ds'; +import DetailHeaderMeta from '@/components/detail/DetailHeaderMeta'; import { serverStatusKind } from './serverDetailData'; // Header meta: [status dot] [(i) with endpoint + ID] [star]. Everything the @@ -12,22 +11,23 @@ export default function ServerHeaderMeta({ server }) { const status = server.status || 'pending'; const endpoint = server.hostname || server.ip_address || t('app.serverDetail.noEndpointConfigured', 'No endpoint configured'); return ( - <> - - -
-
{t('common.labels.status', 'Status')}
-
{status}
-
{t('app.serverDetail.endpoint', 'Endpoint')}
-
{endpoint}
-
{t('app.serverDetail.serverId', 'ID')}
-
- {server.id} - -
-
-
- - + + {server.id} + + + ), + }, + ]} + favorite={} + /> ); } diff --git a/frontend/src/components/serverdetail/ServerHealthCard.jsx b/frontend/src/components/serverdetail/ServerHealthCard.jsx index 9a97d277..28d8dc84 100644 --- a/frontend/src/components/serverdetail/ServerHealthCard.jsx +++ b/frontend/src/components/serverdetail/ServerHealthCard.jsx @@ -50,8 +50,8 @@ const ServerHealthCard = ({ server }) => { return ( <> -
-

{t('app.serverHealthCard.permissionLevel', 'Permission level')}

+
+

{t('app.serverHealthCard.permissionLevel', 'Permission level')}

{levelName} @@ -75,8 +75,8 @@ const ServerHealthCard = ({ server }) => { {SET_HINT}
-
-

{t('app.serverHealthCard.health', 'Health')} {health.code}

+
+

{t('app.serverHealthCard.health', 'Health')} {health.code}

{server.last_report_at && (

{t('app.serverHealthCard.lastReport', 'Last report')}: {formatDateTime(server.last_report_at)} diff --git a/frontend/src/components/serverdetail/ServerOverviewTab.jsx b/frontend/src/components/serverdetail/ServerOverviewTab.jsx index 0dcba474..070efe02 100644 --- a/frontend/src/components/serverdetail/ServerOverviewTab.jsx +++ b/frontend/src/components/serverdetail/ServerOverviewTab.jsx @@ -1,5 +1,5 @@ import { serverStatusKind } from './serverDetailData'; -import { Pill, KpiBand } from '../ds'; +import { Pill, KpiBand, MetricCard, Gauge } from '../ds'; import OnboardingWizard from '../server/OnboardingWizard'; import SystemStatusCard from './SystemStatusCard'; import ServerHealthCard from './ServerHealthCard'; @@ -8,8 +8,6 @@ import { InfoList, InfoItem } from '../InfoList'; import { useTranslation } from 'react-i18next'; import { formatDateTime } from '@/utils/intl'; import { - KpiTile, - KpiGauge, PulseIcon, ClockIcon, CpuIcon, @@ -29,6 +27,31 @@ import { DockerMiniIcon, } from './serverDetailShared'; +// Usage thresholds for the CPU / memory / disk tiles. +const USAGE_DANGER_PERCENT = 85; +const USAGE_WARN_PERCENT = 70; + +// A percent tile on the shared MetricCard: the value, a thin meter and the +// capacity line underneath. Same tile the service overview's KPI band uses. +const UsageTile = ({ icon, label, percent, color, sub }) => { + const has = Number.isFinite(percent); + const safe = has ? Math.min(Math.max(percent, 0), 100) : 0; + const danger = safe > USAGE_DANGER_PERCENT; + const warn = safe > USAGE_WARN_PERCENT && !danger; + return ( + + + {sub &&

{sub}
} + + ); +}; + const ServerOverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) => { const { t } = useTranslation(); const formatUptime = (seconds) => { @@ -41,6 +64,7 @@ const ServerOverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) => }; const isOnline = server.status === 'online'; + const statusLabel = server.status || 'pending'; const cpuCores = systemInfo?.cpu_cores || server.cpu_cores; const cpuModel = systemInfo?.cpu_model || server.cpu_model; const totalMemory = systemInfo?.total_memory || server.total_memory; @@ -72,33 +96,35 @@ const ServerOverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) =>
)} - } + tone={isOnline ? 'green' : server.status === 'connecting' ? 'amber' : 'red'} + value={statusLabel.charAt(0).toUpperCase() + statusLabel.slice(1)} label={t('common.labels.status', 'Status')} - value={server.status || 'pending'} - tone={isOnline ? 'success' : server.status === 'connecting' ? 'warning' : 'danger'} /> - } - label={t('common.labels.uptime', 'Uptime')} + tone="accent" value={isOnline ? formatUptime(metrics?.uptime) : '—'} - sub={isOnline && metrics?.uptime ? 'since last boot' : null} - /> - + {isOnline && metrics?.uptime ?
{t('app.serverOverviewTab.sinceLastBoot', 'since last boot')}
: null} + + } label="CPU" percent={isOnline ? metrics?.cpu_percent : null} color="var(--accent-bright)" sub={cpuCores ? `${cpuCores} cores` : null} /> - } label={t('common.labels.memory', 'Memory')} percent={isOnline ? metrics?.memory_percent : null} color="var(--cyan)" sub={totalMemory ? formatBytes(totalMemory) : null} /> - } label={t('common.labels.disk', 'Disk')} percent={isOnline ? metrics?.disk_percent : null} @@ -108,7 +134,7 @@ const ServerOverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) =>
{!isOnline && ( -
+

{t('app.serverOverviewTab.serverOffline', 'Server offline')}

@@ -121,9 +147,9 @@ const ServerOverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) =>
)} -
-
-

{t('app.serverOverviewTab.serverInformation', 'Server information')}

+
+
+

{t('app.serverOverviewTab.serverInformation', 'Server information')}

{t('common.labels.status', 'Status')}}> {server.status} @@ -138,8 +164,8 @@ const ServerOverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) =>
-
-

{t('app.serverOverviewTab.systemInformation', 'System information')}

+
+

{t('app.serverOverviewTab.systemInformation', 'System information')}

{t('app.serverOverviewTab.operatingSystem', 'Operating system')}} value={osLabel} /> {t('app.serverOverviewTab.architecture', 'Architecture')}} value={systemInfo?.architecture || server.architecture || 'N/A'} /> @@ -154,8 +180,8 @@ const ServerOverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) =>
-
-

{t('app.serverOverviewTab.agentInformation', 'Agent information')}

+
+

{t('app.serverOverviewTab.agentInformation', 'Agent information')}

{t('app.serverOverviewTab.agentVersion', 'Agent version')}} value={server.agent_version || 'Not installed'} mono /> {t('app.serverOverviewTab.agentId', 'Agent ID')}} value={server.agent_id || 'N/A'} mono /> @@ -166,9 +192,7 @@ const ServerOverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) => -
- -
+
); diff --git a/frontend/src/components/serverdetail/ServerSettingsTab.jsx b/frontend/src/components/serverdetail/ServerSettingsTab.jsx index d36fcce8..acdd8b9e 100644 --- a/frontend/src/components/serverdetail/ServerSettingsTab.jsx +++ b/frontend/src/components/serverdetail/ServerSettingsTab.jsx @@ -1,5 +1,7 @@ import { TOKEN_EXPIRY_OPTIONS } from './serverDetailData'; import { useCallback, useState, useEffect, useId } from 'react'; +import { useNavigate, useParams } from 'react-router-dom'; +import { Server, Tags, KeyRound, Shield, RefreshCw, Trash2 } from 'lucide-react'; import api from '../../services/api'; import { useToast } from '../../contexts/useToast.js'; import { useConfirm } from '../../hooks/useConfirm'; @@ -8,6 +10,8 @@ import { InfoList, InfoItem } from '../InfoList'; import InfoTip from '../InfoTip'; import { DangerZone } from '../DangerZone'; import { Button } from '@/components/ui/button'; +import { Card } from '@/components/ui/card'; +import { DetailSettings, DetailSettingsSection } from '@/components/detail/DetailSettings'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Pill } from '../ds'; @@ -22,48 +26,57 @@ import { } from '@/components/ui/select'; import TagsPanel from '../shared/TagsPanel'; import { useTranslation } from 'react-i18next'; -import { - KeyIcon, - ServerIcon, - NetworkIcon, - TrashIcon, - TagIcon, -} from './serverDetailShared'; +import { KeyIcon, TrashIcon } from './serverDetailShared'; import { toastError } from '@/utils/errorMessage'; import { formatDateTime } from '@/utils/intl'; // Radix Select items cannot carry an empty value; this stands for "no group". const NO_GROUP = '__none'; -const AgentRegistrationSection = ({ server, onRegenerateToken }) => { - const { t } = useTranslation(); +// The connection-string InfoTip depends on the server's state, so its copy is +// assembled here rather than inline in the section title. +const connectionStringHelp = (server, t) => { const expires = server.registration_expires; const isExpired = expires && new Date(expires) < new Date(); - const isOnline = server.status === 'online'; - - return ( -
-
- -
-

{t('app.serverSettingsTab.connectionString', 'Connection string')} - - {t('app.serverSettingsTab.generateAFreshConnectionStringTo', 'Generate a fresh connection string to pair (or re-pair) this server. Useful after reinstalling the agent: old credentials are gone, but a new string brings the agent right back to this row.')} - {isOnline && ` ${t('app.serverSettingsTab.onlineRegenerateNote', 'This server is online now; a new string only affects re-pairing.')}`} - {isExpired && ` ${t('app.serverSettingsTab.previousTokenExpired', 'The previous token has expired.')}`} -

-

{t('app.serverSettingsTab.pairOrRepair', 'Pair or re-pair this server.')}

-
-
- -
- ); + return [ + t('app.serverSettingsTab.generateAFreshConnectionStringTo', 'Generate a fresh connection string to pair (or re-pair) this server. Useful after reinstalling the agent: old credentials are gone, but a new string brings the agent right back to this row.'), + server.status === 'online' && t('app.serverSettingsTab.onlineRegenerateNote', 'This server is online now; a new string only affects re-pairing.'), + isExpired && t('app.serverSettingsTab.previousTokenExpired', 'The previous token has expired.'), + ].filter(Boolean).join(' '); }; const ServerSettingsTab = ({ server, onUpdate, onRegenerateToken, onDelete }) => { const { t } = useTranslation(); + const navigate = useNavigate(); + // Section lives in the URL (/servers/:id/settings/:section), same as the + // service detail page, so it is shareable and survives a refresh. + const { section: sectionParam } = useParams(); + const settingsGroups = [ + { + label: t('app.settingsTab.general', 'General'), + items: [ + { id: 'general', label: t('app.serverSettingsTab.basicInformation', 'Basic information'), icon: Server }, + { id: 'tags', label: t('app.serverSettingsTab.tags', 'Tags'), icon: Tags }, + ], + }, + { + label: t('app.serverSettingsTab.connection', 'Connection'), + items: [ + { id: 'connection', label: t('app.serverSettingsTab.connectionString', 'Connection string'), icon: KeyRound }, + { id: 'allowlist', label: t('app.serverSettingsTab.ipAllowlist', 'IP allowlist'), icon: Shield }, + { id: 'credentials', label: t('app.serverSettingsTab.apiKeyRotation', 'API key rotation'), icon: RefreshCw }, + ], + }, + { + label: t('app.settingsTab.advanced', 'Advanced'), + items: [ + { id: 'danger', label: t('app.serverSettingsTab.removeServer', 'Remove server'), icon: Trash2 }, + ], + }, + ]; + const settingsItems = settingsGroups.flatMap((group) => group.items); + const section = settingsItems.some((item) => item.id === sectionParam) ? sectionParam : 'general'; + const setSection = (next) => navigate(`/servers/${server.id}/settings/${next}`, { replace: true }); const fieldId = useId(); const { confirm: confirmSettings } = useConfirm(); const [formData, setFormData] = useState({ @@ -172,218 +185,233 @@ const ServerSettingsTab = ({ server, onUpdate, onRegenerateToken, onDelete }) => } return ( -
-
-
-
-
- -
-

{t('app.serverSettingsTab.basicInformation', 'Basic information')}

-

{t('app.serverSettingsTab.identityAndGroupingForThisServer', 'Identity and grouping for this server.')}

-
-
-
- - -
- -
- -