Skip to content

feat: add date range preset constants and use them in the log filter - #1809

Merged
creamlike1024 merged 2 commits into
QuantumNous:mainfrom
QuentinHsu:feature/date-shortcut
Sep 23, 2025
Merged

feat: add date range preset constants and use them in the log filter#1809
creamlike1024 merged 2 commits into
QuantumNous:mainfrom
QuentinHsu:feature/date-shortcut

Conversation

@QuentinHsu

@QuentinHsu QuentinHsu commented Sep 15, 2025

Copy link
Copy Markdown
Collaborator

如图:

image

Summary by CodeRabbit

  • New Features

    • Added quick-select date-range presets to MJ Logs, Task Logs, and Usage Logs filters (Today, Last 7 Days, This Week, Last 30 Days, This Month) for faster date filtering.
  • Localization

    • Added English translations for the new date range presets.

@coderabbitai

coderabbitai Bot commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a DATE_RANGE_PRESETS constant and integrates it into three log filter components' DatePicker as quick-select date ranges; includes corresponding English i18n entries. No public API or exported signature changes.

Changes

Cohort / File(s) Summary
Date range presets integration in log filters
web/src/components/table/mj-logs/MjLogsFilters.jsx, web/src/components/table/task-logs/TaskLogsFilters.jsx, web/src/components/table/usage-logs/UsageLogsFilters.jsx
Import DATE_RANGE_PRESETS and pass a mapped presets prop to Form.DatePicker: { text: t(preset.text), start: preset.start(), end: preset.end() }.
New console constants
web/src/constants/console.constants.js
Adds DATE_RANGE_PRESETS array with five presets (今天, 近 7 天, 本周, 近 30 天, 本月); each preset exposes start() and end() functions that return Date via dayjs computations.
Localization updates
web/src/i18n/locales/en.json
Adds English translations for the five time-range labels: "今天": "Today", "近 7 天": "Last 7 Days", "本周": "This Week", "近 30 天": "Last 30 Days", "本月": "This Month".

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant UI as LogsFilters UI
  participant DP as DatePicker (with presets)
  participant C as Component (Mj/Task/Usage Filters)
  participant S as Data Source / Logs Table

  U->>UI: Open date picker
  UI->>DP: Show presets (from DATE_RANGE_PRESETS)
  note right of DP #E6F7FF: presets: { text, start(), end() }
  U->>DP: Select preset
  DP-->>C: Emit selected { start, end }
  C->>S: Apply date filter and request data
  S-->>C: Return filtered logs
  C-->>UI: Render filtered logs
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A hop, a nibble, a preset found,
I pick the range and scroll around.
Today or month, a joyful twitch,
Logs appear at my small pitch.
Hooray — quick filters, neatly bound 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately captures the primary change: adding date range preset constants and applying them in the log filters. It is concise, specific to the feature, and matches the changes in the constants, i18n, and log filter components shown in the diff. There is no irrelevant noise or vague wording.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e34b5de and 92895eb.

📒 Files selected for processing (1)
  • web/src/i18n/locales/en.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/i18n/locales/en.json

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@QuentinHsu
QuentinHsu force-pushed the feature/date-shortcut branch from ef2d1a3 to e34b5de Compare September 15, 2025 13:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
web/src/components/table/task-logs/TaskLogsFilters.jsx (1)

24-25: Same presets concerns as MjLogsFilters

Applies equally here: confirm presets API, consider lazy start/end, and verify week start expectations.

Refer to the verification script shared in MjLogsFilters.

Also applies to: 59-63

web/src/components/table/usage-logs/UsageLogsFilters.jsx (1)

24-25: Same presets concerns as MjLogsFilters

Confirm presets API shape, consider passing start/end functions if supported, and validate week start (Sunday vs Monday).

Use the MjLogsFilters verification script.

Also applies to: 60-64

🧹 Nitpick comments (1)
web/src/constants/console.constants.js (1)

