SystemInfoPage.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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 */}
  186. <div className="flex items-center justify-between">
  187. <div>
  188. <h1 className="text-2xl font-bold text-white">{t('system.title', 'System Information')}</h1>
  189. <p className="text-bambu-gray mt-1">
  190. {t('system.subtitle', 'Monitor system resources and database statistics')}
  191. </p>
  192. </div>
  193. <button
  194. onClick={() => refetch()}
  195. disabled={isFetching}
  196. 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"
  197. >
  198. <RefreshCw className={`w-4 h-4 ${isFetching ? 'animate-spin' : ''}`} />
  199. {t('common.refresh', 'Refresh')}
  200. </button>
  201. </div>
  202. {/* Application Info */}
  203. <Section title={t('system.application', 'Application')} icon={Server}>
  204. <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
  205. <StatCard
  206. icon={Server}
  207. label={t('system.version', 'Version')}
  208. value={`v${systemInfo.app.version}`}
  209. />
  210. <StatCard
  211. icon={Clock}
  212. label={t('system.uptime', 'System Uptime')}
  213. value={systemInfo.system.uptime_formatted}
  214. />
  215. <StatCard
  216. icon={Server}
  217. label={t('system.hostname', 'Hostname')}
  218. value={systemInfo.system.hostname}
  219. />
  220. </div>
  221. </Section>
  222. {/* Support & Troubleshooting */}
  223. <Section title={t('support.title', 'Support & Troubleshooting')} icon={Headphones}>
  224. <div className="space-y-4">
  225. <p className="text-sm text-bambu-gray">
  226. {t('support.description', 'Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.')}
  227. </p>
  228. {/* Debug Logging Toggle */}
  229. <div className="flex items-center justify-between p-4 bg-bambu-dark rounded-lg">
  230. <div className="flex items-center gap-3">
  231. <div className={`p-2 rounded-lg ${debugLoggingState?.enabled ? 'bg-amber-500/20 text-amber-500' : 'bg-bambu-dark-tertiary text-bambu-gray'}`}>
  232. <Bug className="w-5 h-5" />
  233. </div>
  234. <div>
  235. <p className="font-medium text-white">{t('support.debugLogging', 'Debug Logging')}</p>
  236. <p className="text-sm text-bambu-gray">
  237. {debugLoggingState?.enabled
  238. ? t('support.debugLoggingEnabled', 'Capturing detailed logs')
  239. : t('support.debugLoggingDisabled', 'Normal logging level')}
  240. {debugLoggingState?.enabled && debugLoggingState.duration_seconds !== null && (
  241. <span className="text-amber-400 ml-2">
  242. ({Math.floor(debugLoggingState.duration_seconds / 60)}m {debugLoggingState.duration_seconds % 60}s)
  243. </span>
  244. )}
  245. </p>
  246. </div>
  247. </div>
  248. <button
  249. onClick={handleToggleDebugLogging}
  250. disabled={debugToggling}
  251. className={`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${
  252. debugLoggingState?.enabled
  253. ? 'bg-amber-500/20 text-amber-400 hover:bg-amber-500/30'
  254. : 'bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30'
  255. } disabled:opacity-50`}
  256. >
  257. {debugToggling && <Loader2 className="w-4 h-4 animate-spin" />}
  258. {debugLoggingState?.enabled
  259. ? t('support.disableDebug', 'Disable')
  260. : t('support.enableDebug', 'Enable')}
  261. </button>
  262. </div>
  263. {/* Support Bundle Download */}
  264. <div className="flex items-center justify-between p-4 bg-bambu-dark rounded-lg">
  265. <div className="flex items-center gap-3">
  266. <div className="p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green">
  267. <Download className="w-5 h-5" />
  268. </div>
  269. <div>
  270. <p className="font-medium text-white">{t('support.supportBundle', 'Support Bundle')}</p>
  271. <p className="text-sm text-bambu-gray">
  272. {t('support.supportBundleDescription', 'Download system info and logs as a ZIP file')}
  273. </p>
  274. </div>
  275. </div>
  276. <button
  277. onClick={handleDownloadBundle}
  278. disabled={bundleDownloading || !debugLoggingState?.enabled}
  279. 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"
  280. title={!debugLoggingState?.enabled ? t('support.enableDebugFirst', 'Enable debug logging first') : undefined}
  281. >
  282. {bundleDownloading && <Loader2 className="w-4 h-4 animate-spin" />}
  283. {bundleDownloading
  284. ? t('support.bundleGenerating', 'Generating...')
  285. : t('common.download', 'Download')}
  286. </button>
  287. </div>
  288. {/* Progress indicator — bundle generation now runs connection +
  289. virtual-printer diagnostics and the log-health scan before
  290. writing the ZIP (#1506 follow-up), so the wait is longer than
  291. a pure file-export. List what's running so it's not opaque. */}
  292. {bundleDownloading && (
  293. <div className="p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1">
  294. <p className="text-sm font-medium text-white flex items-center gap-2">
  295. <Loader2 className="w-3.5 h-3.5 animate-spin text-bambu-green" />
  296. {t('support.bundleGenerating', 'Generating...')}
  297. </p>
  298. <ul className="text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1">
  299. <li>{t('support.bundleStepConnection', 'Running printer connectivity checks')}</li>
  300. <li>{t('support.bundleStepVirtualPrinters', 'Running virtual-printer setup checks')}</li>
  301. <li>{t('support.bundleStepLogScan', 'Scanning recent logs for known issues')}</li>
  302. <li>{t('support.bundleStepBuild', 'Building the support bundle ZIP')}</li>
  303. </ul>
  304. </div>
  305. )}
  306. {/* Error message */}
  307. {bundleError && (
  308. <div className="p-3 bg-red-500/20 border border-red-500/30 rounded-lg text-red-400 text-sm">
  309. {bundleError}
  310. </div>
  311. )}
  312. {/* Instructions */}
  313. {!debugLoggingState?.enabled && (
  314. <div className="p-4 bg-bambu-dark-tertiary/50 rounded-lg">
  315. <p className="text-sm text-bambu-gray">
  316. <span className="text-amber-400 font-medium">{t('support.instructions', 'To report an issue:')}</span>
  317. <br />
  318. 1. {t('support.step1', 'Enable debug logging')}
  319. <br />
  320. 2. {t('support.step2', 'Reproduce the issue')}
  321. <br />
  322. 3. {t('support.step3', 'Download the support bundle')}
  323. <br />
  324. 4. {t('support.step4', 'Attach the ZIP file to your issue report')}
  325. </p>
  326. </div>
  327. )}
  328. {/* Privacy Info */}
  329. <div className="p-4 bg-bambu-dark rounded-lg space-y-3">
  330. <p className="text-sm font-medium text-white">{t('support.privacyTitle', 'What\'s in the support bundle?')}</p>
  331. <div className="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
  332. <div>
  333. <p className="text-bambu-green font-medium mb-1">{t('support.collected', 'Collected:')}</p>
  334. <ul className="text-bambu-gray space-y-0.5">
  335. <li>• {t('support.collectItem1', 'App version and debug mode')}</li>
  336. <li>• {t('support.collectItem2', 'OS, architecture, Python version')}</li>
  337. <li>• {t('support.collectItem3', 'Database statistics (counts only)')}</li>
  338. <li>• {t('support.collectItem4', 'Printer models and nozzle counts')}</li>
  339. <li>• {t('support.collectItem5', 'Non-sensitive settings (themes, formats)')}</li>
  340. <li>• {t('support.collectItem6', 'Debug logs (sanitized)')}</li>
  341. <li>• {t('support.collectItem7', 'Printer connectivity and firmware versions')}</li>
  342. <li>• {t('support.collectItem8', 'Integration status (Spoolman, MQTT, HA)')}</li>
  343. <li>• {t('support.collectItem9', 'Network interfaces (subnets only)')}</li>
  344. <li>• {t('support.collectItem10', 'Python package versions')}</li>
  345. <li>• {t('support.collectItem11', 'Database health checks')}</li>
  346. <li>• {t('support.collectItem12', 'Docker environment details')}</li>
  347. </ul>
  348. </div>
  349. <div>
  350. <p className="text-red-400 font-medium mb-1">{t('support.notCollected', 'NOT collected:')}</p>
  351. <ul className="text-bambu-gray space-y-0.5">
  352. <li>• {t('support.notItem1', 'Printer names and serial numbers')}</li>
  353. <li>• {t('support.notItem2', 'Access codes and passwords')}</li>
  354. <li>• {t('support.notItem3', 'Email addresses')}</li>
  355. <li>• {t('support.notItem4', 'API keys and tokens')}</li>
  356. <li>• {t('support.notItem5', 'Webhook URLs')}</li>
  357. <li>• {t('support.notItem6', 'Your hostname or username')}</li>
  358. <li>• {t('support.notItem7', 'IP addresses')}</li>
  359. </ul>
  360. </div>
  361. </div>
  362. <p className="text-xs text-bambu-gray/70">
  363. {t('support.privacyNote', 'Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].')}
  364. </p>
  365. </div>
  366. {/* Log Viewer */}
  367. <LogViewer />
  368. </div>
  369. </Section>
  370. {/* Connection Diagnostic */}
  371. <Section title={t('diagnostic.sectionTitle', 'Connection Diagnostic')} icon={Stethoscope}>
  372. <p className="text-sm text-bambu-gray mb-4">
  373. {t(
  374. 'diagnostic.sectionDescription',
  375. "Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.",
  376. )}
  377. </p>
  378. {allPrinters && allPrinters.length > 0 ? (
  379. <div className="space-y-2">
  380. {allPrinters.map((printer) => (
  381. <div
  382. key={printer.id}
  383. className="flex items-center justify-between p-3 bg-bambu-dark rounded-lg"
  384. >
  385. <div className="min-w-0">
  386. <span className="font-medium text-white">{printer.name}</span>
  387. <span className="text-sm text-bambu-gray ml-2">{printer.ip_address}</span>
  388. </div>
  389. <button
  390. onClick={() => setDiagnosticPrinter(printer)}
  391. 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"
  392. >
  393. <Stethoscope className="w-4 h-4" />
  394. {t('diagnostic.runButton', 'Run diagnostic')}
  395. </button>
  396. </div>
  397. ))}
  398. </div>
  399. ) : (
  400. <p className="text-bambu-gray">{t('diagnostic.noPrinters', 'No printers configured.')}</p>
  401. )}
  402. </Section>
  403. {/* System Health */}
  404. <Section title={t('systemHealth.sectionTitle')} icon={HeartPulse}>
  405. <div className="flex items-start justify-between gap-3 mb-3">
  406. <p className="text-sm text-bambu-gray">{t('systemHealth.sectionDescription')}</p>
  407. <button
  408. onClick={() => refetchHealth()}
  409. disabled={healthFetching}
  410. 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"
  411. >
  412. <RefreshCw className={`w-4 h-4 ${healthFetching ? 'animate-spin' : ''}`} />
  413. {t('systemHealth.rescan')}
  414. </button>
  415. </div>
  416. {systemHealth ? (
  417. <SystemHealthPanel result={systemHealth} />
  418. ) : (
  419. <p className="text-sm text-bambu-gray">{t('common.loading')}</p>
  420. )}
  421. </Section>
  422. {/* Database Stats */}
  423. <Section title={t('system.database', 'Database')} icon={Database}>
  424. <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
  425. <StatCard
  426. icon={Database}
  427. label={t('system.dbEngine', 'Database Engine')}
  428. value={systemInfo.database.engine || 'SQLite'}
  429. />
  430. <StatCard
  431. icon={Database}
  432. label={t('system.dbVersion', 'Version')}
  433. value={systemInfo.database.version || 'unknown'}
  434. />
  435. </div>
  436. <div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-4">
  437. <StatCard
  438. icon={Archive}
  439. label={t('system.totalArchives', 'Total Archives')}
  440. value={systemInfo.database.archives}
  441. />
  442. <StatCard
  443. icon={CheckCircle2}
  444. label={t('system.completed', 'Completed')}
  445. value={systemInfo.database.archives_completed}
  446. color="text-green-500"
  447. />
  448. <StatCard
  449. icon={XCircle}
  450. label={t('system.failed', 'Failed')}
  451. value={systemInfo.database.archives_failed}
  452. color="text-red-500"
  453. />
  454. <StatCard
  455. icon={Loader2}
  456. label={t('system.printing', 'Printing')}
  457. value={systemInfo.database.archives_printing}
  458. color="text-yellow-500"
  459. />
  460. </div>
  461. <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
  462. <StatCard
  463. icon={Printer}
  464. label={t('system.printers', 'Printers')}
  465. value={systemInfo.database.printers}
  466. />
  467. <StatCard
  468. icon={Palette}
  469. label={t('system.filaments', 'Filaments')}
  470. value={systemInfo.database.filaments}
  471. />
  472. <StatCard
  473. icon={FolderKanban}
  474. label={t('system.projects', 'Projects')}
  475. value={systemInfo.database.projects}
  476. />
  477. <StatCard
  478. icon={Plug}
  479. label={t('system.smartPlugs', 'Smart Plugs')}
  480. value={systemInfo.database.smart_plugs}
  481. />
  482. </div>
  483. <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
  484. <StatCard
  485. icon={Clock}
  486. label={t('system.totalPrintTime', 'Total Print Time')}
  487. value={systemInfo.database.total_print_time_formatted}
  488. />
  489. <StatCard
  490. icon={Archive}
  491. label={t('system.totalFilament', 'Total Filament Used')}
  492. value={`${systemInfo.database.total_filament_kg} kg`}
  493. subValue={`${systemInfo.database.total_filament_grams.toLocaleString()} g`}
  494. />
  495. </div>
  496. </Section>
  497. {/* Connected Printers */}
  498. <Section title={t('system.connectedPrinters', 'Connected Printers')} icon={Printer}>
  499. <div className="flex items-center gap-4 mb-4">
  500. <div className="text-3xl font-bold text-bambu-green">
  501. {systemInfo.printers.connected}
  502. </div>
  503. <div className="text-bambu-gray">
  504. {t('system.ofTotal', 'of {{total}} printers connected', {
  505. total: systemInfo.printers.total,
  506. })}
  507. </div>
  508. </div>
  509. {systemInfo.printers.connected_list.length > 0 ? (
  510. <div className="space-y-2">
  511. {systemInfo.printers.connected_list.map((printer) => (
  512. <div
  513. key={printer.id}
  514. className="flex items-center justify-between p-3 bg-bambu-dark rounded-lg"
  515. >
  516. <div className="flex items-center gap-3">
  517. <div className="w-2 h-2 rounded-full bg-bambu-green" />
  518. <span className="font-medium text-white">{printer.name}</span>
  519. </div>
  520. <div className="flex items-center gap-4 text-sm text-bambu-gray">
  521. <span>{printer.model}</span>
  522. <span
  523. className={`px-2 py-0.5 rounded ${
  524. printer.state === 'RUNNING'
  525. ? 'bg-bambu-green/20 text-bambu-green'
  526. : printer.state === 'IDLE'
  527. ? 'bg-blue-500/20 text-blue-400'
  528. : 'bg-bambu-dark-tertiary'
  529. }`}
  530. >
  531. {printer.state}
  532. </span>
  533. </div>
  534. </div>
  535. ))}
  536. </div>
  537. ) : (
  538. <p className="text-bambu-gray">{t('system.noPrintersConnected', 'No printers connected')}</p>
  539. )}
  540. </Section>
  541. {/* Storage */}
  542. <Section title={t('system.storage', 'Storage')} icon={HardDrive}>
  543. <div className="space-y-4">
  544. <div>
  545. <div className="flex justify-between text-sm mb-1">
  546. <span className="text-bambu-gray">{t('system.diskUsage', 'Disk Usage')}</span>
  547. <span className="text-white">
  548. {systemInfo.storage.disk_used_formatted} / {systemInfo.storage.disk_total_formatted}
  549. </span>
  550. </div>
  551. <ProgressBar percent={systemInfo.storage.disk_percent_used} color={diskColor} />
  552. <p className="text-xs text-bambu-gray mt-1">
  553. {systemInfo.storage.disk_free_formatted} {t('system.free', 'free')} (
  554. {(100 - systemInfo.storage.disk_percent_used).toFixed(1)}%)
  555. </p>
  556. </div>
  557. <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
  558. <StatCard
  559. icon={Archive}
  560. label={t('system.archiveStorage', 'Archive Storage')}
  561. value={systemInfo.storage.archive_size_formatted}
  562. />
  563. <StatCard
  564. icon={Database}
  565. label={t('system.databaseSize', 'Database Size')}
  566. value={systemInfo.storage.database_size_formatted}
  567. />
  568. {libraryStats && (
  569. <StatCard
  570. icon={FolderOpen}
  571. label={t('system.fileManagerStorage', 'File Manager')}
  572. value={formatBytes(libraryStats.total_size_bytes)}
  573. subValue={`${libraryStats.total_files} files, ${libraryStats.total_folders} folders`}
  574. />
  575. )}
  576. </div>
  577. </div>
  578. </Section>
  579. {/* System Resources */}
  580. <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
  581. {/* Memory */}
  582. <Section title={t('system.memory', 'Memory')} icon={MemoryStick}>
  583. <div className="space-y-4">
  584. <div>
  585. <div className="flex justify-between text-sm mb-1">
  586. <span className="text-bambu-gray">{t('system.memoryUsage', 'Memory Usage')}</span>
  587. <span className="text-white">
  588. {systemInfo.memory.used_formatted} / {systemInfo.memory.total_formatted}
  589. </span>
  590. </div>
  591. <ProgressBar percent={systemInfo.memory.percent_used} color={memoryColor} />
  592. <p className="text-xs text-bambu-gray mt-1">
  593. {systemInfo.memory.available_formatted} {t('system.available', 'available')}
  594. </p>
  595. </div>
  596. </div>
  597. </Section>
  598. {/* CPU */}
  599. <Section title={t('system.cpu', 'CPU')} icon={Cpu}>
  600. <div className="space-y-4">
  601. <div className="grid grid-cols-2 gap-4">
  602. <StatCard
  603. icon={Cpu}
  604. label={t('system.cores', 'Cores')}
  605. value={systemInfo.cpu.count}
  606. subValue={`${systemInfo.cpu.count_logical} logical`}
  607. />
  608. <StatCard
  609. icon={Cpu}
  610. label={t('system.usage', 'Usage')}
  611. value={`${systemInfo.cpu.percent}%`}
  612. />
  613. </div>
  614. </div>
  615. </Section>
  616. </div>
  617. {/* System Details */}
  618. <Section title={t('system.systemDetails', 'System Details')} icon={Server}>
  619. <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
  620. <StatCard
  621. icon={Server}
  622. label={t('system.os', 'Operating System')}
  623. value={systemInfo.system.platform}
  624. subValue={systemInfo.system.platform_release}
  625. />
  626. <StatCard
  627. icon={Cpu}
  628. label={t('system.architecture', 'Architecture')}
  629. value={systemInfo.system.architecture}
  630. />
  631. <StatCard
  632. icon={Server}
  633. label={t('system.python', 'Python')}
  634. value={systemInfo.system.python_version}
  635. />
  636. <StatCard
  637. icon={Clock}
  638. label={t('system.bootTime', 'Boot Time')}
  639. value={formatDateTime(systemInfo.system.boot_time, timeFormat)}
  640. />
  641. </div>
  642. </Section>
  643. {diagnosticPrinter && (
  644. <ConnectionDiagnosticModal
  645. printerId={diagnosticPrinter.id}
  646. printerName={diagnosticPrinter.name}
  647. onClose={() => setDiagnosticPrinter(null)}
  648. />
  649. )}
  650. </div>
  651. );
  652. }