Skip to content

種別を自動選択した際に駅一覧を系統全体へ揃えて始発駅と終着駅のずれを防ぐ - #6644

Merged
TinyKitten merged 2 commits into
devfrom
claude/preset-auto-origin-station-5rjpbd
Aug 10, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/preset-auto-origin-station-5rjpbd

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

概要

種別を持つ路線を選んだとき、プリセットの始発駅・終着駅が意図しない終端になる問題を修正します。

useLineSelection.handleLineSelected は、駅の指定種別(station.trainType)を pendingTrainType へ自動選択する一方、駅一覧 pendingStations は路線単独の lineStations のままでした。系統全体を取り直す処理はバス経路(fallbackTrainType)にしか掛かっていません。

その結果、同じプリセットが2つの異なる駅一覧で表現されます。

  • 保存時(handleLineSelected): hasTrainType: true と trainTypeId を保存する一方、direction や通知駅は路線単独の並びで解決する
  • 復元時(handlePresetPress → openModalByTrainTypeId): lineGroupStations で直通を含む系統全体を取得する

保存時の並びで決めた direction を、範囲も並びも異なる系統全体のリストへ当てるため、始発駅・終着駅がずれます。東京メトロ副都心線のように直通運転で系統が複数路線にまたがるほど差が大きくなります。

既存テストでも、バス経路には「最初の種別を自動選択し lineGroup の駅を取得する」ケースがある一方、鉄道で station.trainType が指定されているケースはテストも再取得もありませんでした。同じ目的の処理がバス側にだけ入っていることから、取得漏れと判断しています。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • lineGroupStations の再取得条件を fallbackTrainType(バスの自動選択のみ)から initialTrainType(指定種別とバスの自動選択の両方)へ拡張。種別を自動選択したら駅一覧も同じ系統へ揃え、handleTrainTypeSelect / openModalByTrainTypeId と同じ状態になるようにした
  • lineGroupStations が空で返った場合は路線単独の駅一覧を残すガードを追加(従来は空配列で潰していた)
  • 直通系統では同じ駅でも駅IDが変わりうるため、pendingStation の引き当てに groupId によるフォールバックを追加
  • handleLineSelected に選択世代(selectionGenerationRef)を導入し、Promise.all の直後と fetchStationsByLineGroupId の直後で世代を照合。路線を選び直した際に、前の選択の取得結果が新しい pendingStations / pendingStation を上書きしないようにした(前者は元からあった同種の穴も塞ぐ)
  • 鉄道路線で指定種別がある場合に系統全体の駅一覧へ差し替わり、groupId フォールバックで乗車駅を引き当てることを検証するテストを追加
  • lineGroupStations が空のときに路線単独の駅一覧を維持することを検証するテストを追加
  • 取得中に別の路線が選ばれた場合に古い系統駅一覧で上書きしないことを検証するテストを追加

影響範囲・リグレッションリスク

  • 種別を持つ鉄道路線を選択した際、方面選択モーダルに表示される駅一覧が路線単独から系統全体(直通を含む)へ変わる。これは種別を手動で選び直した場合(handleTrainTypeSelect)やプリセット復元時(openModalByTrainTypeId)と同じ状態であり、従来はこの経路だけが食い違っていた
  • 路線選択時に lineGroupStations の取得が1回増えるが、fetchStationsByLineGroupIdLoading は既に方面選択モーダルのローディング判定に含まれているためスケルトン表示となり、UXの退行はない
  • バス経路の挙動は変わらない(initialTrainType は fallbackTrainType を含むため)。空応答時に駅一覧を潰さなくなる点のみ改善される
  • 世代管理は handleLineSelected にのみ導入しており、handleTrainTypeSelect / openModalByTrainTypeId の挙動は変えていない

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

追加した3件のテストは、いずれも対応する修正を個別に戻すと落ちることを確認済みです。npm test は 215 suites / 2280 tests すべて成功。

なお、この環境には API の接続情報も実機も無いため、実際の副都心線データでの表示確認は行えていません。修正はロジックの整合性とユニットテストで担保しています。

