Skip to content

fix: address PR 793 review comments#796

Merged
otomatty merged 2 commits into
developfrom
fix/pr-793-admin-locale-formatting
May 2, 2026
Merged

fix: address PR 793 review comments#796
otomatty merged 2 commits into
developfrom
fix/pr-793-admin-locale-formatting

Conversation

@otomatty
Copy link
Copy Markdown
Owner

@otomatty otomatty commented May 2, 2026

概要

PR #793 の未対応レビューコメントに対する develop 向け修正です。Admin のロケール固定表示、メンバー管理 read-only TSDoc、HeadingLevelClamp の不要処理、Hocuspocus shutdown のエラーハンドリングをまとめて対応します。

変更点

  • admin/: 日付・数値整形を i18n の現在言語に応じたロケールへ変更し、ja / en のテストを追加
  • src/: NoteMembersManageSectionreadOnly TSDoc を実装済み UI 契約に同期
  • src/: HeadingLevelClamp で doc 変更のない transaction をスキップし、必要になるまで state.tr を作らないように変更
  • server/hocuspocus/: SIGTERM / SIGINT の shutdown 処理を共通化し、失敗時にログ出力して exit(1) するように変更

変更の種類

  • 🐛 バグ修正 (Bug fix)
  • ✨ 新機能 (New feature)
  • 💥 破壊的変更 (Breaking change)
  • 📝 ドキュメント (Documentation)
  • 🎨 スタイル/リファクタリング (Style/Refactor)
  • 🧪 テスト (Tests)
  • 🔧 ビルド/CI (Build/CI)

テスト方法

  1. bunx prettier --check admin/src/lib/dateUtils.ts admin/src/lib/dateUtils.test.ts admin/src/pages/users/UsersContent.tsx admin/src/pages/users/UsersContent.test.tsx admin/src/pages/users/UserCard.tsx
  2. bunx eslint admin/src/lib/dateUtils.ts admin/src/lib/dateUtils.test.ts admin/src/pages/users/UsersContent.tsx admin/src/pages/users/UsersContent.test.tsx admin/src/pages/users/UserCard.tsx
  3. bunx vitest run --config admin/vitest.config.ts admin/src/lib/dateUtils.test.ts admin/src/pages/users/UsersContent.test.tsx
  4. bunx prettier --check src/pages/NoteMembers/NoteMembersManageSection.tsx src/components/editor/TiptapEditor/headingLevelClampExtension.ts server/hocuspocus/src/index.ts
  5. bunx eslint src/pages/NoteMembers/NoteMembersManageSection.tsx src/components/editor/TiptapEditor/headingLevelClampExtension.ts server/hocuspocus/src/index.ts
  6. bunx vitest run src/components/editor/TiptapEditor/headingLevelClampExtension.test.ts src/pages/NoteMembers/NoteMembersManageSection.test.tsx
  7. cd server/hocuspocus && bun run build

チェックリスト

  • テストがすべてパスする
  • Lint エラーがない
  • 必要に応じてドキュメントを更新した
  • コミットメッセージが Conventional Commits に従っている

スクリーンショット(UI 変更がある場合)

表示フォーマット・TSDoc・内部処理の修正のため未添付です。

関連 Issue

Related to #793

Summary by CodeRabbit

  • New Features

    • Date and number formatting now follow the app language (e.g., Japanese vs. US English) across admin user lists and cards.
  • Documentation

    • Clarified read-only behavior and visible status badges for member management.
  • Tests

    • Expanded tests to cover locale selection, date formatting, and number formatting.
  • Chores

    • Improved server shutdown handling for more reliable process termination.

The admin UI uses i18next, but several user-management views were still
calling toLocaleDateString("ja-JP") / toLocaleString("ja-JP") directly.
When the admin language is switched to English, dates and counts kept
rendering in Japanese format, defeating the i18n setup.

- admin/src/lib/dateUtils.ts: add getActiveLocale() and formatNumber(),
  make formatDate() honour the active i18n locale.
- UsersContent.tsx / UserCard.tsx: route the three remaining hardcoded
  ja-JP call sites through these helpers (table row pageCount, mobile
  card pageCount, and the delete-impact lastAiUsageAt date).
