Skip to content

trainRouteクエリの設計変更に追従し、シミュレーション用の速度計算をサーバーへ委譲 - #6341

Merged
TinyKitten merged 6 commits into
devfrom
feature/sync-train-route-query-args
Jul 4, 2026
Merged

TinyKitten merged 6 commits into
devfrom
feature/sync-train-route-query-args

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 3, 2026 •

Copy link
Copy Markdown
Member

概要

gql-stg.trainlcd.app のスキーマ変更(trainRoute クエリの引数 fromStationGroupId/toStationGroupId → fromStationId/toStationId への改名)に追従し、あわせて useSimulationMode の速度・加減速度・区間距離の算出を新設した GetTrainRoute クエリへ委譲しました。サーバー委譲により不要になった路線種別/列車種別ベースの定数テーブルは削除しています。

変更の種類

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

変更内容

  • GraphQLスキーマ変更に追従して src/@types/graphql.d.ts を再生成(trainRoute の引数改名を反映)
  • src/lib/graphql/queries.ts に GetTrainRoute クエリ(distanceFromPrevious / maxAcceleration / maxDeceleration / maxSpeed)を追加
  • src/hooks/useSimulationMode.ts の速度プロファイル生成を GetTrainRoute の応答に委譲し、LINE_TYPE_MAX_ACCEL_IN_M_S 等の路線種別/列車種別ベースの定数テーブルによる計算と getDistance を用いた直線距離計算を廃止
    • サーバーが返す segments は駅IDではなく maybeRevsersedStations と同じ並び順の配列位置で対応付け(同一駅IDが非隣接位置に複数回出現するケースでの誤対応を避けるため)
  • 上記委譲により全ファイルから未参照になった src/constants/simulationMode.ts(路線種別/列車種別ベースの速度・加減速度定数)を削除
  • src/hooks/useSimulationMode.test.tsx を useGraphQLQuery のモックに合わせて全面的に書き直し

テスト

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

関連Issue

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

Summary by CodeRabbit

  • 新機能
    • 列車ルート取得に基づき、区間ごとの最高速度・加減速度を反映した走行計算に対応しました。
    • 進行方向に応じて出発駅・到着駅を切り替えて再計算します。
  • バグ修正
    • 区間距離の算出をルート情報に合わせて見直し、より正確な速度プロファイルを生成します。
    • 必要なルート情報が不足する場合は無効な計算を行わずスキップします。

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

coderabbitai Bot commented Jul 3, 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: ASSERTIVE

Plan: Pro

Run ID: 4e657679-855c-4f5d-977d-0cb3ef5f29db

📥 Commits

Reviewing files that changed from the base of the PR and between e5e154c and 369e2fa.

📒 Files selected for processing (1)
  • src/hooks/useSimulationMode.ts

📝 Walkthrough

Walkthrough

列車ルートの速度プロファイル生成を、固定定数ベースから GraphQL の GET_TRAIN_ROUTE で取得した segments ベースへ切り替え、関連する型定義、定数、テストを更新しています。

Changes

trainRouteクエリへの移行

Layer / File(s) Summary
GraphQL型とクエリ定義
src/@types/graphql.d.ts, src/lib/graphql/queries.ts
QueryTrainRouteArgs を fromStationId 前提に更新し、GetTrainRouteQuery/Variables 型と GET_TRAIN_ROUTE クエリを追加。
useSimulationModeのGraphQL連携と区間計算
src/hooks/useSimulationMode.ts
fromStationId/toStationId を算出して GET_TRAIN_ROUTE を呼び出し、trainRoute.segments から距離・速度パラメータを使って区間生成を行うよう変更。
旧シミュレーション定数の削除
src/constants/simulationMode.ts, src/constants/index.ts, src/hooks/useSimulationMode.test.tsx
速度/加減速度定数の削除と再エクスポート除去にあわせ、関連テストの前提も trainRoute ベースへ更新。
useSimulationModeテストのtrainRouteモック化
src/hooks/useSimulationMode.test.tsx
useGraphQLQuery のモックと mockTrainRoute を追加し、各ケースの期待値・コメントを segments 前提に更新。

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant useSimulationMode
  participant useGraphQLQuery
  participant GraphQLServer
  participant generateTrainSpeedProfile

  useSimulationMode->>useGraphQLQuery: GET_TRAIN_ROUTE(fromStationId, toStationId, lineGroupId)
  useGraphQLQuery->>GraphQLServer: trainRoute取得
  GraphQLServer-->>useGraphQLQuery: trainRoute.segments
  useGraphQLQuery-->>useSimulationMode: trainRouteData
  useSimulationMode->>useSimulationMode: distanceFromPrevious を積算
  useSimulationMode->>generateTrainSpeedProfile: maxSpeed/maxAcceleration/maxDeceleration
  generateTrainSpeedProfile-->>useSimulationMode: 速度プロファイル
