Skip to content

経路検索の種別一覧を種別ごとの起点路線デザインで表示しヘッダーを行先路線名に変更 - #6251

Merged
TinyKitten merged 2 commits into
devfrom
fix/train-type-card-origin-line
Jun 17, 2026
Merged

TinyKitten merged 2 commits into
devfrom
fix/train-type-card-origin-line

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

概要

経路検索の列車種別一覧モーダルで、各種別が通る路線に関係なく単一路線のデザイン(背景色・路線記号)で CommonCard が表示されていた不具合を修正しました。あわせて表示ロジックを切り出して整理し、ユニットテストを追加しています。

変更の種類

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

変更内容

  • 各列車種別の起点路線(始発側で乗車する路線)を item.lines から特定し、CommonCard をその路線の配色・路線記号で描画するように修正(例: 池袋→元町・中華街でみなとみらい線を選んだ際、東武東上線経由の種別に西武池袋線のデザインが当たる問題を解消)。
  • 起点路線は「行先路線(destination.line)の反対側の端」を始発側として判定。経由路線(サブタイトル)の算出も起点路線基準に統一。
  • この一覧では駅番号は出さず、路線シンボル(静的画像)固定表示に統一(番号が出たり静的画像になったりする不整合を解消)。
  • ヘッダーの路線名を、行先がある経路検索では行先路線名を表示するように変更。
  • API 側にフィルタ処理が追加され不要になったクライアント側フィルタ撤去まわりのコメント・混入文字を整理。
  • 表示ロジック(getOriginLine / getViaLines / formatLineNames)を src/utils/trainTypeList.ts に抽出。実体を import して検証するユニットテスト(16 ケース)を src/utils/trainTypeList.test.ts に追加し、コンポーネント内ロジックのコピーを検証していた陳腐化済みの TrainTypeListModal.test.tsx を削除。

テスト

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

関連Issue

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

Summary by CodeRabbit

  • Refactor
    • 路線名の整形や起点・経由路線の算出など、路線表示ロジックを整理し、表示の一貫性を高めました。
    • 運行種別一覧の絞り込み挙動を見直し、表示内容が更新されました。
  • Tests
    • 起点・経由路線の算出、および路線名の整形について、包括的なユニットテストを追加しました。

@TinyKitten TinyKitten self-assigned this Jun 17, 2026
@github-actions github-actions Bot added the react label Jun 17, 2026
@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4650091e-907a-41a7-87a4-2fb580a9980e

📥 Commits

Reviewing files that changed from the base of the PR and between 67d8a3a and c555631.

📒 Files selected for processing (2)
  • src/utils/trainTypeList.test.ts
  • src/utils/trainTypeList.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/utils/trainTypeList.test.ts
  • src/utils/trainTypeList.ts

📝 Walkthrough

Walkthrough

TrainTypeListModal に埋め込まれていた起点路線・経由路線の計算ロジックと路線名整形ロジックを src/utils/trainTypeList.ts へ抽出し、3つの新関数(getOriginLine・getViaLines・formatLineNames)として公開した。モーダル側はローカル実装を削除して新関数を利用する形に置き換え、CommonCard への targetStation 廃止・destination フィルタリング分岐の削除も行われた。旧コンポーネントテストは削除され、新ユーティリティ向けの独立したテストファイルが追加された。

Changes

TrainTypeList ユーティリティ抽出とモーダル更新

Layer / File(s) Summary
新規ユーティリティ関数の実装とテスト
src/utils/trainTypeList.ts, src/utils/trainTypeList.test.ts
getOriginLine・getViaLines・formatLineNames を新規追加。getOriginLine は目的地位置から始発側端の路線を返し、getViaLines は区間を切り出して経由路線を返す。formatLineNames は日英・会社グループ化に対応した路線名文字列を生成する。テストでは池袋〜みなとみらい線の想定モデルを使い、各分岐・順序・エッジケースを網羅する。
TrainTypeListModal のユーティリティ利用への置き換え
src/components/TrainTypeListModal.tsx, src/components/TrainTypeListModal.test.tsx
~/utils/trainTypeList をインポートしローカルヘルパー実装を削除。renderItem 内で getOriginLine・getViaLines を呼び出し、CommonCard には targetStation の代わりに originLine を line として渡す形に変更。trainTypes の useMemo から destination フィルタリング分岐を削除し、ヘッダー路線名は destination?.line を優先する実装に更新。旧コンポーネントテスト(343行)は削除。

Sequence Diagram

