Skip to content

経路検索改良 - #4721

Merged
TinyKitten merged 4 commits into
devfrom
fix/route-search
Dec 10, 2025
Merged

TinyKitten merged 4 commits into
devfrom
fix/route-search

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Dec 9, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

リリースノート

リファクタリング

  • 検索結果処理を簡素化し、重複除外をやめ生データを表示します。
  • 路線選択の取得フローを統合し、経路種別(viaライン)に基づく絞り込みを強化しました。

新機能 / 挙動変更

  • 乗車券対象外の駅のみを境界選択モーダルに表示するように変更。
  • 列車種別の自動リセットを廃止し、一度選んだ種別が保持されやすくなりました。

✏️ Tip: You can customize this high-level summary in your review settings.

@TinyKitten TinyKitten self-assigned this Dec 9, 2025
@github-actions github-actions Bot added the react label Dec 9, 2025
@coderabbitai

coderabbitai Bot commented Dec 9, 2025 •

Copy link
Copy Markdown
Contributor

Note

.coderabbit.yml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'auto_review'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

SelectBoundModal に getIsPass を使ったパス駅除外処理を追加し、stationsWithoutPass を RouteInfoModal に渡す。RouteSearchScreen は handleLineSelected を再構成して routeTypes/viaLineId を用いた取得フローと駅取得の分岐を統合し、検索結果の重複除去や自動フェッチを削除した。

Changes

Cohort / File(s) Summary
駅フィルタリングとモーダル入出力
src/components/SelectBoundModal.tsx
getIsPass を導入し memoized な stationsWithoutPass を計算、RouteInfoModal にフィルタ済みリストを渡す。モーダル閉鎖時の一部 state リセット(trainType クリア)を削除。
路線選択と取得フロー再編
src/screens/RouteSearchScreen.tsx
uniqBy 削除、検索結果の重複除去をやめる。findLocalType を利用し、handleLineSelected を統合して groupId/lineId 検証、getRouteTypes(viaLineId あり)→ trainTypes 処理→ 条件付きで stations を取得する新フローを実装。自動フェッチ effect を削除し依存配列を調整。モーダルの loading/error ソース参照を更新。
型定義拡張(TrainType)
src/@types/graphql.d.ts
QueryRouteTypesArgs / QueryRoutesArgs に viaLineId?: number を追加。多数のフラグメント/クエリ型に trainType: TrainTypeNested 形を追記し、TinyTrainTypeFieldsFragment を導入。
GraphQL クエリとフラグメント
src/lib/graphql/queries.ts
TINY_TRAIN_TYPE_FRAGMENT を追加。GetRouteTypes に $viaLineId: Int 変数を追加し routeTypes(viaLineId: $viaLineId) を受け取れるように変更。
キャッシュポリシー調整
src/lib/gql.ts
Apollo InMemoryCache の typePolicies に TrainType: { keyFields: false } を追加。
トレイン型一覧表示調整
src/components/TrainTypeListModal.tsx
FlatList の data を useMemo で導出した trainTypes に切替(各 trainType に nested trainType をマージ)、keyExtractor を tt.id のみに変更。
選択画面の UI 状態リセット整理
src/screens/SelectLineScreen.tsx
handleLineSelected / openModalByLineId で方向や目的地関連の UI state を明示的に null にする一方、バルク閉鎖ハンドラでの pending 系リセットを削除(空関数化)。

Sequence Diagram

