Skip to content

Commit e0a40fd

Browse files
committed
fix(web-ui): address CodeRabbit review findings
- remove duplicate agentsPath key in app.js data() - wrap localStorage.setItem for claudeConfigs in try/catch - use locale-neutral weekdayKeys in logic layer, localize in computed - guard weekdayLabels fallback and max division-by-zero - normalize fallback tooltip tokenTotal to prevent null render
1 parent 077e906 commit e0a40fd

5 files changed

Lines changed: 9 additions & 10 deletions

File tree

tests/unit/session-usage.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ test('buildUsageHourlyHeatmap produces 7x24 grid with correct aggregation', () =
119119
assert.strictEqual(result.range, '7d');
120120
assert.strictEqual(result.grid.length, 7);
121121
assert.strictEqual(result.grid[0].length, 24);
122-
assert.strictEqual(result.weekdayLabels.length, 7);
122+
assert.strictEqual(result.weekdayKeys.length, 7);
123123
assert.strictEqual(result.hourLabels.length, 24);
124124

125125
const april6Dow = (new Date(Date.UTC(2026, 3, 6)).getUTCDay() + 6) % 7;

web-ui/app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ document.addEventListener('DOMContentLoaded', () => {
112112
_pendingCodexApplyOptions: null,
113113
agentsContent: '',
114114
agentsPath: '',
115-
agentsPath: '',
116115
agentsExists: false,
117116
agentsLineEnding: '\n',
118117
agentsLoading: false,

web-ui/logic.sessions.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export function buildUsageHourlyHeatmap(sessions = [], options = {}) {
352352
range,
353353
grid,
354354
maxSessionCount: Math.max(1, maxSessionCount),
355-
weekdayLabels: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
355+
weekdayKeys: [0, 1, 2, 3, 4, 5, 6],
356356
hourLabels: Array.from({ length: 24 }, (_, index) => String(index).padStart(2, '0'))
357357
};
358358
}

web-ui/modules/app.computed.session.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,13 @@ export function createSessionComputed() {
588588
const result = buildUsageHourlyHeatmap(sessions, { range: this.sessionsUsageTimeRange });
589589
const t = typeof this.t === 'function' ? this.t : null;
590590
const lang = typeof this.lang === 'string' ? this.lang.trim().toLowerCase() : '';
591-
const weekdayLabels = lang === 'en'
592-
? ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
593-
: result.weekdayLabels;
594-
const max = result.maxSessionCount;
591+
const weekdayLabelsZh = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
592+
const weekdayLabelsEn = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
593+
const weekdayLabels = lang === 'en' ? weekdayLabelsEn : weekdayLabelsZh;
594+
const max = Math.max(1, result.maxSessionCount);
595595
const grid = Array.isArray(result.grid) ? result.grid : [];
596596
const rows = grid.map((cells, dayIndex) => ({
597-
weekday: weekdayLabels[dayIndex],
597+
weekday: weekdayLabels[dayIndex] || '',
598598
cells: cells.map((cell, hourIndex) => {
599599
const ratio = cell.sessionCount > 0 ? (cell.sessionCount / max) : 0;
600600
const level = cell.sessionCount <= 0
@@ -609,7 +609,7 @@ export function createSessionComputed() {
609609
messages: cell.messageCount,
610610
tokens: (cell.tokenTotal || 0).toLocaleString('en-US')
611611
})
612-
: `${weekdayLabels[dayIndex]} ${hourLabel}:00 · ${cell.sessionCount} sessions · ${cell.messageCount} messages · ${cell.tokenTotal} tokens`;
612+
: `${weekdayLabels[dayIndex] || ''} ${hourLabel}:00 · ${cell.sessionCount} sessions · ${cell.messageCount} messages · ${(cell.tokenTotal || 0).toLocaleString('en-US')} tokens`;
613613
return {
614614
hour: hourIndex,
615615
hourLabel,

web-ui/modules/app.methods.claude-config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function createClaudeConfigMethods(options = {}) {
3737
},
3838

3939
saveClaudeConfigs() {
40-
localStorage.setItem('claudeConfigs', JSON.stringify(this.claudeConfigs));
40+
try { localStorage.setItem('claudeConfigs', JSON.stringify(this.claudeConfigs)); } catch (_) {}
4141
if (this.currentClaudeConfig) {
4242
try { localStorage.setItem('currentClaudeConfig', this.currentClaudeConfig); } catch (_) {}
4343
}

0 commit comments

Comments
 (0)