Skip to content

経路検索で複数種別のConnectedRoutesを利用 - #6530

Draft
TinyKitten wants to merge 9 commits into
devfrom
feature/use-connected-routes
Draft

経路検索で複数種別のConnectedRoutesを利用#6530
TinyKitten wants to merge 9 commits into
devfrom
feature/use-connected-routes

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Aug 4, 2026

Copy link
Copy Markdown
Member

概要

単一の列車種別だけでは到達できない経路を、ConnectedRoutesで検索できるようにします。

変更の種類

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

変更内容

  • routeTypes で単一種別の経路が見つからない場合のみ connectedRoutes を問い合わせます。
  • ConnectedRoutesの各経路を既存の列車種別選択UIで扱える候補へ変換します。
  • StationAPIが付与する仮想 lineGroupId と駅列を保持し、初期候補と候補切替時に使用します。
  • ConnectedRoutesも空の場合は、従来の選択路線フォールバックを維持します。
  • 単一種別で到達できる既存経路には追加のAPI呼び出しは発生しません。
  • routeTypes または connectedRoutes の取得失敗時は、経路なしとして次のフォールバックへ進まずエラー状態を維持します。
  • GraphQL操作名を GetConnectedRoutesQuery へ変更しました。
  • 回帰リスクは複数種別経路の状態構築です。仮想 lineGroupId、区間路線、区間種別の変換テストに加え、取得条件・状態更新・候補切替・取得失敗を検証するフック統合テストを追加して軽減します。

テスト

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

Node.js 22.23.2 / npm 10.9.9で以下を確認しました。

  • npm run lint: 605ファイルすべて通過
  • npm test -- --runInBand: 202スイート、2,177テストすべて通過
  • npm run typecheck: 通過
  • npm test -- --runInBand src/hooks/useDestinationSelection.test.tsx: ConnectedRoutes選択フローの6テストすべて通過

関連Issue

なし

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

UI変更なし

Summary by CodeRabbit

  • 新機能

    • 複数の列車種別をまたぐ接続経路を取得し、1つの選択肢として表示できるようになりました。
    • 接続経路に含まれる駅や路線情報を、列車種別の選択・表示に反映します。
    • 接続経路の読み込み中やエラー発生時も、適切に状態を表示します。
  • 品質改善

    • 経路情報や列車種別が不足している場合、不完全な選択肢を表示しないよう改善しました。

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

接続経路を取得するGraphQLクエリとデータ型を追加しました。経路の駅情報から列車種別を構築します。通常の列車種別がない場合は接続経路を使用し、駅情報を再利用して行き先選択状態を更新します。

Changes

接続経路選択フロー

Layer / File(s) Summary
接続経路のGraphQL契約
src/lib/graphql/queries.ts, src/hooks/useDestinationSelection.ts
接続経路の駅情報フラグメントと取得クエリを追加しました。レスポンス型とクエリ変数型を定義しました。
接続経路の列車種別構築
src/utils/routeSearch.ts, src/utils/routeSearch.test.ts
接続経路の駅から路線と列車種別を収集し、TrainTypeを生成します。経路IDまたは列車種別情報がない場合はnullを返します。テストを追加しました。
行き先選択への統合
src/hooks/useDestinationSelection.ts
列車種別がない場合に接続経路を遅延取得します。取得した駅情報を保持し、列車種別選択時に再利用します。取得中と取得エラーをモーダル状態へ反映します。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant 行き先選択
  participant GET_CONNECTED_ROUTES
  participant buildConnectedRouteTrainType
  行き先選択->>GET_CONNECTED_ROUTES: 出発駅グループIDと到着駅グループIDを送信
  GET_CONNECTED_ROUTES-->>行き先選択: 接続経路と停車駅一覧を返却
  行き先選択->>buildConnectedRouteTrainType: 接続経路を渡す
  buildConnectedRouteTrainType-->>行き先選択: TrainTypeを返却
  行き先選択->>行き先選択: 駅情報とモーダル状態を更新
Loading

Possibly related PRs

  • TrainLCD/MobileApp#6509: useDestinationSelection.tsと接続経路関連のGraphQL処理を変更しています。

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 タイトルは、複数の列車種別を含むConnectedRoutesを経路検索で利用する主な変更を簡潔に示しています。
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 feature/use-connected-routes

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

🧹 Nitpick comments (1)
src/lib/graphql/queries.ts (1)

482-485: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

GraphQL 操作名を命名規約に合わせてください。

GetConnectedRoutesFeatureVerbQuery 形式ではありません。GetConnectedRoutesQuery のように Query 接尾辞を追加してください。

🤖 Prompt for 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.

In `@src/lib/graphql/queries.ts` around lines 482 - 485, Update the GraphQL
operation name in GetConnectedRoutes to follow the FeatureVerbQuery convention
by adding the Query suffix, while preserving its variables and query body.

Source: Coding guidelines

🤖 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/useDestinationSelection.ts`:
- Around line 196-255: Add integration tests for useDestinationSelection that
mock useLazyGraphQLQuery and call jest.clearAllMocks() after every test. Cover
that an existing single train type skips GET_CONNECTED_ROUTES, an empty
single-type result stores ConnectedRoutes stops and the virtual lineGroupId,
empty ConnectedRoutes preserves the existing line fallback, and switching to a
virtual candidate reuses cached stations without calling
GET_LINE_GROUP_STATIONS.
- Around line 196-204: Update the route-selection flow around fetchRouteTypes
and fetchConnectedRoutes to inspect each query result’s error before treating
its data as empty. Only invoke fetchConnectedRoutes when fetchRouteTypes
succeeded with no train types, and only apply the existing route fallback when
fetchConnectedRoutes succeeded with an empty response; propagate or handle
either fetch error instead of interpreting it as “no routes.”

---

Nitpick comments:
In `@src/lib/graphql/queries.ts`:
- Around line 482-485: Update the GraphQL operation name in GetConnectedRoutes
to follow the FeatureVerbQuery convention by adding the Query suffix, while
preserving its variables and query body.
🪄 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: 08b69967-f408-48b8-a3e0-ef152ba3162b

📥 Commits

Reviewing files that changed from the base of the PR and between d7dedea and 22f897c.

📒 Files selected for processing (4)
  • src/hooks/useDestinationSelection.ts
  • src/lib/graphql/queries.ts
  • src/utils/routeSearch.test.ts
  • src/utils/routeSearch.ts

Comment thread src/hooks/useDestinationSelection.ts
Comment thread src/hooks/useDestinationSelection.ts
@TinyKitten
TinyKitten marked this pull request as draft August 5, 2026 05:35
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