sequenceDiagram
    participant User as ユーザー
    participant RouteSearch as RouteSearchScreen
    participant RouteAPI as RouteTypes API
    participant StationAPI as Stations API
    participant SelectBound as SelectBoundModal
    Note over RouteSearch,RouteAPI: ユーザーが路線を選択したときの処理フロー

    User->>RouteSearch: 路線選択
    activate RouteSearch
    RouteSearch->>RouteSearch: handleLineSelected 実行 (groupId, lineId 検証)
    alt groupId/lineId が存在
        RouteSearch->>RouteAPI: getRouteTypes(viaLineId?)
        activate RouteAPI
        RouteAPI-->>RouteSearch: routeTypes
        deactivate RouteAPI
        alt routeTypes に trainTypes がある
            RouteSearch->>StationAPI: getStationsByLineGroup / getStationsByGroupId
        else trainTypes が空
            RouteSearch->>StationAPI: getStationsByLineId (fallback)
        end
    else groupId/lineId 不在
        RouteSearch->>StationAPI: getStationsByLineId
    end
    activate StationAPI
    StationAPI-->>RouteSearch: stations
    deactivate StationAPI
    RouteSearch->>RouteSearch: dropEitherJunctionStation を適用
    RouteSearch->>RouteSearch: stationsWithoutPass を計算 (getIsPass)
    RouteSearch->>SelectBound: stationsWithoutPass を渡してモーダルを開く
    deactivate RouteSearch

    activate SelectBound
    User->>SelectBound: 駅選択
    SelectBound-->>RouteSearch: 選択結果
    deactivate SelectBound
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • RouteSearchScreen の handleLineSelected(groupId/lineId 検証、routeTypes→条件付き stations フェッチ)のロジック検証
  • GraphQL 型拡張(trainType の階層追加)と queries における viaLineId の伝播確認
  • キャッシュポリシー変更がキャッシュヒット/整合性に与える影響の確認
  • SelectBoundModal の stationsWithoutPass 計算と既存の表示ロジック整合性
  • TrainTypeListModal のデータマッピング(nested trainType マージ)と key の一貫性

Possibly related PRs

Poem

🐰 フェッチして、選んで、また走る
パスは跳ねて、リストは軽やか
ルート呼んで、駅を集めて
モーダル開けば、選択はすぐそこ
新しい流れ、ぴょんと一跳び! 🚉✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトル「経路検索改良」は、変更内容の主要な目的である経路検索機能の改善を的確に反映しており、簡潔で明確です。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/route-search

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

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

🧹 Nitpick comments (4)
src/components/TrainTypeListModal.tsx (1)

180-195: trainTypes の派生と keyExtractor は妥当ですが、わずかな簡略化余地があります

  • fetchedTrainTypes から現在の line.id に対応する nestedTrainType をマージして表示用フィールドを上書きする方針は、line / lines を元の値のまま維持できていて良いと思います。
  • id を元の tt.id で強制上書きしているので、TrainTypeNested 側の ID に引きずられないのも安心です。
  • .filter((tt) => tt) は map 内で null などを返していない現状では常に真になるため、将来 null を返す予定がなければ削ってしまっても読みやすくなりそうです。
-    const trainTypes = fetchedTrainTypes
-      .map((tt) => {
+    const trainTypes = fetchedTrainTypes
+      .map((tt) => {
         const nestedTrainType = tt.lines?.find((l) => l.id === line?.id)
           ?.trainType as TrainType | undefined;
         return { ...tt, ...nestedTrainType, id: tt.id };
-      })
-      .filter((tt) => tt) as TrainType[];
-
-    return trainTypes;
+      }) as TrainType[];
+
+    return trainTypes;
  • keyExtractor を tt.id ?? index にしたのも実用上は十分だと思いますが、ID が null なケースがほぼ無い前提であれば、あとからバグ調査しやすいように「ID が無いことが分かるキー」(例: fallback-${index})のままにしておくのも手です(任意)。

Also applies to: 231-235

src/screens/SelectLineScreen.tsx (1)

622-624: handleCloseSelectBoundModal が状態を一切リセットしなくなった点の意図確認

handleCloseSelectBoundModal がモーダルの表示状態だけを変更し、pendingStation / pendingStations / pendingLine などはそのまま残す形になっています。

  • 「閉じても状態は保持したい」(再オープン時にそのまま続きを見せたい)意図であればこの実装で問題ありません。
  • もし「キャンセルしたら一旦すべてクリアしたい」想定なら、従来どおりここでリセットするか、もしくは「キャンセル専用のリセットハンドラ」を別途用意するのが良さそうです。

どちらの UX を狙っているか、改めて方針だけ決めておくと後から迷わないと思います。

src/screens/RouteSearchScreen.tsx (2)

155-177: 検索件数上限の扱いはシンプルになっていますが、ENV 値のバリデーション余地があります