関連Issue

スクリーンショット(任意)

Summary by CodeRabbit

  • 改善
    • 鉄道路線で列車種別が指定されている場合、対応する駅グループの駅一覧を表示できるようになりました。
    • 駅グループの情報がない場合は、従来の路線駅一覧を引き続き表示します。
    • 選択中の駅は、駅IDまたは駅グループIDを基に適切に引き継がれます。
    • 路線をすばやく切り替えた際、以前の路線情報が後から表示を上書きしないよう改善しました。

@TinyKitten TinyKitten self-assigned this Aug 10, 2026
@github-actions github-actions Bot added the react label Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

handleLineSelected が、列車種別の groupId に基づく駅一覧を鉄道路線にも適用します。系統駅一覧が空の場合は路線駅一覧を保持します。選択世代を検証し、古い非同期結果の適用を防止します。関連するテストを追加しました。

Changes

駅一覧選択

Layer / File(s) Summary
系統駅一覧の解決とフォールバック
src/hooks/useLineSelection.ts, src/hooks/useLineSelection.test.tsx
groupId を持つ自動選択種別から系統駅一覧を取得します。取得結果が空の場合は路線駅一覧を保持します。駅は駅ID、駅グループID、既存の保留駅の順に照合します。関連する鉄道路線のテストを追加します。
非同期選択結果の世代管理
src/hooks/useLineSelection.ts, src/hooks/useLineSelection.test.tsx
路線選択ごとに選択世代を更新します。取得後に世代を検証し、古い路線の結果を状態へ適用しません。非同期応答順序を検証するテストを追加します。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant handleLineSelected
  participant StationAPI
  participant StationState
  User->>handleLineSelected: 路線を選択
  handleLineSelected->>handleLineSelected: 選択世代を更新
  handleLineSelected->>StationAPI: 駅・列車種別を取得
  StationAPI-->>handleLineSelected: 取得結果を返却
  handleLineSelected->>StationAPI: groupIdで系統駅一覧を取得
  StationAPI-->>handleLineSelected: 系統駅一覧を返却
  handleLineSelected->>StationState: 最新世代の駅状態を設定
Loading

Possibly related PRs

Poem

うさぎが路線を選ぶ
系統の駅をたどる
空なら路線を残す
古い返事は止める
新しい駅だけぴょんと反映 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed 指定種別の自動選択時に駅一覧を系統全体へ揃える主要変更を明確に示しています。
Description check ✅ Passed 概要、変更内容、影響範囲、テスト結果、関連Issue、任意項目をテンプレートに沿って記載しています。
✨ 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 claude/preset-auto-origin-station-5rjpbd

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

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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/hooks/useLineSelection.test.tsx`:
- Around line 336-380: Update the test around handleLineSelected to exercise
groupId-based pending-station reconciliation: set the selected line station to
id 10 with groupId 100, include a group station with id 110 and groupId 100, and
assert pendingStation.id is 110. Keep the existing group fetch and pending
station assertions otherwise unchanged.

In `@src/hooks/useLineSelection.ts`:
- Around line 171-188: Update handleLineSelected to record the current selection
generation when each invocation begins, then after the
fetchStationsByLineGroupId await, update pendingStations and pendingStation only
if that generation still matches the current selection. Ensure stale requests
from earlier selections cannot overwrite the newer atom state.
🪄 Autofix

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: 69f626d5-4d48-4ed1-ac17-e6af79ef2dd4

📥 Commits

Reviewing files that changed from the base of the PR and between 0a2c9b8 and a1f3a6b.

📒 Files selected for processing (2)
  • src/hooks/useLineSelection.test.tsx
  • src/hooks/useLineSelection.ts

Comment thread src/hooks/useLineSelection.test.tsx Resolved
Comment thread src/hooks/useLineSelection.ts Resolved
@TinyKitten
TinyKitten merged commit 8ae8b97 into dev Aug 10, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/preset-auto-origin-station-5rjpbd branch August 10, 2026 09:58
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.

2 participants