Loading

Possibly related PRs

  • TrainLCD/MobileApp#5992: src/constants/simulationMode.ts の TrainTypeKind 系の定数変更と同じ領域に関わります。
  • TrainLCD/MobileApp#6210: useGraphQLQuery と GraphQL クエリ層の導入・更新と接続しています。
  • TrainLCD/MobileApp#6331: src/@types/graphql.d.ts の QueryTrainRouteArgs と trainRoute 系型定義の更新が重なります。

Poem

ぴょんと跳ねて GraphQL へ 🐰
segments が来たよ、道のりも来た
速さと減速をふわりと受け取り
うさぎの足どり、くるくる正確
新しい線路でまた会おう 🚃

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 変更内容(trainRouteの引数変更追従と速度計算のサーバー委譲)を適切に要約しており、主な変更点が明確です。
Description check ✅ Passed 概要・変更内容・テストが揃っており、テンプレートの必須項目をほぼ満たしています。
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.
✨ 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/sync-train-route-query-args

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

@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 3, 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.

@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 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.

@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 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.

@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks/useSimulationMode.test.tsx (1)

72-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

mockStation は共通 factory に寄せられます。 src/utils/test/factories.ts の createStation で置き換えられるので、ここでは mockPassStation だけ通過駅用の派生として残し、setupAtomMocks はこのテスト固有のままで十分です。

🤖 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/hooks/useSimulationMode.test.tsx` around lines 72 - 104, The test helper
in useSimulationMode.test.tsx duplicates station construction logic that already
exists in createStation, so replace mockStation usage with the shared factory
from src/utils/test/factories.ts and keep only mockPassStation as the
test-specific derived helper. Update the local setupAtomMocks/test setup to
build stations through createStation for the common cases, preserving the
existing line override behavior via the helper’s arguments rather than
re-declaring the full Station shape.

Source: Path instructions

🤖 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/hooks/useSimulationMode.ts`:
- Around line 81-95: `useSimulationMode` の `useGraphQLQuery(GET_TRAIN_ROUTE)` で
`trainRouteData` だけを受けており、失敗時の `error` が無視されています。`useSimulationMode` 内で
`error`(必要なら `loading` も)を分解して、クエリ失敗時にログ出力などで明示的に可視化してください。特に `trainRouteData`
を使う `useEffect` や `segments` 生成の前で、`useGraphQLQuery` の結果を見て失敗状態を追跡できるようにしてください。

In `@src/lib/graphql/queries.ts`:
- Around line 479-498: The GraphQL operation name in GET_TRAIN_ROUTE does not
follow the required FeatureVerbQuery naming pattern. Update the query name
inside the gql definition from GetTrainRoute to GetTrainRouteQuery so it matches
the coding guideline and stays consistent with other query names like
GetStationListQuery.

---

Outside diff comments:
In `@src/hooks/useSimulationMode.test.tsx`:
- Around line 72-104: The test helper in useSimulationMode.test.tsx duplicates
station construction logic that already exists in createStation, so replace
mockStation usage with the shared factory from src/utils/test/factories.ts and
keep only mockPassStation as the test-specific derived helper. Update the local
setupAtomMocks/test setup to build stations through createStation for the common
cases, preserving the existing line override behavior via the helper’s arguments
rather than re-declaring the full Station shape.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 61a8a12d-497e-4b29-8562-5d069ef22d44

📥 Commits

Reviewing files that changed from the base of the PR and between 9a4347d and e5e154c.

📒 Files selected for processing (6)
  • src/@types/graphql.d.ts
  • src/constants/index.ts
  • src/constants/simulationMode.ts
  • src/hooks/useSimulationMode.test.tsx
  • src/hooks/useSimulationMode.ts
  • src/lib/graphql/queries.ts
💤 Files with no reviewable changes (2)
  • src/constants/simulationMode.ts
  • src/constants/index.ts

Comment thread src/hooks/useSimulationMode.ts Resolved
Comment thread src/lib/graphql/queries.ts Resolved
@coderabbitai

coderabbitai Bot commented Jul 4, 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 1 file(s) based on 2 unresolved review comments.

Files modified:

  • src/hooks/useSimulationMode.ts

Commit: 2798089087904886c3bc3a779e04cb0e1493365e

The changes have been pushed to the feature/sync-train-route-query-args branch.

Time taken: 2m 52s

coderabbitai Bot and others added 2 commits July 4, 2026 07:19
@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved and changes approved.

@TinyKitten
TinyKitten merged commit c083061 into dev Jul 4, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/sync-train-route-query-args branch July 4, 2026 07:37
@TinyKitten TinyKitten mentioned this pull request Jul 4, 2026
4 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