- dateUtils.test.ts: cover ja/en locale switching and formatNumber.
- UsersContent.test.tsx: keep the mock backwards compatible with the
  existing "1,234" assertion under the test setup's forced ja locale.

Addresses devin-ai PR #793 review.

Made-with: Cursor
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7fb7b363-2688-4076-9c4a-0f8470e8d620

📥 Commits

Reviewing files that changed from the base of the PR and between 5f209ff and 406f40f.

📒 Files selected for processing (3)
  • server/hocuspocus/src/index.ts
  • src/components/editor/TiptapEditor/headingLevelClampExtension.ts
  • src/pages/NoteMembers/NoteMembersManageSection.tsx
✅ Files skipped from review due to trivial changes (1)
  • src/pages/NoteMembers/NoteMembersManageSection.tsx

📝 Walkthrough

Walkthrough

Locale-aware formatting added: getActiveLocale() returns "ja-JP" or "en-US" based on i18n; formatDate() and new formatNumber() use it. UI components and tests updated to use these utilities. Several unrelated small changes added (graceful shutdown, tiptap clamp tweak, JSDoc).

Changes

Locale-aware Date and Number Formatting

Layer / File(s) Summary
Data Shape / Utility API
admin/src/lib/dateUtils.ts
Added `getActiveLocale(): "ja-JP"
Core Implementation
admin/src/lib/dateUtils.ts
Implements locale derivation from i18n.language primary subtag and delegates formatting to toLocaleDateString / toLocaleString with the active locale.
Wiring / Integration
admin/src/pages/users/UserCard.tsx, admin/src/pages/users/UsersContent.tsx
Replaced direct toLocaleString("ja-JP") and hardcoded "ja-JP" date usage with formatNumber(...) and toLocaleDateString(getActiveLocale()). Updated imports.
Tests / Mocks
admin/src/lib/dateUtils.test.ts, admin/src/pages/users/UsersContent.test.tsx
Added tests for getActiveLocale, expanded formatDate tests to switch `i18n.changeLanguage("ja"

Graceful Shutdown Consolidation

Layer / File(s) Summary
Core Implementation
server/hocuspocus/src/index.ts
Added gracefulShutdown(signal) helper that logs the signal, awaits hocuspocusServer.destroy(), closes pgPool if present, and exits with 0 or 1 on failure.
Wiring / Signal Handlers
server/hocuspocus/src/index.ts
Replaced inline SIGTERM / SIGINT handlers to call gracefulShutdown(...) for shared error handling.

Tiptap Heading Clamp Behavior

Layer / File(s) Summary
Core Implementation
src/components/editor/TiptapEditor/headingLevelClampExtension.ts
buildHeadingClampTr now lazily constructs a `Transaction
Performance Guard
src/components/editor/TiptapEditor/headingLevelClampExtension.ts
appendTransaction now early-returns null if none of the incoming transactions have docChanged, avoiding unnecessary clamp checks.

Docs / JSDoc Clarification

Layer / File(s) Summary
Documentation
src/pages/NoteMembers/NoteMembersManageSection.tsx
JSDoc for readOnly prop updated to enumerate hidden/disabled UI elements and to include declined in visible status badges.

Sequence Diagram(s)

sequenceDiagram
participant UI
participant DateUtils
participant i18n
UI->>DateUtils: render -> formatDate/formatNumber(value)
DateUtils->>i18n: read language
i18n-->>DateUtils: language (e.g., "ja" / "en")
DateUtils->>DateUtils: derive getActiveLocale()
DateUtils-->>UI: formatted string (locale-aware)
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through locales, sniffed the breeze,

"ja" or "en", I'll choose with ease.
Dates and numbers now dress to match,
No more hardcode stuck in a patch.
A rabbit claps—formatting's at peace!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title "fix: address PR 793 review comments" is vague and does not describe the actual substantive changes (locale-aware date/number formatting in the admin UI). Replace with a more specific title such as "fix(admin): locale-aware date and number formatting" or similar, which clearly reflects the primary technical change.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pr-793-admin-locale-formatting

Review rate limit: 3/5 reviews remaining, refill in 18 minutes and 46 seconds.

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

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces dynamic localization for date and number formatting by replacing hardcoded "ja-JP" strings with a new getActiveLocale utility and adding corresponding tests. The review feedback suggests improving consistency in UsersContent.tsx by using the formatDate helper instead of a manual toLocaleDateString call, which would also permit the removal of the getActiveLocale import in that file.

} from "@zedi/ui";
import type { UserAdmin, UserRole, UserStatus } from "@/api/admin";
import { formatDate } from "@/lib/dateUtils";
import { formatDate, formatNumber, getActiveLocale } from "@/lib/dateUtils";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

getActiveLocaleformatDate 内部で使用されており、コンポーネント側で直接呼び出す必要がなくなるため、インポートから削除できます。

Suggested change
import { formatDate, formatNumber, getActiveLocale } from "@/lib/dateUtils";
import { formatDate, formatNumber } from "@/lib/dateUtils";

Comment on lines 388 to 390
date: new Date(confirm.deleteTarget.impact.lastAiUsageAt).toLocaleDateString(
"ja-JP",
getActiveLocale(),
),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

既に formatDate ユーティリティが定義されているため、ここでもそれを利用することでコードの重複を避け、日付形式(0埋めなど)の統一性を保つことができます。また、formatDate は内部で getActiveLocale() を呼び出しており、不正な日付入力に対するハンドリングも含まれているため、より安全です。

                    date: formatDate(confirm.deleteTarget.impact.lastAiUsageAt),

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
admin/src/pages/users/UsersContent.tsx (1)

20-20: ⚡ Quick win

Use formatDate for delete-impact date to keep date output consistent.

This path currently skips the shared formatting options/invalid-date handling used elsewhere.

Proposed refactor
-import { formatDate, formatNumber, getActiveLocale } from "@/lib/dateUtils";
+import { formatDate, formatNumber } from "@/lib/dateUtils";
...
-                    date: new Date(confirm.deleteTarget.impact.lastAiUsageAt).toLocaleDateString(
-                      getActiveLocale(),
-                    ),
+                    date: formatDate(confirm.deleteTarget.impact.lastAiUsageAt),

Also applies to: 388-390

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@admin/src/pages/users/UsersContent.tsx` at line 20, The delete-impact date
rendering in UsersContent currently bypasses shared date formatting and
invalid-date handling by using getActiveLocale/formatNumber; change both
occurrences (around the import and the other instance at lines ~388-390) to call
the shared formatDate helper instead, passing the same date value and any
existing options so invalid-date handling is preserved; update the JSX where the
delete-impact value is displayed to use formatDate(dateValue) (or
formatDate(dateValue, options) if options are used) and remove the ad-hoc
locale/number formatting logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@admin/src/pages/users/UsersContent.tsx`:
- Line 20: The delete-impact date rendering in UsersContent currently bypasses
shared date formatting and invalid-date handling by using
getActiveLocale/formatNumber; change both occurrences (around the import and the
other instance at lines ~388-390) to call the shared formatDate helper instead,
passing the same date value and any existing options so invalid-date handling is
preserved; update the JSX where the delete-impact value is displayed to use
formatDate(dateValue) (or formatDate(dateValue, options) if options are used)
and remove the ad-hoc locale/number formatting logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 20627fc2-5639-41a5-8ed6-52e5bfe289bd

📥 Commits

Reviewing files that changed from the base of the PR and between 346c98d and 5f209ff.

📒 Files selected for processing (5)
  • admin/src/lib/dateUtils.test.ts
  • admin/src/lib/dateUtils.ts
  • admin/src/pages/users/UserCard.tsx
  • admin/src/pages/users/UsersContent.test.tsx
  • admin/src/pages/users/UsersContent.tsx

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Co-authored-by: Cursor <cursoragent@cursor.com>
@otomatty otomatty changed the title fix(admin): locale-aware date and number formatting fix: address PR 793 review comments May 2, 2026
@otomatty otomatty merged commit 74cdbaa into develop May 2, 2026
17 checks passed
@otomatty otomatty deleted the fix/pr-793-admin-locale-formatting branch May 2, 2026 02:23
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.

1 participant