SEARCH_STATION_RESULT_LIMIT をそのまま Number.parseInt して limit に渡す実装は分かりやすいです。

一方で、ENV 文字列が不正(空文字や数値でない)だった場合に NaN がそのまま API に渡る可能性があるので、簡単なフォールバックを入れておくと堅牢になります。

-      const limit = Number.parseInt(SEARCH_STATION_RESULT_LIMIT, 10);
+      const parsed = Number.parseInt(SEARCH_STATION_RESULT_LIMIT, 10);
+      const limit = Number.isNaN(parsed) ? 50 : parsed; // 例: デフォルト 50

ここは運用上 ENV が常に正しい前提ならそのままでも構いませんが、一度想定値を確認しておくと安心です。


187-276: handleLineSelected の新しい経路種別フローは良いですが、いくつかエッジケース確認を推奨します

全体として、

  • 出発駅の groupId / 到着候補駅の groupId / 経由路線 ID から routeTypes を取得
  • routeTypes.trainTypes からローカル種別 (findLocalType) を優先選択
  • ローカル種別の groupId で lineGroupStations を取得して pendingStations に反映
  • fetchedTrainTypes と trainType を一括で navigationState に保存

というフローは一貫しており、viaLineId を含めた API の意図とも合っていて良い実装だと思います。

気になった点は次の 3 点です(どれも致命的ではなく、仕様確認レベルです):

  1. ガード条件とモーダル表示順序

    • setSelectBoundModalVisible(true) をガードより先に呼んでいるため、groupId や line.id が欠けているケースでは、データなしの状態でモーダルだけ開いたまま return することになります。
    • そのようなケースが実際には「起こらない前提」なら問題ありませんが、念のため「起こったときにどう見せたいか」(例: そもそもモーダルを開かない・エラートーストを出す)を決めておくとよさそうです。
  2. fetchedTrainTypes が空 or groupId がすべて null の場合

    • !fetchedTrainTypes.length の場合は station.line?.id を使って GET_LINE_STATIONS にフォールバックしていますが、
    • fetchedTrainTypes が空ではないが、findLocalType(...) ?? fetchedTrainTypes[0] の結果に groupId が付いていないケース(理論的にはあり得る)では、if (!localTrainType?.groupId) { return; } で何もせず終了し、pendingStations が空のままになる可能性があります。
    • サーバー側の仕様として「ここで返る TrainType には必ず groupId が付いている」前提であれば OK ですが、そうでない場合は「no-train-type フォールバック」と同じ振る舞いに寄せるのも選択肢です。
  3. フォールバック時の lineId の選択

    • !fetchedTrainTypes.length のフォールバックで station.line?.id を使用していますが、文脈的には selectedStation.line.id を使う方が直感的かもしれません。
    • 実際には station.line が常に「現在経路検索している路線」を指しているなら現状でも問題ありませんが、その前提に依存しているので、一度確認しておくと安心です。

いずれも仕様次第なので、「こういうケースは起こり得ない」という前提が固まっているなら現状のままでも大丈夫だと思いますが、その前提をコメントなどで軽く共有しておくと後から読みやすくなりそうです。

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a9f836 and 2ca7122.

📒 Files selected for processing (7)
  • src/@types/graphql.d.ts (67 hunks)
  • src/components/SelectBoundModal.tsx (4 hunks)
  • src/components/TrainTypeListModal.tsx (3 hunks)
  • src/lib/gql.ts (1 hunks)
  • src/lib/graphql/queries.ts (6 hunks)
  • src/screens/RouteSearchScreen.tsx (7 hunks)
  • src/screens/SelectLineScreen.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/SelectBoundModal.tsx
🧰 Additional context used
📓 Path-based instructions (4)
src/{components,screens}/**/*.tsx

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Component files should use PascalCase naming (e.g., StationBanner.tsx)

Use PascalCase for component file names (e.g., StationBanner.tsx)

Files:

  • src/components/TrainTypeListModal.tsx
  • src/screens/RouteSearchScreen.tsx
  • src/screens/SelectLineScreen.tsx
