SystemInfoPage.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. import { useState } from 'react';
  2. import { useQuery, useQueryClient } from '@tanstack/react-query';
  3. import { useTranslation } from 'react-i18next';
  4. import {
  5. Server,
  6. Database,
  7. HardDrive,
  8. Cpu,
  9. MemoryStick,
  10. Printer,
  11. Archive,
  12. Clock,
  13. CheckCircle2,
  14. XCircle,
  15. Loader2,
  16. RefreshCw,
  17. Plug,
  18. FolderKanban,
  19. Palette,
  20. Bug,
  21. Download,
  22. Headphones,
  23. FolderOpen,
  24. Stethoscope,
  25. HeartPulse,
  26. } from 'lucide-react';
  27. import { api, supportApi, type Printer as PrinterModel } from '../api/client';
  28. import { Card } from '../components/Card';
  29. import { LogViewer } from '../components/LogViewer';
  30. import { ConnectionDiagnosticModal } from '../components/ConnectionDiagnostic';
  31. import { SystemHealthPanel } from '../components/SystemHealthPanel';
  32. import { formatDateTime, type TimeFormat } from '../utils/date';
  33. function formatBytes(bytes: number): string {
  34. if (bytes < 1024) return `${bytes} B`;
  35. if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
  36. if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
  37. return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
  38. }
  39. function StatCard({
  40. icon: Icon,
  41. label,
  42. value,
  43. subValue,
  44. color = 'text-bambu-green',
  45. }: {
  46. icon: React.ElementType;
  47. label: string;
  48. value: string | number;
  49. subValue?: string;
  50. color?: string;
  51. }) {
  52. return (
  53. <div className="flex items-start gap-3 p-4 bg-bambu-dark rounded-lg">
  54. <div className={`p-2 rounded-lg bg-bambu-dark-tertiary ${color}`}>
  55. <Icon className="w-5 h-5" />
  56. </div>
  57. <div className="flex-1 min-w-0">
  58. <p className="text-sm text-bambu-gray">{label}</p>
  59. <p className="text-lg font-semibold text-white truncate">{value}</p>
  60. {subValue && <p className="text-xs text-bambu-gray mt-0.5">{subValue}</p>}
  61. </div>
  62. </div>
  63. );
  64. }
  65. function ProgressBar({ percent, color = 'bg-bambu-green' }: { percent: number; color?: string }) {
  66. return (
  67. <div className="w-full h-2 bg-bambu-dark rounded-full overflow-hidden">
  68. <div
  69. className={`h-full ${color} transition-all duration-300`}
  70. style={{ width: `${Math.min(100, percent)}%` }}
  71. />
  72. </div>
  73. );
  74. }
  75. function Section({
  76. title,
  77. icon: Icon,
  78. children,
  79. }: {
  80. title: string;
  81. icon: React.ElementType;
  82. children: React.ReactNode;
  83. }) {
  84. return (
  85. <Card className="p-6">
  86. <div className="flex items-center gap-2 mb-4">
  87. <Icon className="w-5 h-5 text-bambu-green" />
  88. <h2 className="text-lg font-semibold text-white">{title}</h2>
  89. </div>
  90. {children}
  91. </Card>
  92. );
  93. }
  94. export function SystemInfoPage() {
  95. const { t } = useTranslation();
  96. const queryClient = useQueryClient();
  97. const [bundleError, setBundleError] = useState<string | null>(null);
  98. const [bundleDownloading, setBundleDownloading] = useState(false);
  99. const [debugToggling, setDebugToggling] = useState(false);
  100. const [diagnosticPrinter, setDiagnosticPrinter] = useState<PrinterModel | null>(null);
  101. const { data: systemInfo, isLoading, refetch, isFetching } = useQuery({
  102. queryKey: ['systemInfo'],
  103. queryFn: api.getSystemInfo,
  104. refetchInterval: 30000, // Auto-refresh every 30 seconds
  105. });
  106. const { data: debugLoggingState } = useQuery({
  107. queryKey: ['debugLogging'],
  108. queryFn: supportApi.getDebugLoggingState,
  109. staleTime: 10 * 1000, // 10 seconds
  110. refetchInterval: 10 * 1000,
  111. });
  112. const { data: settings } = useQuery({
  113. queryKey: ['settings'],
  114. queryFn: api.getSettings,
  115. });
  116. const { data: libraryStats } = useQuery({
  117. queryKey: ['library-stats'],
  118. queryFn: api.getLibraryStats,
  119. });
  120. const { data: allPrinters } = useQuery({
  121. queryKey: ['printers'],
  122. queryFn: api.getPrinters,
  123. });
  124. const {
  125. data: systemHealth,
  126. refetch: refetchHealth,
  127. isFetching: healthFetching,
  128. } = useQuery({
  129. queryKey: ['systemHealth'],
  130. queryFn: api.getSystemHealth,
  131. staleTime: 60 * 1000,
  132. });
  133. const timeFormat: TimeFormat = settings?.time_format || 'system';
  134. const handleToggleDebugLogging = async () => {
  135. setDebugToggling(true);
  136. try {
  137. const newState = await supportApi.setDebugLogging(!debugLoggingState?.enabled);
  138. // Immediately update the cache with the new state (includes fresh enabled_at timestamp)
  139. queryClient.setQueryData(['debugLogging'], newState);
  140. } catch (err) {
  141. console.error('Failed to toggle debug logging:', err);
  142. } finally {
  143. setDebugToggling(false);
  144. }
  145. };
  146. const handleDownloadBundle = async () => {
  147. setBundleError(null);
  148. setBundleDownloading(true);
  149. try {
  150. await supportApi.downloadSupportBundle();
  151. } catch (err) {
  152. setBundleError(err instanceof Error ? err.message : 'Failed to download support bundle');
  153. } finally {
  154. setBundleDownloading(false);
  155. }
  156. };
  157. if (isLoading) {
  158. return (
  159. <div className="flex items-center justify-center h-64">
  160. <Loader2 className="w-8 h-8 text-bambu-green animate-spin" />
  161. </div>
  162. );
  163. }
  164. if (!systemInfo) {
  165. return (
  166. <div className="p-6 text-center text-bambu-gray">
  167. {t('system.failedToLoad', 'Failed to load system information')}
  168. </div>
  169. );
  170. }
  171. const diskColor =
  172. systemInfo.storage.disk_percent_used > 90
  173. ? 'bg-red-500'
  174. : systemInfo.storage.disk_percent_used > 75
  175. ? 'bg-yellow-500'
  176. : 'bg-bambu-green';
  177. const memoryColor =
  178. systemInfo.memory.percent_used > 90
  179. ? 'bg-red-500'
  180. : systemInfo.memory.percent_used > 75
  181. ? 'bg-yellow-500'
  182. : 'bg-bambu-green';
  183. return (
  184. <div className="p-6 space-y-6">
  185. {/* Header. Same stacking as the Spool Inventory header (#2813) -- one
  186. button rather than five, so it only just overflows at 390px, but the
  187. overflow is the same. items-start keeps Refresh at its own width
  188. while stacked instead of stretching it across the page. */}
  189. <div className="flex flex-col items-start gap-4 sm:flex-row sm:items-center sm:justify-between">
  190. <div>
  191. <h1 className="text-2xl font-bold text-white">{t('system.title', 'System Information')}</h1>
  192. <p className="text-bambu-gray mt-1">
  193. {t('system.subtitle', 'Monitor system resources and database statistics')}
  194. </p>
  195. </div>
  196. <button
  197. onClick={() => refetch()}
  198. disabled={isFetching}
  199. className="flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50"
  200. >
  201. <RefreshCw className={`w-4 h-4 ${isFetching ? 'animate-spin' : ''}`} />
  202. {t('common.refresh', 'Refresh')}
  203. </button>
  204. </div>
  205. {/* Application Info */}
  206. <Section title={t('system.application', 'Application')} icon={Server}>
  207. <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
  208. <StatCard
  209. icon={Server}
  210. label={t('system.version', 'Version')}
  211. value={`v${systemInfo.app.version}`}
  212. />
  213. <StatCard
  214. icon={Clock}
  215. label={t('system.uptime', 'System Uptime')}
  216. value={systemInfo.system.uptime_formatted}
  217. />
  218. <StatCard
  219. icon={Server}
  220. label={t('system.hostname', 'Hostname')}
  221. value={systemInfo.system.hostname}
  222. />
  223. </div>
  224. </Section>
  225. {/* Support & Troubleshooting */}
  226. <Section title={t('support.title', 'Support & Troubleshooting')} icon={Headphones}>
  227. <div className="space-y-4">
  228. <p className="text-sm text-bambu-gray">
  229. {t('support.description', 'Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.')}
  230. </p>
  231. {/* Debug Logging Toggle */}
  232. <div className="flex items-center justify-between p-4 bg-bambu-dark rounded-lg">
  233. <div className="flex items-center gap-3">
  234. <div className={`p-2 rounded-lg ${debugLoggingState?.enabled ? 'bg-amber-500/20 text-amber-500' : 'bg-bambu-dark-tertiary text-bambu-gray'}`}>
  235. <Bug className="w-5 h-5" />
  236. </div>
  237. <div>
  238. <p className="font-medium text-white">{t('support.debugLogging', 'Debug Logging')}</p>
  239. <p className="text-sm text-bambu-gray">
  240. {debugLoggingState?.enabled
  241. ? t('support.debugLoggingEnabled', 'Capturing detailed logs')
  242. : t('support.debugLoggingDisabled', 'Normal logging level')}
  243. {debugLoggingState?.enabled && debugLoggingState.duration_seconds !== null && (
  244. <span className="text-amber-700 dark:text-amber-400 ml-2">
  245. ({Math.floor(debugLoggingState.duration_seconds / 60)}m {debugLoggingState.duration_seconds % 60}s)
  246. </span>
  247. )}
  248. </p>
  249. </div>
  250. </div>
  251. <button
  252. onClick={handleToggleDebugLogging}
  253. disabled={debugToggling}
  254. className={`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${
  255. debugLoggingState?.enabled
  256. ? 'bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-500/20 dark:text-amber-400 dark:hover:bg-amber-500/30'
  257. : 'bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30'
  258. } disabled:opacity-50`}
  259. >
  260. {debugToggling && <Loader2 className="w-4 h-4 animate-spin" />}
  261. {debugLoggingState?.enabled
  262. ? t('support.disableDebug', 'Disable')
  263. : t('support.enableDebug', 'Enable')}
  264. </button>
  265. </div>
  266. {/* Support Bundle Download */}
  267. <div className="flex items-center justify-between p-4 bg-bambu-dark rounded-lg">
  268. <div className="flex items-center gap-3">
  269. <div className="p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green">
  270. <Download className="w-5 h-5" />
  271. </div>
  272. <div>
  273. <p className="font-medium text-white">{t('support.supportBundle', 'Support Bundle')}</p>
  274. <p className="text-sm text-bambu-gray">
  275. {t('support.supportBundleDescription', 'Download system info and logs as a ZIP file')}
  276. </p>
  277. </div>
  278. </div>
  279. <button
  280. onClick={handleDownloadBundle}
  281. disabled={bundleDownloading || !debugLoggingState?.enabled}
  282. className="px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
  283. title={!debugLoggingState?.enabled ? t('support.enableDebugFirst', 'Enable debug logging first') : undefined}
  284. >
  285. {bundleDownloading && <Loader2 className="w-4 h-4 animate-spin" />}
  286. {bundleDownloading
  287. ? t('support.bundleGenerating', 'Generating...')
  288. : t('common.download', 'Download')}
  289. </button>
  290. </div>
  291. {/* Progress indicator — bundle generation now runs connection +
  292. virtual-printer diagnostics and the log-health scan before
  293. writing the ZIP (#1506 follow-up), so the wait is longer than
  294. a pure file-export. List what's running so it's not opaque. */}
  295. {bundleDownloading && (
  296. <div className="p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1">
  297. <p className="text-sm font-medium text-white flex items-center gap-2">
  298. <Loader2 className="w-3.5 h-3.5 animate-spin text-bambu-green" />
  299. {t('support.bundleGenerating', 'Generating...')}
  300. </p>
  301. <ul className="text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1">
  302. <li>{t('support.bundleStepConnection', 'Running printer connectivity checks')}</li>
  303. <li>{t('support.bundleStepVirtualPrinters', 'Running virtual-printer setup checks')}</li>
  304. <li>{t('support.bundleStepLogScan', 'Scanning recent logs for known issues')}</li>
  305. <li>{t('support.bundleStepBuild', 'Building the support bundle ZIP')}</li>
  306. </ul>
  307. </div>
  308. )}
  309. {/* Error message */}
  310. {bundleError && (
  311. <div className="p-3 bg-red-100 border border-red-300 rounded-lg text-red-700 dark:bg-red-500/20 dark:border-red-500/30 dark:text-red-400 text-sm">
  312. {bundleError}
  313. </div>
  314. )}
  315. {/* Instructions */}
  316. {!debugLoggingState?.enabled && (
  317. <div className="p-4 bg-bambu-dark-tertiary/50 rounded-lg">
  318. <p className="text-sm text-bambu-gray">
  319. <span className="text-amber-700 dark:text-amber-400 font-medium">{t('support.instructions', 'To report an issue:')}</span>
  320. <br />
  321. 1. {t('support.step1', 'Enable debug logging')}
  322. <br />
  323. 2. {t('support.step2', 'Reproduce the issue')}
  324. <br />
  325. 3. {t('support.step3', 'Download the support bundle')}
  326. <br />
  327. 4. {t('support.step4', 'Attach the ZIP file to your issue report')}
  328. </p>
  329. </div>
  330. )}
  331. {/* Privacy Info */}
  332. <div className="p-4 bg-bambu-dark rounded-lg space-y-3">
  333. <p className="text-sm font-medium text-white">{t('support.privacyTitle', 'What\'s in the support bundle?')}</p>
  334. <div className="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
  335. <div>
  336. <p className="text-bambu-green font-medium mb-1">{t('support.collected', 'Collected:')}</p>
  337. <ul className="text-bambu-gray space-y-0.5">
  338. <li>• {t('support.collectItem1', 'App version and debug mode')}</li>
  339. <li>• {t('support.collectItem2', 'OS, architecture, Python version')}</li>
  340. <li>• {t('support.collectItem3', 'Database statistics (counts only)')}</li>
  341. <li>• {t('support.collectItem4', 'Printer models and nozzle counts')}</li>
  342. <li>• {t('support.collectItem5', 'Non-sensitive settings (themes, formats)')}</li>
  343. <li>• {t('support.collectItem6', 'Debug logs (sanitized)')}</li>
  344. <li>• {t('support.collectItem7', 'Printer connectivity and firmware versions')}</li>
  345. <li>• {t('support.collectItem8', 'Integration status (Spoolman, MQTT, HA)')}</li>
  346. <li>• {t('support.collectItem9', 'Network interfaces (subnets only)')}</li>
  347. <li>• {t('support.collectItem10', 'Python package versions')}</li>
  348. <li>• {t('support.collectItem11', 'Database health checks')}</li>
  349. <li>• {t('support.collectItem12', 'Docker environment details')}</li>
  350. </ul>
  351. </div>
  352. <div>
  353. <p className="text-red-700 dark:text-red-400 font-medium mb-1">{t('support.notCollected', 'NOT collected:')}</p>
  354. <ul className="text-bambu-gray space-y-0.5">
  355. <li>• {t('support.notItem1', 'Printer names and serial numbers')}</li>
  356. <li>• {t('support.notItem2', 'Access codes and passwords')}</li>
  357. <li>• {t('support.notItem3', 'Email addresses')}</li>
  358. <li>• {t('support.notItem4', 'API keys and tokens')}</li>
  359. <li>• {t('support.notItem5', 'Webhook URLs')}</li>
  360. <li>• {t('support.notItem6', 'Your hostname or username')}</li>
  361. <li>• {t('support.notItem7', 'IP addresses')}</li>
  362. </ul>
  363. </div>
  364. </div>
  365. <p className="text-xs text-bambu-gray/70">
  366. {t('support.privacyNote', 'Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].')}
  367. </p>
  368. </div>
  369. {/* Log Viewer */}
  370. <LogViewer />
  371. </div>
  372. </Section>
  373. {/* Connection Diagnostic */}
  374. <Section title={t('diagnostic.sectionTitle', 'Connection Diagnostic')} icon={Stethoscope}>
  375. <p className="text-sm text-bambu-gray mb-4">
  376. {t(
  377. 'diagnostic.sectionDescription',
  378. "Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.",
  379. )}
  380. </p>
  381. {allPrinters && allPrinters.length > 0 ? (
  382. <div className="space-y-2">
  383. {allPrinters.map((printer) => (
  384. <div
  385. key={printer.id}
  386. className="flex items-center justify-between p-3 bg-bambu-dark rounded-lg"
  387. >
  388. <div className="min-w-0">
  389. <span className="font-medium text-white">{printer.name}</span>
  390. <span className="text-sm text-bambu-gray ml-2">{printer.ip_address}</span>
  391. </div>
  392. <button
  393. onClick={() => setDiagnosticPrinter(printer)}
  394. className="flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0"
  395. >
  396. <Stethoscope className="w-4 h-4" />
  397. {t('diagnostic.runButton', 'Run diagnostic')}
  398. </button>
  399. </div>
  400. ))}
  401. </div>
  402. ) : (
  403. <p className="text-bambu-gray">{t('diagnostic.noPrinters', 'No printers configured.')}</p>
  404. )}
  405. </Section>
  406. {/* System Health */}
  407. <Section title={t('systemHealth.sectionTitle')} icon={HeartPulse}>
  408. <div className="flex items-start justify-between gap-3 mb-3">
  409. <p className="text-sm text-bambu-gray">{t('systemHealth.sectionDescription')}</p>
  410. <button
  411. onClick={() => refetchHealth()}
  412. disabled={healthFetching}
  413. className="flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0 disabled:opacity-50"
  414. >
  415. <RefreshCw className={`w-4 h-4 ${healthFetching ? 'animate-spin' : ''}`} />
  416. {t('systemHealth.rescan')}
  417. </button>
  418. </div>
  419. {systemHealth ? (
  420. <SystemHealthPanel result={systemHealth} />
  421. ) : (
  422. <p className="text-sm text-bambu-gray">{t('common.loading')}</p>
  423. )}
  424. </Section>
  425. {/* Database Stats */}
  426. <Section title={t('system.database', 'Database')} icon={Database}>
  427. <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
  428. <StatCard
  429. icon={Database}
  430. label={t('system.dbEngine', 'Database Engine')}
  431. value={systemInfo.database.engine || 'SQLite'}
  432. />
  433. <StatCard
  434. icon={Database}
  435. label={t('system.dbVersion', 'Version')}
  436. value={systemInfo.database.version || 'unknown'}
  437. />
  438. </div>
  439. <div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
  440. <StatCard
  441. icon={Archive}
  442. label={t('system.totalArchives', 'Total Archives')}
  443. value={systemInfo.database.archives}
  444. />
  445. <StatCard
  446. icon={CheckCircle2}
  447. label={t('system.completed', 'Completed')}
  448. value={systemInfo.database.archives_completed}
  449. color="text-green-500"
  450. />
  451. <StatCard
  452. icon={XCircle}
  453. label={t('system.failed', 'Failed')}
  454. value={systemInfo.database.archives_failed}
  455. color="text-red-500"
  456. />
  457. <StatCard
  458. icon={Loader2}
  459. label={t('system.printing', 'Printing')}
  460. value={systemInfo.database.archives_printing}
  461. color="text-yellow-500"
  462. />
  463. </div>
  464. <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
  465. <StatCard
  466. icon={Printer}
  467. label={t('system.printers', 'Printers')}
  468. value={systemInfo.database.printers}
  469. />
  470. <StatCard
  471. icon={Palette}
  472. label={t('system.filaments', 'Filaments')}
  473. value={systemInfo.database.filaments}
  474. />
  475. <StatCard
  476. icon={FolderKanban}
  477. label={t('system.projects', 'Projects')}
  478. value={systemInfo.database.projects}
  479. />
  480. <StatCard
  481. icon={Plug}
  482. label={t('system.smartPlugs', 'Smart Plugs')}
  483. value={systemInfo.database.smart_plugs}
  484. />
  485. </div>
  486. <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
  487. <StatCard
  488. icon={Clock}
  489. label={t('system.totalPrintTime', 'Total Print Time')}
  490. value={systemInfo.database.total_print_time_formatted}
  491. />
  492. <StatCard
  493. icon={Archive}
  494. label={t('system.totalFilament', 'Total Filament Used')}
  495. value={`${systemInfo.database.total_filament_kg} kg`}
  496. subValue={`${systemInfo.database.total_filament_grams.toLocaleString()} g`}
  497. />
  498. </div>
  499. </Section>
  500. {/* Connected Printers */}
  501. <Section title={t('system.connectedPrinters', 'Connected Printers')} icon={Printer}>
  502. <div className="flex items-center gap-4 mb-4">
  503. <div className="text-3xl font-bold text-bambu-green">
  504. {systemInfo.printers.connected}
  505. </div>
  506. <div className="text-bambu-gray">
  507. {t('system.ofTotal', 'of {{total}} printers connected', {
  508. total: systemInfo.printers.total,
  509. })}
  510. </div>
  511. </div>
  512. {systemInfo.printers.connected_list.length > 0 ? (
  513. <div className="space-y-2">
  514. {systemInfo.printers.connected_list.map((printer) => (
  515. <div
  516. key={printer.id}
  517. className="flex items-center justify-between p-3 bg-bambu-dark rounded-lg"
  518. >
  519. <div className="flex items-center gap-3">
  520. <div className="w-2 h-2 rounded-full bg-bambu-green" />
  521. <span className="font-medium text-white">{printer.name}</span>
  522. </div>
  523. <div className="flex items-center gap-4 text-sm text-bambu-gray">
  524. <span>{printer.model}</span>
  525. <span
  526. className={`px-2 py-0.5 rounded ${
  527. printer.state === 'RUNNING'
  528. ? 'bg-bambu-green/20 text-bambu-green'
  529. : printer.state === 'IDLE'
  530. ? 'bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400'
  531. : 'bg-bambu-dark-tertiary'
  532. }`}
  533. >
  534. {printer.state}
  535. </span>
  536. </div>
  537. </div>
  538. ))}
  539. </div>
  540. ) : (
  541. <p className="text-bambu-gray">{t('system.noPrintersConnected', 'No printers connected')}</p>
  542. )}
  543. </Section>
  544. {/* Storage */}
  545. <Section title={t('system.storage', 'Storage')} icon={HardDrive}>
  546. <div className="space-y-4">
  547. <div>
  548. <div className="flex justify-between text-sm mb-1">
  549. <span className="text-bambu-gray">{t('system.diskUsage', 'Disk Usage')}</span>
  550. <span className="text-white">
  551. {systemInfo.storage.disk_used_formatted} / {systemInfo.storage.disk_total_formatted}
  552. </span>
  553. </div>
  554. <ProgressBar percent={systemInfo.storage.disk_percent_used} color={diskColor} />
  555. <p className="text-xs text-bambu-gray mt-1">
  556. {systemInfo.storage.disk_free_formatted} {t('system.free', 'free')} (
  557. {(100 - systemInfo.storage.disk_percent_used).toFixed(1)}%)
  558. </p>
  559. </div>
  560. <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
  561. <StatCard
  562. icon={Archive}
  563. label={t('system.archiveStorage', 'Archive Storage')}
  564. value={systemInfo.storage.archive_size_formatted}
  565. />
  566. <StatCard
  567. icon={Database}
  568. label={t('system.databaseSize', 'Database Size')}
  569. value={systemInfo.storage.database_size_formatted}
  570. />
  571. {libraryStats && (
  572. <StatCard
  573. icon={FolderOpen}
  574. label={t('system.fileManagerStorage', 'File Manager')}
  575. value={formatBytes(libraryStats.total_size_bytes)}
  576. subValue={`${libraryStats.total_files} files, ${libraryStats.total_folders} folders`}
  577. />
  578. )}
  579. </div>
  580. </div>
  581. </Section>
  582. {/* System Resources */}
  583. <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
  584. {/* Memory */}
  585. <Section title={t('system.memory', 'Memory')} icon={MemoryStick}>
  586. <div className="space-y-4">
  587. <div>
  588. <div className="flex justify-between text-sm mb-1">
  589. <span className="text-bambu-gray">{t('system.memoryUsage', 'Memory Usage')}</span>
  590. <span className="text-white">
  591. {systemInfo.memory.used_formatted} / {systemInfo.memory.total_formatted}
  592. </span>
  593. </div>
  594. <ProgressBar percent={systemInfo.memory.percent_used} color={memoryColor} />
  595. <p className="text-xs text-bambu-gray mt-1">
  596. {systemInfo.memory.available_formatted} {t('system.available', 'available')}
  597. </p>
  598. </div>
  599. </div>
  600. </Section>
  601. {/* CPU */}
  602. <Section title={t('system.cpu', 'CPU')} icon={Cpu}>
  603. <div className="space-y-4">
  604. <div className="grid grid-cols-2 gap-4">
  605. <StatCard
  606. icon={Cpu}
  607. label={t('system.cores', 'Cores')}
  608. value={systemInfo.cpu.count}
  609. subValue={`${systemInfo.cpu.count_logical} logical`}
  610. />
  611. <StatCard
  612. icon={Cpu}
  613. label={t('system.usage', 'Usage')}
  614. value={`${systemInfo.cpu.percent}%`}
  615. />
  616. </div>
  617. </div>
  618. </Section>
  619. </div>
  620. {/* System Details */}
  621. <Section title={t('system.systemDetails', 'System Details')} icon={Server}>
  622. <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
  623. <StatCard
  624. icon={Server}
  625. label={t('system.os', 'Operating System')}
  626. value={systemInfo.system.platform}
  627. subValue={systemInfo.system.platform_release}
  628. />
  629. <StatCard
  630. icon={Cpu}
  631. label={t('system.architecture', 'Architecture')}
  632. value={systemInfo.system.architecture}
  633. />
  634. <StatCard
  635. icon={Server}
  636. label={t('system.python', 'Python')}
  637. value={systemInfo.system.python_version}
  638. />
  639. <StatCard
  640. icon={Clock}
  641. label={t('system.bootTime', 'Boot Time')}
  642. value={formatDateTime(systemInfo.system.boot_time, timeFormat)}
  643. />
  644. </div>
  645. </Section>
  646. {diagnosticPrinter && (
  647. <ConnectionDiagnosticModal
  648. printerId={diagnosticPrinter.id}
  649. printerName={diagnosticPrinter.name}
  650. onClose={() => setDiagnosticPrinter(null)}
  651. />
  652. )}
  653. </div>
  654. );
  655. }