Repository navigation
経路検索改良 - #4721
経路検索改良#4721
Conversation
|
Note
|
| 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
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
- 縦画面対応に関わるバグの修正とGraphQL BFF移行 #4521 — SelectBoundModal の props/状態ハンドリング変更と重複するファイル・ロジックを含むため強い関連あり
- プリセット機能のバグを修正と仕様変更 #4529 — SelectLine / modal の state リセット周りでオーバーラップする変更があるため関連あり
- 路線選択画面に戻る時に毎回位置情報を更新しないようにした #4108 — SelectBound 系の state リセット削除に関する他の変更と直接的に関連あり
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.
There was a problem hiding this comment.
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 点です(どれも致命的ではなく、仕様確認レベルです):
ガード条件とモーダル表示順序
setSelectBoundModalVisible(true)をガードより先に呼んでいるため、groupIdやline.idが欠けているケースでは、データなしの状態でモーダルだけ開いたままreturnすることになります。- そのようなケースが実際には「起こらない前提」なら問題ありませんが、念のため「起こったときにどう見せたいか」(例: そもそもモーダルを開かない・エラートーストを出す)を決めておくとよさそうです。
fetchedTrainTypesが空 orgroupIdがすべて 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 フォールバック」と同じ振る舞いに寄せるのも選択肢です。
フォールバック時の lineId の選択
!fetchedTrainTypes.lengthのフォールバックでstation.line?.idを使用していますが、文脈的にはselectedStation.line.idを使う方が直感的かもしれません。- 実際には
station.lineが常に「現在経路検索している路線」を指しているなら現状でも問題ありませんが、その前提に依存しているので、一度確認しておくと安心です。いずれも仕様次第なので、「こういうケースは起こり得ない」という前提が固まっているなら現状のままでも大丈夫だと思いますが、その前提をコメントなどで軽く共有しておくと後から読みやすくなりそうです。
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 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.tsxsrc/screens/RouteSearchScreen.tsxsrc/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.tsxsrc/screens/RouteSearchScreen.tsxsrc/lib/gql.tssrc/screens/SelectLineScreen.tsxsrc/@types/graphql.d.tssrc/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-ignoreonly for true compatibility issues and include an inline reasonUse
.editorconfigstandards: UTF-8 encoding, two-space indentation, single quotes, and ES5 trailing commas
Files:
src/components/TrainTypeListModal.tsxsrc/screens/RouteSearchScreen.tsxsrc/lib/gql.tssrc/screens/SelectLineScreen.tsxsrc/@types/graphql.d.tssrc/lib/graphql/queries.ts
src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Biome is authoritative for linting; avoid
// biome-ignoreunless a rule is truly incompatible and document the rationale inline
Files:
src/components/TrainTypeListModal.tsxsrc/screens/RouteSearchScreen.tsxsrc/lib/gql.tssrc/screens/SelectLineScreen.tsxsrc/@types/graphql.d.tssrc/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.tsxsrc/screens/RouteSearchScreen.tsxsrc/@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.tsxsrc/screens/RouteSearchScreen.tsxsrc/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,selectedBoundpendingWantedDestinationfetchedTrainTypes,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 由来であればこのままで問題ないと思います。
Summary by CodeRabbit
リリースノート
リファクタリング
新機能 / 挙動変更
✏️ Tip: You can customize this high-level summary in your review settings.