Skip to content

プリセット保存時の始発駅指定フローを廃止して経路内の最寄駅から自動解決 - #6640

Merged
TinyKitten merged 2 commits into
devfrom
claude/preset-auto-origin-station-5rjpbd
Aug 10, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/preset-auto-origin-station-5rjpbd

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

概要

プリセット保存時、終点を明示的にユーザーが設定した場合にだけ表示されていた「始発駅を選択」フローを廃止しました。代わりに、保存する経路内の最寄駅から始発駅(保存される direction)を自動で解決します。ユーザーはプリセット名を入力するだけで保存できます。

変更の種類

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

変更内容

  • SavePresetNameModal から始発駅選択セクション(方向カード2枚・選択必須バリデーション・不透明度アニメーション)を削除。DirectionOption 型と directionOptions prop も撤去し、onSubmit を (name: string) => void に簡素化
  • src/utils/presetRouteEndpoints.ts に resolvePresetSaveDirection を追加。保存する経路は行き先を境に片側だけなので、経路内の最寄駅がどちら側にあるかで direction(=駅一覧のどちら側の終端から乗るか)が一意に決まる。最寄駅は「現在駅が駅一覧に含まれていればその駅 → 含まれなければ座標距離で最も近い駅」の順に解決する
  • 行き先が駅一覧の終端にある場合は反対側に一意に定まるため、座標計算を経ずに確定させる
  • 行き先そのものは始発駅候補から除外。これは既存の getPresetOriginStation が駅一覧の並び順の食い違いを検知するための前提(従来は保存時UIのフィルタが担保していたもの)を引き継ぐため
  • SelectBoundModal の presetDirectionOptions を presetSaveDirection に置き換え。方向解決には生の pendingStation(無ければ GPS 確定駅)を渡す。effectiveStation は区間外だと stations[0] へ倒れて実際の現在地を表さないため
  • effectiveStations(notifyStationIds の絞り込み範囲)を presetSaveDirection から導出するよう変更。復元時の usePresetStops.presetStops と同じ切り方に揃えることで、保存する向きと通知駅の絞り込み範囲が構造的にズレないようにした
  • 未使用になった翻訳キー selectStartStationTitle / departure を ja/en 双方から削除
  • resolvePresetSaveDirection のユニットテストを11件追加(終端ケース、座標フォールバック、現在駅=行き先のケース、解決不能時の null など)
  • SelectBoundModal.render.test.tsx に、乗車駅未設定時に GPS 確定駅の座標から向きが決まることを検証するテストを追加

実際の始発駅は復元時に既存の usePresetStops の nearestPresetStation(経路内の最寄中間駅)が解決するため、「保存した経路内の最寄駅から乗る」挙動はランタイムで成立します。

影響範囲・リグレッションリスク

  • 保存済みプリセットのデータ構造(saved_routes テーブル)は変更していないため、既存プリセットの互換性に影響なし
  • direction の意味・復元ロジック(getPresetOriginStation / getPresetRouteEndpoints)は不変。変わるのは保存時に direction を誰が決めるか(ユーザー選択 → 自動解決)だけ
  • 従来ユーザーが「現在地と逆側の終端から乗る」プリセットを意図的に作れたが、今後は現在地側に自動で寄る。この経路を作る手段は無くなる
  • effectiveStations の導出変更により、行き先が駅一覧の先頭にある場合の絞り込み範囲が [行き先] の1駅から経路全体に変わる(保存される direction と整合する側へ修正)

テスト

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

npm test は 215 suites / 2274 tests すべて成功。追加したリグレッションテストは、修正前のコードでは INBOUND を返して失敗することも確認済みです。なお本セッションの環境にはシミュレータ/エミュレータが無いため、実機でのUI確認は未実施です。

関連Issue

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

Summary by CodeRabbit

  • 新機能

    • プリセット保存時の方向を、現在駅・最寄り駅・行き先から自動判定するようになりました。
    • 保存時に方向を手動で選択する必要がなくなりました。
  • 改善

    • プリセット名の入力を整理し、名前のみで保存できるようになりました。
    • 名前の前後の空白は自動的に除去され、未入力時のみ保存ボタンが無効になります。
    • 不要になった方向選択関連の表示と翻訳を削除しました。

@TinyKitten TinyKitten self-assigned this Aug 10, 2026
@github-actions github-actions Bot added the react label Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

プリセット保存時の方向選択UIを削除しました。駅一覧、目的駅、現在駅または最寄駅から保存方向を自動解決します。保存名モーダルは、トリム済みの名前だけを送信します。方向解決と保存処理のテストを追加しました。

Changes

プリセット保存方向

Layer / File(s) Summary
保存方向の解決ロジック
src/utils/presetRouteEndpoints.ts, src/utils/presetRouteEndpoints.test.ts
resolvePresetSaveDirection を追加しました。目的駅、現在駅、最寄駅、駅の順序から INBOUND、OUTBOUND、または null を返します。各条件のテストを追加しました。
保存名モーダルの簡素化
src/components/SavePresetNameModal.tsx, assets/translations/en.json, assets/translations/ja.json
方向選択UI、DirectionOption、方向選択関連の状態とアニメーションを削除しました。onSubmit は名前だけを受け取ります。
保存処理への統合
src/components/SelectBoundModal.tsx, src/components/SelectBoundModal.render.test.tsx
自動解決した方向を保存処理へ渡します。方向候補の生成とモーダルへの受け渡しを削除しました。GPS確定駅を使用する保存処理のテストを追加しました。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SelectBoundModal
  participant resolvePresetSaveDirection
  participant SavePresetNameModal
  participant SavedRoutes
  User->>SelectBoundModal: プリセット保存を開始する
  SelectBoundModal->>resolvePresetSaveDirection: 駅一覧、目的駅、現在駅を渡す
  resolvePresetSaveDirection-->>SelectBoundModal: 保存方向を返す
  SelectBoundModal->>SavePresetNameModal: 名前入力画面を表示する
  User->>SavePresetNameModal: プリセット名を送信する
  SavePresetNameModal-->>SelectBoundModal: トリム済みの名前を返す
  SelectBoundModal->>SavedRoutes: 自動解決した方向で保存する
Loading

Possibly related PRs

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 タイトルは、始発駅選択フローの廃止と経路内の最寄駅による自動解決という主要変更を明確に示しています。
Description check ✅ Passed 概要、変更内容、影響範囲、テスト結果を記載し、テンプレートの必須項目を十分に満たしています。
✨ 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 claude/preset-auto-origin-station-5rjpbd

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

🧹 Nitpick comments (1)
src/utils/presetRouteEndpoints.test.ts (1)

149-267: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

afterEach でモック状態をリセットしてください。

このテストファイルには jest.clearAllMocks() を呼び出す afterEach がありません。テスト規約に従い、共通クリーンアップを追加してください。

As per coding guidelines, afterEach では jest.clearAllMocks() を呼び出すこと。

🤖 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/utils/presetRouteEndpoints.test.ts` around lines 149 - 267, Add an
afterEach cleanup for the resolvePresetSaveDirection test suite that calls
jest.clearAllMocks(), following the file’s existing test setup conventions.
Ensure mock state is cleared after every test without changing the test cases or
their assertions.

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/components/SelectBoundModal.tsx`:
- Around line 642-650: Update the presetSaveDirection useMemo in
SelectBoundModal to pass the actual current station using station ??
confirmedStation, rather than effectiveStation ?? confirmedStation. Preserve
coordinate-based nearest-station resolution when the current station is outside
the route, and add a SelectBoundModal test covering an unset station with
confirmedStation on the opposite side of the destination.

---

Nitpick comments:
In `@src/utils/presetRouteEndpoints.test.ts`:
- Around line 149-267: Add an afterEach cleanup for the
resolvePresetSaveDirection test suite that calls jest.clearAllMocks(), following
the file’s existing test setup conventions. Ensure mock state is cleared after
every test without changing the test cases or their assertions.
🪄 Autofix

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: 6df842b8-a929-4105-991d-9b4cd4c55275

📥 Commits

Reviewing files that changed from the base of the PR and between 0398379 and 84d1e99.

📒 Files selected for processing (6)
  • assets/translations/en.json
  • assets/translations/ja.json
  • src/components/SavePresetNameModal.tsx
  • src/components/SelectBoundModal.tsx
  • src/utils/presetRouteEndpoints.test.ts
  • src/utils/presetRouteEndpoints.ts
💤 Files with no reviewable changes (2)
  • assets/translations/ja.json
  • assets/translations/en.json

Comment thread src/components/SelectBoundModal.tsx Resolved
@TinyKitten
TinyKitten merged commit a9ef8e7 into dev Aug 10, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/preset-auto-origin-station-5rjpbd branch August 10, 2026 03:56
@TinyKitten TinyKitten mentioned this pull request Aug 10, 2026
5 of 9 tasks
@TinyKitten TinyKitten mentioned this pull request Aug 11, 2026
7 of 9 tasks
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.

2 participants