Skip to content

設定モーダルの列車種別選択で直近の停車駅の列車種別を取得する - #5678

Merged
TinyKitten merged 2 commits into
devfrom
feature/train-type-modal-current-station
Mar 26, 2026
Merged

TinyKitten merged 2 commits into
devfrom
feature/train-type-modal-current-station

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 26, 2026 •

Copy link
Copy Markdown
Member

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

    • コンポーネント内の列車種別/モーダルロジックをフックへ移行し、UIがより簡潔に。
  • Tests

    • 新フックの振る舞いを検証する単体テストを追加しました(選択・取得・遷移を網羅)。

@github-actions github-actions Bot added the react label Mar 26, 2026
@coderabbitai

coderabbitai Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

訓練タイプ選択フローを新しいフックuseTrainTypeModalに抽出し、Permittedコンポーネントはローカルのモーダル/選択ロジックを削除してフックへ委譲。フックはJotai連携とApolloの2つのlazyクエリで駅・訓練タイプの取得とモーダル遷移を管理。単体テストが追加された。

Changes

Cohort / File(s) Summary
新フック実装
src/hooks/useTrainTypeModal.ts
訓練タイプ選択のモーダル状態、フェッチ(GET_STATION_TRAIN_TYPES_LIGHT, GET_LINE_GROUP_STATIONSのuseLazyQuery)、Jotai原子更新、選択フロー(selectedBoundによる分岐)、クローズアニメ完了ハンドラ等を提供する新フックを追加。
コンポーネント統合
src/components/Permitted.tsx
ローカルのuseState/useRefベースの訓練タイプ・モーダル制御、選択ロジック、GraphQL参照を削除。useTrainTypeModalから返る状態・ハンドラへ差し替え。レンダープロップの更新(SelectBoundSettingListModal / TrainTypeListModal)。
テスト追加
src/hooks/useTrainTypeModal.test.tsx
フックの単体テストを追加。Apolloのlazyクエリ、Jotai原子、通過駅処理、モーダル表示・選択フロー、fetch結果に伴う状態遷移をモックして検証。

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 新フックでぴょんと跳び、
モーダルの道筋すっきりと、
駅とタイプつなぎ合わせ、
テストで跳ね返すバグ、
今日もコードで跳ねるよ!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR タイトルは、通過駅をスキップして直近の停車駅の列車種別を取得するという主要な変更を正確に反映している。簡潔で具体的な表現により、チームメンバーは履歴を確認する際に本 PR の主要な意図を明確に理解できる。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 feature/train-type-modal-current-station

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

@TinyKitten TinyKitten self-assigned this Mar 26, 2026

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 30e2727 and 1df950a.

📒 Files selected for processing (3)
  • src/components/Permitted.tsx
  • src/hooks/useTrainTypeModal.test.tsx
  • src/hooks/useTrainTypeModal.ts

Comment thread src/hooks/useTrainTypeModal.ts Resolved

@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.

♻️ 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1df950a and 7192cd0.

📒 Files selected for processing (3)
  • src/components/Permitted.tsx
  • src/hooks/useTrainTypeModal.test.tsx
  • src/hooks/useTrainTypeModal.ts
✅ Files skipped from review due to trivial changes (1)
  • src/hooks/useTrainTypeModal.test.tsx

@TinyKitten
TinyKitten merged commit 285e706 into dev Mar 26, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/train-type-modal-current-station branch March 26, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant