Skip to content

種別変更画面で経路外の路線が表示されるバグを修正 - #5715

Merged
TinyKitten merged 11 commits into
devfrom
feature/fix-display-current-line-selection
Mar 29, 2026
Merged

TinyKitten merged 11 commits into
devfrom
feature/fix-display-current-line-selection

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • 種別変更画面(TypeChangeNotify)の左バーに経路外の路線が表示されるバグを修正
  • TrainTypeBoxの「〜線内」表示を nextTrainType から直接取得するように修正
  • 乗換路線が0件の場合に種別変更画面に遷移できない問題を修正

変更内容

TypeChangeNotify (src/components/TypeChangeNotify.tsx)

  • displayCurrentLine の算出ロジックを、種別が変わる直前の駅の s.line を参照する方式に変更
  • 従来: s.lines(駅に紐づく全路線配列)から検索 → 常磐快速線等の経路外路線が混入する問題があった
  • 修正後: stations 配列で次の種別に変わる直前の駅を特定し、その line プロパティを使用

TrainTypeBox (src/components/TrainTypeBox.tsx)

  • intermediateLineEntry(trainType.lines ベース)を廃止し、nextTrainType を直接参照するように変更
  • nextTrainType.line?.company で会社名、nextTrainType.name で種別名を取得

Main (src/screens/Main.tsx)

  • updateBottomState で transferLines が0件の場合でも isTypeWillChange なら TYPE_CHANGE に直接遷移するように修正

Test plan

  • 小田急→千代田線→常磐線の経路で、TypeChangeNotify左側に「東京メトロ千代田線」が表示されることを確認
  • 東急→副都心線→東武の経路で、左側に「東急東横線」が表示されることを確認
  • TrainTypeBoxの「〜線内」表示が正しく表示されることを確認
  • 乗換路線が0件の駅でもタップでTYPE_CHANGE画面に遷移できることを確認
  • npm run typecheck ✅
  • npm run lint ✅
  • npm test ✅

🤖 Generated with Claude Code

Summary by CodeRabbit

変更内容

  • バグ修正

    • 電車種別が変わる際の中間路線名を、直前の駅情報から正しく表示するよう改善しました。
    • 「次の電車種別」の表示判定を所在会社情報に基づき安定化し、表示ラベルの参照元を統一しました。
    • 種別変更時に画面下部が適切に「種別変更」へ遷移する条件を追加しました。
  • テスト

    • 中間路線表示のテストデータを更新し、期待動作を検証するケースを整備しました。

@github-actions github-actions Bot added the react label Mar 28, 2026
@coderabbitai

coderabbitai Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

駅一覧を基に、列車 typeId が変わる直前の駅の .line を中間路線として決定するよう TypeChangeNotify を変更。TrainTypeBox は nextTrainType.line を直接参照して次電車表示判定へ切替。Main の下部状態遷移に TYPE_CHANGE への早期遷移を追加。テストモックを更新。

変更内容

Cohort / File(s) Summary
TypeChangeNotify 本体
src/components/TypeChangeNotify.tsx
displayCurrentLine が station と selectedDirection を基に stations をスライスし、スライス内で trainType.typeId が変わる直前の駅の .line を中間路線として採用するように変更。従来の .lines?.find(...) ロジックを削除。
TypeChangeNotify テスト
src/components/TypeChangeNotify.test.tsx
モック更新:各 line に company を追加。useCurrentTrainType の戻り値に lines 配列を含め、中間路線コンテキストを提供。stations の一箇所で line を切替え、useCurrentStation の戻りを調整。
TrainTypeBox 本体
src/components/TrainTypeBox.tsx
useNextLine() 依存を除去し、nextTrainType?.line(およびその company.id)を用いて「次の列車種別」表示判定と表示テキスト取得を行うように変更。表示ガードと会社名取得ロジックを nextTrainType.line.company 基準へ移行。
Main 下部状態遷移
src/screens/Main.tsx
updateBottomState に早期分岐を追加:前状態が 'LINE' で transferLines が無く、isTypeWillChange が true かつ shouldHideTypeChange が false の場合、即座に bottomState を 'TYPE_CHANGE' に遷移(従来の 'TRANSFER' 処理をスキップ)。

Sequence Diagram(s)

sequenceDiagram
  participant UI as "UI"
  participant Nav as "useCurrentTrainType / navTrainType"
  participant Stations as "stations"
  participant TypeBox as "TrainTypeBox"
  participant Notify as "TypeChangeNotify"
  participant Main as "Main.updateBottomState"

  UI->>Nav: 現在/次の trainType を取得
  UI->>Stations: stations と selectedDirection を取得
  TypeBox->>Nav: nextTrainType?.line を参照して表示判定
  Notify->>Stations: selectedDirection で stations をスライス
  Notify->>Stations: スライス内で typeId が変わる直前の駅を検索
  Notify->>UI: 中間路線 (.line) を返す
  TypeBox->>UI: 次電車表示を更新(company/id 比較)
  UI->>Main: 現在状態・フラグを渡す
  Main->>Main: 条件により bottomState='TYPE_CHANGE' へ早期遷移
  Main-->>UI: 下部状態を更新
Loading

コード審査難易度の推定

🎯 4 (Complex) | ⏱️ ~45 分

詩

🐰 ぴょん、線路さがして中間の駅!
直前の駅の線をそっと借りたよ
次の表示はすっとつながるぴょん
下はすぐに TYPE_CHANGE へ跳んだよ 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、TypeChangeNotifyコンポーネントで経路外の路線が表示されるバグ修正という主要な変更を明確に要約しており、変更内容と一致している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed プルリクエストの説明は、テンプレートの主要なセクション(概要、変更内容、テスト)が記入されており、実装内容が詳細に記述されています。

✏️ 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 feature/fix-display-current-line-selection

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

TinyKitten and others added 4 commits March 29, 2026 07:59
useCurrentTrainTypeが返すtrainTypeにはlinesが含まれない場合があるため、
navigationState.trainType(fetchedTrainTypesから選択されたもの)を優先的に参照する

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@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 the current code and only fix it if needed.

Inline comments:
In `@src/components/TrainTypeBox.tsx`:
- Around line 104-107: intermediateLineEntry currently uses lines?.find(l =>
l.id !== currentLine?.id) which can return a previously passed line (e.g., A
when current is B); change the logic in the useMemo so you locate the index of
currentLine in lines (using currentLine?.id) and then search only lines with a
greater index (i > currentIndex) to pick the first subsequent line; reference
the existing symbols intermediateLineEntry, useMemo, navTrainType, trainType,
currentLine and lines when making the change.

In `@src/components/TypeChangeNotify.tsx`:
- Around line 1286-1290: The current logic in displayCurrentLine (using
lines?.find to set intermediate) picks the first matching intermediate line and
thus returns the upstream/first one in multi-intermediate routes; instead
restrict the search to lines strictly between currentLine and nextLine and
return the one closest to nextLine (i.e., the last matching intermediate).
Replace the lines?.find(...) usage with logic that locates the slice/range
between currentLine and nextLine (using their indices in lines from navTrainType
or trainType) and pick the last element in that range as intermediate, ensuring
variables referenced are navTrainType, trainType, lines, currentLine, nextLine,
and intermediate (falling back to currentLine if none).
🪄 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: 7bb2e9ca-3fe0-47b1-812d-96f8ce60ee37

📥 Commits

Reviewing files that changed from the base of the PR and between 4d9ce0a and 88f0c00.

📒 Files selected for processing (2)
  • src/components/TrainTypeBox.tsx
  • src/components/TypeChangeNotify.tsx

Comment thread src/components/TrainTypeBox.tsx Resolved
Comment thread src/components/TypeChangeNotify.tsx Resolved
trainType.linesに小田急多摩線・小田急小田原線等の同一会社路線が含まれる場合、
路線IDでの除外では小田急小田原線が先にヒットしてしまうため、
会社IDで比較して同一会社の路線をスキップするように修正

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@TinyKitten
TinyKitten force-pushed the feature/fix-display-current-line-selection branch from 867b35e to b0f693b Compare March 28, 2026 23:56

@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.

♻️ Duplicate comments (1)
src/components/TrainTypeBox.tsx (1)

103-108: ⚠️ Potential issue | 🟠 Major

会社ID比較だけでは逆側の路線誤選択を防げません。

Line 106 の find() は先頭から固定で走るので、trainType.lines = [小田急多摩, 小田急小田原, 千代田, 常磐] で現在が千代田のときに小田急側を拾えます。currentLine の位置と selectedDirection を基準に、進行方向側だけを候補にしないと 線内 表示がまだ過去側へ戻ります。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/TrainTypeBox.tsx` around lines 103 - 108, The current
intermediateLineEntry useMemo picks the first line with a different company.id,
which can choose a line behind the current position; update the logic to compute
the index of currentLine within (navTrainType?.lines ?? trainType?.lines), then
filter candidate lines to only those on the selectedDirection side (e.g.,
indices greater than currentIndex for forward, less for backward) before calling
find by company id; modify the useMemo block that defines intermediateLineEntry
to use currentIndex, selectedDirection and a directional filter so only
forward-facing lines are considered when locating a different company.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/components/TrainTypeBox.tsx`:
- Around line 103-108: The current intermediateLineEntry useMemo picks the first
line with a different company.id, which can choose a line behind the current
position; update the logic to compute the index of currentLine within
(navTrainType?.lines ?? trainType?.lines), then filter candidate lines to only
those on the selectedDirection side (e.g., indices greater than currentIndex for
forward, less for backward) before calling find by company id; modify the
useMemo block that defines intermediateLineEntry to use currentIndex,
selectedDirection and a directional filter so only forward-facing lines are
considered when locating a different company.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7a9c9410-6c9d-437c-afa2-09274a02792d

📥 Commits

Reviewing files that changed from the base of the PR and between 88f0c00 and 4daa820.

📒 Files selected for processing (4)
  • src/components/TrainTypeBox.tsx
  • src/components/TypeChangeNotify.test.tsx
  • src/components/TypeChangeNotify.tsx
  • src/screens/Main.tsx
✅ Files skipped from review due to trivial changes (1)
  • src/screens/Main.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/TypeChangeNotify.tsx
  • src/components/TypeChangeNotify.test.tsx

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/TrainTypeBox.tsx`:
- Around line 246-252: showNextTrainType currently only checks for
nextTrainType?.line and compares currentLine?.company?.id to
nextTrainType.line.company?.id, so when company or its name fields
(nameEnglishShort/nameShort) are undefined you render "undefined…" in the
template; fix by deriving a safe displayCompanyName from
nextTrainType.line.company (e.g., prefer nameEnglishShort, then nameShort, then
null) and use that in the useMemo condition and in the render: update the
useMemo (showNextTrainType) to require a non-null displayCompanyName and
nextTrainType?.line, and change the template usage to use the displayCompanyName
(or hide the whole fragment when null) so you never interpolate undefined
company names; reference symbols: showNextTrainType, nextTrainType, currentLine,
nameEnglishShort, nameShort, and the hook useNextTrainType.
🪄 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: 8169bec7-6282-4183-a0db-75ea7b6b6a3e

📥 Commits

Reviewing files that changed from the base of the PR and between 4daa820 and f288960.

📒 Files selected for processing (1)
  • src/components/TrainTypeBox.tsx

Comment thread src/components/TrainTypeBox.tsx Resolved
@TinyKitten TinyKitten self-assigned this Mar 29, 2026

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/TrainTypeBox.tsx`:
- Around line 246-259: nextTrainTypeCompanyName is computed but not used in the
render, and the render directly reads company.nameEnglishShort / nameShort which
causes "undefined" in EN mode when only nameShort exists; update the code to
consistently derive a language-aware company name and use it both for visibility
and rendering: replace the current nextTrainTypeCompanyName with a
language-specific value (e.g., pick company.nameEnglishShort when in English
mode else company.nameShort), use that value in the showNextTrainType boolean
(alongside nextTrainType and currentLine company id checks), and update the
render portion that currently reads company.nameEnglishShort/nameShort to render
nextTrainTypeCompanyName (with a final null/empty fallback), ensuring
nextTrainType, nextTrainTypeCompanyName, showNextTrainType and currentLine
comparisons remain in dependencies.
🪄 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: 4645ed23-b9eb-4a59-a86d-1ff3b4e86194

📥 Commits

Reviewing files that changed from the base of the PR and between f288960 and 619259b.

📒 Files selected for processing (1)
  • src/components/TrainTypeBox.tsx

Comment thread src/components/TrainTypeBox.tsx Resolved
@TinyKitten
TinyKitten merged commit 040a3a2 into dev Mar 29, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/fix-display-current-line-selection branch March 29, 2026 01:27
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