Skip to content

feat(overview): add Today time window and make it the default - #369

Merged
caigee-cmd merged 1 commit into
caigee-cmd:mainfrom
haocheng23:feat/overview-today-window
Oct 23, 2026
Merged

caigee-cmd merged 1 commit into
caigee-cmd:mainfrom
haocheng23:feat/overview-today-window

Conversation

@haocheng23

Copy link
Copy Markdown
Contributor

Summary

  • 概览页顶部时间切换新增「今天」选项:按本地零点(Asia/Shanghai)到当前的日历日统计,排在「1小时」之前。
  • 概览页默认时间窗口改为「今天」(原为 24 小时)。
  • 复用上游已有的共享窗口抽象 frontend/src/lib/statsWindow.ts:StatsWindow 增加 'today',statsQuery 对 'today' 只下发 from(本地零点 ISO)。后端 Recorder.Stats 在缺省 to 时默认取当前时刻,因此无需改动后端。
  • 前端经 //go:embed all:static 打进二进制,已执行 npm run sync 重新生成 internal/webui/static:index.html 与新哈希 JS 一起替换,未保留旧 index-*.js。
 frontend/src/lib/statsWindow.ts
-export type StatsWindow = '1' | '24' | '168' | '720' | 'custom'
+export type StatsWindow = 'today' | '1' | '24' | '168' | '720' | 'custom'
 export const STATS_WINDOW_LABEL: Record<StatsWindow, string> = {
+  today: 'statsWindowToday',
   '1': 'statsWindow1h',
   ...

 export function statsQuery(window, custom) {
+  if (window === 'today') {
+    const start = new Date(); start.setHours(0, 0, 0, 0)
+    return { from: start.toISOString() }
+  }
   if (window === 'custom') { ... }
 }

 frontend/src/pages/OverviewPage.tsx
-  const [statsWindow, setStatsWindow] = useState<StatsWindow>('24')
+  const [statsWindow, setStatsWindow] = useState<StatsWindow>('today')

 frontend/src/i18n/messages.ts
+    statsWindowToday: 'Today',   // EN
+    statsWindowToday: '今天',     // ZH

UsagePage 复用同一个 StatsWindowControls,因此「今天」在用量页同样可用;其默认值仍保持 24h,未改动。

Test plan

  • cd frontend && npm run build && npm run lint — tsc -b && vite build 通过;oxlint 0 error(35 条 warning 为既有)
  • 已新增 changelog/unreleased/overview-today-window.md(中英双语,release-notes.py validate 通过)
  • npm run sync 已重新生成 internal/webui/static,index.html 与资产哈希一致
  • diff 中无 token / auth / 主机信息
  • go test ./... / go vet ./... — 本 PR 未改 Go 源码(仅内嵌静态产物替换);当前环境无 Go 工具链,交由 CI 兜底
  • cd worker && npm test — 未涉及

- Add a "Today" option to the shared stats window switcher: a calendar day
  from local midnight to now, sent as an explicit `from` (backend defaults
  `to` to now). Placed before 1h.
- Overview page now defaults to the Today window on load (was 24h).
- Rebuild embedded console assets (internal/webui/static).
@caigee-cmd
caigee-cmd merged commit 5797a7c into caigee-cmd:main Oct 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants