Skip to content

Commit a369cf5

Browse files
committed
refactor: extract dashboard formatters
1 parent 8826223 commit a369cf5

2 files changed

Lines changed: 31 additions & 25 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { DashboardAccountSortMode } from "../dashboard-settings.js";
2+
3+
export function formatDashboardSettingState(value: boolean): string {
4+
return value ? "[x]" : "[ ]";
5+
}
6+
7+
export function formatMenuSortMode(mode: DashboardAccountSortMode): string {
8+
return mode === "ready-first" ? "Ready-First" : "Manual";
9+
}
10+
11+
export function formatMenuLayoutMode(
12+
mode: "compact-details" | "expanded-rows",
13+
): string {
14+
return mode === "expanded-rows" ? "Expanded Rows" : "Compact + Details Pane";
15+
}
16+
17+
export function formatMenuQuotaTtl(ttlMs: number): string {
18+
if (ttlMs >= 60_000 && ttlMs % 60_000 === 0) {
19+
return `${Math.round(ttlMs / 60_000)}m`;
20+
}
21+
if (ttlMs >= 1_000 && ttlMs % 1_000 === 0) {
22+
return `${Math.round(ttlMs / 1_000)}s`;
23+
}
24+
return `${ttlMs}ms`;
25+
}

lib/codex-manager/settings-hub.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { createInterface } from "node:readline/promises";
33
import { loadPluginConfig, savePluginConfig } from "../config.js";
44
import {
55
type DashboardAccentColor,
6-
type DashboardAccountSortMode,
76
type DashboardDisplaySettings,
87
type DashboardStatuslineField,
98
type DashboardThemePreset,
@@ -51,6 +50,12 @@ import {
5150
} from "./backend-settings-schema.js";
5251
import { promptBehaviorSettingsPanel } from "./behavior-settings-panel.js";
5352
import { promptDashboardDisplayPanel } from "./dashboard-display-panel.js";
53+
import {
54+
formatDashboardSettingState,
55+
formatMenuLayoutMode,
56+
formatMenuQuotaTtl,
57+
formatMenuSortMode,
58+
} from "./dashboard-formatters.js";
5459
import {
5560
cloneDashboardSettingsData,
5661
dashboardSettingsDataEqual,
@@ -500,14 +505,6 @@ function applyUiThemeFromDashboardSettings(
500505
});
501506
}
502507

503-
function formatDashboardSettingState(value: boolean): string {
504-
return value ? "[x]" : "[ ]";
505-
}
506-
507-
function formatMenuSortMode(mode: DashboardAccountSortMode): string {
508-
return mode === "ready-first" ? "Ready-First" : "Manual";
509-
}
510-
511508
function resolveMenuLayoutMode(
512509
settings: DashboardDisplaySettings,
513510
): "compact-details" | "expanded-rows" {
@@ -522,22 +519,6 @@ function resolveMenuLayoutMode(
522519
: "compact-details";
523520
}
524521

525-
function formatMenuLayoutMode(
526-
mode: "compact-details" | "expanded-rows",
527-
): string {
528-
return mode === "expanded-rows" ? "Expanded Rows" : "Compact + Details Pane";
529-
}
530-
531-
function formatMenuQuotaTtl(ttlMs: number): string {
532-
if (ttlMs >= 60_000 && ttlMs % 60_000 === 0) {
533-
return `${Math.round(ttlMs / 60_000)}m`;
534-
}
535-
if (ttlMs >= 1_000 && ttlMs % 1_000 === 0) {
536-
return `${Math.round(ttlMs / 1_000)}s`;
537-
}
538-
return `${ttlMs}ms`;
539-
}
540-
541522
async function withQueuedRetryForTests<T>(
542523
pathKey: string,
543524
task: () => Promise<T>,

0 commit comments

Comments
 (0)