**/*.{ts,tsx,js,jsx,json}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use Biome as the formatter for all code files

Files:

  • src/components/TrainTypeListModal.tsx
  • src/screens/RouteSearchScreen.tsx
  • src/lib/gql.ts
  • src/screens/SelectLineScreen.tsx
  • src/@types/graphql.d.ts
  • src/lib/graphql/queries.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx,js,jsx}: Use Biome as the linter for all code files
Use // biome-ignore only for true compatibility issues and include an inline reason

Use .editorconfig standards: UTF-8 encoding, two-space indentation, single quotes, and ES5 trailing commas

Files:

  • src/components/TrainTypeListModal.tsx
  • src/screens/RouteSearchScreen.tsx
  • src/lib/gql.ts
  • src/screens/SelectLineScreen.tsx
  • src/@types/graphql.d.ts
  • src/lib/graphql/queries.ts
src/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Biome is authoritative for linting; avoid // biome-ignore unless a rule is truly incompatible and document the rationale inline

Files:

  • src/components/TrainTypeListModal.tsx
  • src/screens/RouteSearchScreen.tsx
  • src/lib/gql.ts
  • src/screens/SelectLineScreen.tsx
  • src/@types/graphql.d.ts
  • src/lib/graphql/queries.ts
🧠 Learnings (4)
📓 Common learnings
Learnt from: TinyKitten
Repo: TrainLCD/MobileApp PR: 0
File: :0-0
Timestamp: 2025-08-11T21:13:39.083Z
Learning: TinyKitten prefers concise code reviews for the TrainLCD/MobileApp repository. Keep review comments brief and to the point.
📚 Learning: 2025-07-18T11:04:45.459Z
Learnt from: TinyKitten
Repo: TrainLCD/MobileApp PR: 4396
File: src/components/TrainTypeBoxJRKyushu.tsx:176-183
Timestamp: 2025-07-18T11:04:45.459Z
Learning: TrainTypeBoxJRKyushuコンポーネントでは、trainTypeNameとprevTrainTypeNameは常に文字列となるため、.split()メソッドを使用する際のnull安全性チェックは不要である。これらの変数はuseMemoとuseLazyPreviousを通じて管理され、translate()関数からのフォールバック値により常に文字列が保証される。

Applied to files:

  • src/components/TrainTypeListModal.tsx
  • src/screens/RouteSearchScreen.tsx
  • src/@types/graphql.d.ts
📚 Learning: 2025-05-19T10:59:37.813Z
Learnt from: TinyKitten
Repo: TrainLCD/MobileApp PR: 4286
File: src/components/HeaderLED.tsx:5-10
Timestamp: 2025-05-19T10:59:37.813Z
Learning: The hooks useCurrentStation, useNextStation, useIsNextLastStop, and useNumbering are properly exported in src/hooks/index.ts, allowing them to be imported from '../hooks' in src/components/HeaderLED.tsx as implemented in PR #4286.

Applied to files:

  • src/components/TrainTypeListModal.tsx
  • src/screens/RouteSearchScreen.tsx
  • src/screens/SelectLineScreen.tsx
📚 Learning: 2025-06-18T17:29:46.085Z
Learnt from: TinyKitten
Repo: TrainLCD/MobileApp PR: 4359
File: src/components/TrainTypeList.tsx:1-1
Timestamp: 2025-06-18T17:29:46.085Z
Learning: When analyzing React import changes in TypeScript/JavaScript files, carefully verify that React.Fragment, React.createElement, or other React namespace usages actually exist in the code before flagging them as issues. Don't assume React.Fragment is used just because the default React import was removed.

Applied to files:

  • src/components/TrainTypeListModal.tsx
🧬 Code graph analysis (2)
src/components/TrainTypeListModal.tsx (1)
src/@types/graphql.d.ts (1)
  • TrainType (292-307)
src/screens/RouteSearchScreen.tsx (2)
src/@types/react-native-dotenv.d.ts (1)
  • SEARCH_STATION_RESULT_LIMIT (5-5)
src/utils/trainTypeString.ts (1)
  • findLocalType (11-13)
🔇 Additional comments (8)
src/lib/gql.ts (1)

40-45: TrainType の typePolicy 追加は整合的ですが、既存コードへの影響確認だけお願いします

TrainType を keyFields: false にしたことで、TrainTypeNested などと同様に正規化されないオブジェクト扱いになり、一貫性が出ていて良さそうです。

一方で、「TrainType を ID ベースで正規化キャッシュしている前提」のコード(cache.readFragment など)がないかだけ一度確認しておくと安心です。

src/lib/graphql/queries.ts (1)

111-157: TrainType 用の小さいフラグメント追加と viaLineId 導入は妥当そうです

  • TinyTrainTypeFields on TrainTypeNested を切り出して LineNested.trainType に差し込む構成は、既存の TrainType( Nested ) フラグメントと衝突せず、再利用性も高くて良いと思います。
  • GET_ROUTE_TYPES の viaLineId 変数追加と引数伝播も型定義(GetRouteTypesVariables.viaLineId?: number)と揃っていて問題なさそうです。

念のため、API 側スキーマで LineNested.trainType フィールドと routeTypes(viaLineId: Int) 引数 が期待どおり定義されているかだけ確認しておくと安心です。

Also applies to: 312-325, 360-425

src/components/TrainTypeListModal.tsx (1)

142-151: 経由路線サブタイトルの組み立てロジックは問題なさそうです

viaLines を Set でユニーク化してから join する実装は従来どおりで、改行のみの変更に見えるのでこの部分はそのままで良さそうです。

src/screens/SelectLineScreen.tsx (1)

387-420: 経路関連状態を「開くタイミングでリセットする」方向への変更は筋が良いです

handleLineSelected / openModalByLineId で以下をまとめてリセットしているのは、前回の選択が残ってしまう問題を避けられるので良いと思います。

  • selectedDirection, wantedDestination, selectedBound
  • pendingWantedDestination
  • fetchedTrainTypes, trainType

この結果、モーダルを開くたびにクリーンな状態から経路検索が始められる構造になっていて分かりやすいです。

一方で、「別の画面やロジックが pendingWantedDestination / selectedDirection などの 継続性 に依存していないか」は念のため一度洗い直しておくと安心です(特に SelectBoundModal / RouteSearchScreen 周り)。

Also applies to: 471-518

src/screens/RouteSearchScreen.tsx (2)

28-48: viaLineId の変数定義はクエリと整合していて問題なさそうです

GetRouteTypesVariables に viaLineId?: number を追加し、GET_ROUTE_TYPES 側でも同名のオプショナル引数として渡しているので、型・クエリともに揃っていて良いと思います。

API 側で viaLineId が本当にオプショナル(nullable)として定義されているかだけ、念のため確認しておいてください。


441-476: SelectBoundModal / TrainTypeListModal の loading / error 連携更新は妥当です

  • SelectBoundModal.loading / error に fetchRouteTypesLoading / fetchRouteTypesError を加えたことで、経路種別取得中の状態やエラーが正しく反映されるようになっていて良いと思います。
  • TrainTypeListModal.loading にも fetchRouteTypesLoading を含めているので、経路種別経由でのライン・駅取得フロー全体でスピナー状態が一貫して扱えています。

この部分は特に懸念ありません。

src/@types/graphql.d.ts (2)

153-167: Query に viaLineId を追加している点について

QueryRouteTypesArgs / QueryRoutesArgs に viaLineId: InputMaybe<Scalars['Int']['input']> が追加されており、既存引数には手を入れていないので後方互換性的にも問題なさそうです。サーバー側スキーマと整合している前提で特に懸念はありません。


493-6884: TrainTypeNested 関連フィールドの拡張について

TinyTrainTypeFieldsFragment の追加とそれに対応する多数の trainType: TrainTypeNested フィールド拡張はいずれも同じフィールド構造(id/typeId/groupId/各種 name/color/direction/kind)で統一されており、既存の TrainTypeNested 型とも矛盾していないように見えます。各フラグメント/クエリ結果から列車種別情報へ直接アクセスできるようにする意図とも合致しており、このファイルが codegen 由来であればこのままで問題ないと思います。

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