20-49: Solid preset definitions; clarify week start and centralize mapping helper

  • Today/Last 7/30 days math is correct (inclusive of today). “本周/本月” depend on dayjs locale; many locales default week start to Sunday. If Monday is desired, either update locale (updateLocale({ weekStart: 1 })) or use ISO week.

Option A (ISO week, if acceptable):

+import isoWeek from 'dayjs/plugin/isoWeek';
+dayjs.extend(isoWeek);
...
-    start: () => dayjs().startOf('week').toDate(),
-    end: () => dayjs().endOf('week').toDate()
+    start: () => dayjs().startOf('isoWeek').toDate(),
+    end: () => dayjs().endOf('isoWeek').toDate()

Option B (centralize UI mapping to reduce duplication):

+export const buildDateRangePresets = (t) =>
+  DATE_RANGE_PRESETS.map(({ text, start, end }) => ({
+    text: t(text),
+    start: start(),
+    end: end(),
+  }));

Then use presets={buildDateRangePresets(t)} in the three filters.

Please confirm the intended definition of “本周/This Week” for your audience and whether changing to ISO week is acceptable. Also verify there’s a global dayjs locale config already setting weekStart=1 if that’s the expectation.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18a385f and ef2d1a3.

📒 Files selected for processing (5)
  • web/src/components/table/mj-logs/MjLogsFilters.jsx (2 hunks)
  • web/src/components/table/task-logs/TaskLogsFilters.jsx (2 hunks)
  • web/src/components/table/usage-logs/UsageLogsFilters.jsx (2 hunks)
  • web/src/constants/console.constants.js (1 hunks)
  • web/src/i18n/locales/en.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
web/src/components/table/usage-logs/UsageLogsFilters.jsx (1)
web/src/constants/console.constants.js (2)
  • DATE_RANGE_PRESETS (23-49)
  • DATE_RANGE_PRESETS (23-49)
web/src/components/table/task-logs/TaskLogsFilters.jsx (1)
web/src/constants/console.constants.js (2)
  • DATE_RANGE_PRESETS (23-49)
  • DATE_RANGE_PRESETS (23-49)
web/src/components/table/mj-logs/MjLogsFilters.jsx (1)
web/src/constants/console.constants.js (2)
  • DATE_RANGE_PRESETS (23-49)
  • DATE_RANGE_PRESETS (23-49)
🔇 Additional comments (2)
web/src/i18n/locales/en.json (1)

2087-2092: Date‑range preset i18n — verified (no duplicates found)

Matches only in web/src/i18n/locales/en.json (lines 2088–2092); no other occurrences under web/src/i18n/locales. Add matching keys to other locale files (e.g., web/src/i18n/locales/zh.json) if translations are required.

web/src/components/table/mj-logs/MjLogsFilters.jsx (1)

24-25: Verify DatePicker presets API + prefer lazy evaluation; confirm week-start semantics

  • Semi Form.DatePicker supports a presets prop and, since v2.52, start/end may be functions — treat them as lazy if available. (semi.design)
  • If DATE_RANGE_PRESETS entries use functions, pass the functions (start/end) instead of calling them during render to avoid stale ranges across midnight; if they are Date values, keep current behavior. Example change (if presets are functions):
- presets={DATE_RANGE_PRESETS.map(preset => ({
-   text: t(preset.text),
-   start: preset.start(),
-   end: preset.end()
- }))}
+ presets={DATE_RANGE_PRESETS.map(preset => ({
+   text: t(preset.text),
+   start: preset.start,
+   end: preset.end
+ }))}
  • Inspect DATE_RANGE_PRESETS at web/src/constants/console.constants to confirm whether start/end are functions or Date objects (affects which approach to use).
  • Confirm “This Week” uses dayjs().startOf('week') (locale-aware) — dayjs.startOf('week') follows locale and may default to Sunday; either configure dayjs locale/updateLocale({ weekStart: 1 }) or use startOf('isoWeek') if your business expects Monday start. (day.js.org)

@creamlike1024
creamlike1024 merged commit 6992fd2 into QuantumNous:main Sep 23, 2025
1 check passed
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…tcut

feat: add date range preset constants and use them in the log filter
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