Repository navigation
設定モーダルの列車種別選択で直近の停車駅の列車種別を取得する - #5678
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
📝 WalkthroughWalkthrough訓練タイプ選択フローを新しいフック Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Permitted as Permitted Component
participant Hook as useTrainTypeModal Hook
participant Apollo as Apollo Client
participant Jotai as Jotai Atoms
User->>Permitted: 設定アクションをクリック
Permitted->>Hook: openSettingListModal()
Hook->>Hook: isSettingListModalOpen = true
User->>Permitted: 訓練タイプ候補を押す
Permitted->>Hook: handleTrainTypePress(stoppingStationId)
Hook->>Apollo: useLazyQuery(GET_STATION_TRAIN_TYPES_LIGHT) with stationId
Apollo-->>Hook: fetched train types
Hook->>Hook: fetchedTrainTypesをセット、loading制御
User->>Permitted: 設定リストを閉じる(アニメ完了)
Permitted->>Hook: handleSettingListCloseAnimationEnd()
Hook->>Hook: isTrainTypeModalVisible = true
User->>Permitted: 訓練タイプを選択
Permitted->>Hook: handleTrainTypeModalSelect(selectedTrainType)
Hook->>Apollo: useLazyQuery(GET_LINE_GROUP_STATIONS) with lineGroupId
Apollo-->>Hook: fetched stations
Hook->>Jotai: setStations / update navigation state / reset speech as必要
Hook->>Hook: isTrainTypeModalVisible = false
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/hooks/useTrainTypeModal.test.tsx (1)
202-204:afterEachはjest.clearAllMocks()に揃えたいです。この suite は
setupMocks()で毎回実装を組み直しているので、ここで必要なのは呼び出し履歴のクリアだけです。resetAllMocks()だと実装まで消えるため、リポジトリのテスト規約から少し外れます。As per coding guidelines, "Mock network and Firebase layers with jest.mock, and call jest.clearAllMocks() in afterEach".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useTrainTypeModal.test.tsx` around lines 202 - 204, The test suite's afterEach currently calls jest.resetAllMocks(), which clears mock implementations set up by setupMocks(); replace that call with jest.clearAllMocks() so only call histories are cleared while mocked implementations provided by setupMocks() remain intact (update the afterEach that references jest.resetAllMocks() to call jest.clearAllMocks() instead).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/hooks/useTrainTypeModal.ts`:
- Around line 35-42: The modal opens before fetchTrainTypes resolves and uses
trainTypeSelectLoading (which is for GET_LINE_GROUP_STATIONS) instead of the
fetchTrainTypes loading state, and it never clears fetchedTrainTypes on
empty/error; update the logic around fetchTrainTypes (the useLazyQuery for
GET_STATION_TRAIN_TYPES_LIGHT) so you wait for its completion before opening
TrainTypeListModal (or at least set fetchedTrainTypes = [] immediately when
starting the fetch), derive and use the loading flag from the fetchTrainTypes
query result (not trainTypeSelectLoading), and on success/empty/error always
replace fetchedTrainTypes with the response (or empty array) so the modal shows
the current result and receives a proper loading prop to disable selection until
fetch completes.
---
Nitpick comments:
In `@src/hooks/useTrainTypeModal.test.tsx`:
- Around line 202-204: The test suite's afterEach currently calls
jest.resetAllMocks(), which clears mock implementations set up by setupMocks();
replace that call with jest.clearAllMocks() so only call histories are cleared
while mocked implementations provided by setupMocks() remain intact (update the
afterEach that references jest.resetAllMocks() to call jest.clearAllMocks()
instead).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 08841cae-1690-4f46-957b-f8d56d3d2167
📒 Files selected for processing (3)
src/components/Permitted.tsxsrc/hooks/useTrainTypeModal.test.tsxsrc/hooks/useTrainTypeModal.ts
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/hooks/useTrainTypeModal.ts (1)
125-142:⚠️ Potential issue | 🟠 Major取得失敗を
[]と同一視すると再試行できなくなります。ここは開始時に
fetchedTrainTypesを空へ戻していますが、失敗を区別する state がありません。通信失敗でも次回trainTypeDisabledがtrueになって設定モーダルから列車種別取得を再試行できなくなるので、空結果とエラーを分けるか、少なくとも失敗時は入口を無効化しないようにしたいです。Also applies to: 170-170
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/hooks/useTrainTypeModal.ts` around lines 125 - 142, handleTrainTypePress currently clears fetchedTrainTypes to [] immediately which conflates “no results” with “fetch failed” and prevents retry; change it to not reset fetchedTrainTypes to [] on start and instead track loading/error or only update fetchedTrainTypes on success, and add error handling for fetchTrainTypes (use .catch or try/catch) to set a fetchedTrainTypesError or clear a loading flag so the entry/button (e.g., trainTypeDisabled) is not disabled on network failure; locate and update the handleTrainTypePress callback, the setNavigation calls that touch fetchedTrainTypes, and the fetchTrainTypes .then chain to implement the error path that preserves retry ability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/hooks/useTrainTypeModal.ts`:
- Around line 125-142: handleTrainTypePress currently clears fetchedTrainTypes
to [] immediately which conflates “no results” with “fetch failed” and prevents
retry; change it to not reset fetchedTrainTypes to [] on start and instead track
loading/error or only update fetchedTrainTypes on success, and add error
handling for fetchTrainTypes (use .catch or try/catch) to set a
fetchedTrainTypesError or clear a loading flag so the entry/button (e.g.,
trainTypeDisabled) is not disabled on network failure; locate and update the
handleTrainTypePress callback, the setNavigation calls that touch
fetchedTrainTypes, and the fetchTrainTypes .then chain to implement the error
path that preserves retry ability.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1eabc01c-c449-4862-8edb-6b9ed7182d7f
📒 Files selected for processing (3)
src/components/Permitted.tsxsrc/hooks/useTrainTypeModal.test.tsxsrc/hooks/useTrainTypeModal.ts
✅ Files skipped from review due to trivial changes (1)
- src/hooks/useTrainTypeModal.test.tsx
Summary
currentLine(現在の駅の路線)を優先するように変更useTrainTypeModalカスタムフックに切り出し、Permitted.tsxからビジネスロジックを分離useCurrentStation(true)でスキップし、停車駅のみを対象にフェッチTest plan
npm run typecheckパスnpm run lintパスnpm test全1331テストパス(新規10テスト含む)🤖 Generated with Claude Code
Summary by CodeRabbit
リリースノート
New Features
Refactor
Tests