sequenceDiagram
  participant Modal as TrainTypeListModal
  participant getOriginLine
  participant getViaLines
  participant formatLineNames
  participant Card as CommonCard (per item)
  Modal->>Modal: trainTypes 計算(destination フィルタ分岐削除)
  Modal->>Modal: renderItem 呼び出し
  renderItem->>getOriginLine: lines, selectedLine, destination
  getOriginLine-->>renderItem: originLine
  renderItem->>getViaLines: lines, selectedLine, destination
  getViaLines-->>renderItem: viaLines[]
  renderItem->>formatLineNames: viaLines, ja
  formatLineNames-->>renderItem: via 路線名文字列
  renderItem->>Card: line=originLine, via 路線名
  Note over Card: targetStation 廃止、line で路線シンボル固定
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 ぴょんぴょん跳ねて、路線を整理
ユーティリティへ、ロジックを移送
起点・経由・名前もスッキリ
テストも新しく生まれ変わり
モーダルは軽く、うさぎも笑顔 🌸

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR タイトルは「経路検索の種別一覧を種別ごとの起点路線デザインで表示しヘッダーを行先路線名に変更」で、起点路線デザイン対応とヘッダー変更という主要な変更内容を正確に反映している。
Description check ✅ Passed PR 説明は概要・変更種類・変更内容・テスト結果など必須セクションが完備されており、起点路線検出・UI 改善・コード抽出・テスト追加の詳細が適切に記述されている。
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.

✏️ 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 fix/train-type-card-origin-line

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

@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai ちょっとレビュー遅くないですか?

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@TinyKitten ご不便をおかけして申し訳ありません!レビューに時間がかかってしまいましたね。もし今後もレビューの遅延が気になる場合は、CodeRabbit のサポートにお知らせいただければ確認いたします。引き続きよろしくお願いします 🙏

(´;ω;`)🐰

@TinyKitten

Copy link
Copy Markdown
Member Author

@CodeRabbit resume

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

@TinyKitten

Copy link
Copy Markdown
Member Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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/components/TrainTypeListModal.tsx (1)

112-169: 🏗️ Heavy lift

モーダル結線の統合テストを1件追加しておくと安全です

ここは表示仕様の結線(originLine 計算→CommonCard 反映、via subtitle 生成)が変更された箇所なので、TrainTypeListModal 側で 1 ケースでも統合寄りに担保しておくと退行を防ぎやすいです(例: destination あり時に CommonCard へ起点路線デザインが渡ること)。

As per coding guidelines, **/*.{test,spec}.{ts,tsx,js,jsx,py,java,go,cs} の「Test agents in isolation and with integration tests to ensure correctness and compatibility」と、src/**/*.test.{ts,tsx} の「When modifying behavior, update or add tests in the same change set.」に基づく提案です。

🤖 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/components/TrainTypeListModal.tsx` around lines 112 - 169, Add an
integration test for the TrainTypeListModal component to ensure the modified
display logic for train type lines is working correctly. The test should verify
that when a destination is provided, the originLine is calculated properly and
the correct line design is passed to the CommonCard component. This test will
help prevent regressions in the renderItem callback's originLine calculation and
subtitle generation logic, particularly when handling multiple grouped via
lines.

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/utils/trainTypeList.test.ts`:
- Around line 1-3: The test file is missing the required `afterEach` hook that
clears all mocks after each test. Following the coding convention for test files
in src/**/*.test.{ts,tsx}, add an `afterEach(() => jest.clearAllMocks())`
statement to ensure all mocks are properly cleared between test cases. This
should be added after the import statements at the top level of the test file.

In `@src/utils/trainTypeList.ts`:
- Around line 100-105: The code in the condition where `group.length > 1`
assigns `companyName` from either `nameShort` or `nameEnglishShort` but does not
validate that these values are defined, potentially resulting in strings like
"undefined線" or "undefined Line". After assigning `companyName`, add a check to
determine if `companyName` is falsy. If it is falsy, return a fallback value by
concatenating the line names from items within the group instead of using the
undefined company name. Only use the current template literal approach when
`companyName` has a valid truthy value.

---

Nitpick comments:
In `@src/components/TrainTypeListModal.tsx`:
- Around line 112-169: Add an integration test for the TrainTypeListModal
component to ensure the modified display logic for train type lines is working
correctly. The test should verify that when a destination is provided, the
originLine is calculated properly and the correct line design is passed to the
CommonCard component. This test will help prevent regressions in the renderItem
callback's originLine calculation and subtitle generation logic, particularly
when handling multiple grouped via lines.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 624ea123-76ca-4d8f-8459-18b4a6bc6710

📥 Commits

Reviewing files that changed from the base of the PR and between e3d13f8 and 67d8a3a.

📒 Files selected for processing (4)
  • src/components/TrainTypeListModal.test.tsx
  • src/components/TrainTypeListModal.tsx
  • src/utils/trainTypeList.test.ts
  • src/utils/trainTypeList.ts
💤 Files with no reviewable changes (1)
  • src/components/TrainTypeListModal.test.tsx

Comment thread src/utils/trainTypeList.test.ts Resolved
Comment thread src/utils/trainTypeList.ts Resolved
@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 2 file(s) based on 2 unresolved review comments.

Files modified:

  • src/utils/trainTypeList.test.ts
  • src/utils/trainTypeList.ts

Commit: c555631cc0950bbed52d35e79ff9888273f314da

The changes have been pushed to the fix/train-type-card-origin-line branch.

Time taken: 3m 17s

Fixed 2 file(s) based on 2 unresolved review comments.

Co-authored-by: CodeRabbit <[email protected]>
@TinyKitten
TinyKitten merged commit 2ccdf2b into dev Jun 17, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the fix/train-type-card-origin-line branch June 17, 2026 11:41
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