Skip to content

Commit 43a9f55

Browse files
authored
Merge pull request #71 from ownpilot/refactor/systempage-constants
refactor(ui): extract SystemPage pure data into SystemPage.constants
2 parents 445941e + 145ac62 commit 43a9f55

2 files changed

Lines changed: 44 additions & 37 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* SystemPage pure data + helpers.
3+
*
4+
* Extracted from SystemPage.tsx — no React: uptime formatting, the tool
5+
* dependency category color map, and the CSV export/import table list.
6+
*/
7+
8+
/** Format a duration in seconds as a compact `1d 2h 3m 4s` string. */
9+
export function formatUptime(seconds: number): string {
10+
const days = Math.floor(seconds / 86400);
11+
const hours = Math.floor((seconds % 86400) / 3600);
12+
const minutes = Math.floor((seconds % 3600) / 60);
13+
const secs = Math.floor(seconds % 60);
14+
15+
const parts: string[] = [];
16+
if (days > 0) parts.push(`${days}d`);
17+
if (hours > 0) parts.push(`${hours}h`);
18+
if (minutes > 0) parts.push(`${minutes}m`);
19+
if (secs > 0 || parts.length === 0) parts.push(`${secs}s`);
20+
21+
return parts.join(' ');
22+
}
23+
24+
/** Category color map for tool dependency badges. */
25+
export const CATEGORY_COLORS: Record<string, string> = {
26+
Email: 'bg-blue-500/10 text-blue-600 dark:text-blue-400',
27+
Image: 'bg-purple-500/10 text-purple-600 dark:text-purple-400',
28+
PDF: 'bg-red-500/10 text-red-600 dark:text-red-400',
29+
Audio: 'bg-green-500/10 text-green-600 dark:text-green-400',
30+
'Coding Agents': 'bg-orange-500/10 text-orange-600 dark:text-orange-400',
31+
};
32+
33+
/** Tables available for CSV export/import. */
34+
export const CSV_TABLES = [
35+
'expenses',
36+
'habits',
37+
'bookmarks',
38+
'notes',
39+
'tasks',
40+
'contacts',
41+
'calendar_events',
42+
'captures',
43+
] as const;

packages/ui/src/pages/SystemPage.tsx

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,7 @@ import { systemApi } from '../api';
3131
import type { SandboxStatus, DatabaseStatus, BackupInfo, DatabaseStats } from '../api';
3232
import type { ToolDependenciesResponse } from '../api/endpoints/misc';
3333
import { PageHomeTab } from '../components/PageHomeTab';
34-
35-
// Helper to format uptime
36-
function formatUptime(seconds: number): string {
37-
const days = Math.floor(seconds / 86400);
38-
const hours = Math.floor((seconds % 86400) / 3600);
39-
const minutes = Math.floor((seconds % 3600) / 60);
40-
const secs = Math.floor(seconds % 60);
41-
42-
const parts: string[] = [];
43-
if (days > 0) parts.push(`${days}d`);
44-
if (hours > 0) parts.push(`${hours}h`);
45-
if (minutes > 0) parts.push(`${minutes}m`);
46-
if (secs > 0 || parts.length === 0) parts.push(`${secs}s`);
47-
48-
return parts.join(' ');
49-
}
50-
51-
// Category color map for tool dependency badges
52-
const CATEGORY_COLORS: Record<string, string> = {
53-
Email: 'bg-blue-500/10 text-blue-600 dark:text-blue-400',
54-
Image: 'bg-purple-500/10 text-purple-600 dark:text-purple-400',
55-
PDF: 'bg-red-500/10 text-red-600 dark:text-red-400',
56-
Audio: 'bg-green-500/10 text-green-600 dark:text-green-400',
57-
'Coding Agents': 'bg-orange-500/10 text-orange-600 dark:text-orange-400',
58-
};
59-
60-
// Tables available for CSV export/import
61-
const CSV_TABLES = [
62-
'expenses',
63-
'habits',
64-
'bookmarks',
65-
'notes',
66-
'tasks',
67-
'contacts',
68-
'calendar_events',
69-
'captures',
70-
] as const;
34+
import { formatUptime, CATEGORY_COLORS, CSV_TABLES } from './SystemPage.constants';
7135

7236
export function SystemPage() {
7337
const [searchParams] = useSearchParams();

0 commit comments

Comments
 (0)