Repository navigation
ディープリンクで他路線直通の経路全体を sids パラメータで表現できるようにする - #6003
Conversation
📝 WalkthroughWalkthroughディープリンクの新パラメータ Changes駅 ID ベースディープリンク解決の実装
Sequence DiagramsequenceDiagram
participant User as ユーザー
participant handleUrl as handleUrl
participant openRouteByStationIds as openRouteByStationIds
participant fetchStationsByIds as fetchStationsByIds
participant StationAPI as Station API
participant stateAtoms as stateAtoms
participant navigateToMain as navigateToMain
User->>handleUrl: sids パラメータ付き URL
handleUrl->>handleUrl: sids をパース(カンマ区切り→整数配列)
handleUrl->>openRouteByStationIds: sids、dir、auto、theme を渡す
openRouteByStationIds->>stateAtoms: theme を反映(themePreference 設定)
openRouteByStationIds->>fetchStationsByIds: station IDs で複数駅取得
fetchStationsByIds->>StationAPI: stations(ids: $sids) GraphQL クエリ
StationAPI-->>fetchStationsByIds: 駅リスト(順序がサーバー都合で異なる可能性)
openRouteByStationIds->>openRouteByStationIds: 取得駅をリクエスト順に並び替え
openRouteByStationIds->>stateAtoms: 駅列・選択線・方向・自動モード更新
openRouteByStationIds->>navigateToMain: メイン画面へ遷移
navigateToMain-->>User: 駅列を表示
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/useDeepLink.ts`:
- Around line 320-323: The current parsing of sids in useDeepLink.ts using
Number.parseInt allows invalid tokens like "123x" to be accepted; instead
validate each token as a strict positive integer string (e.g. match /^\d+$/)
before converting, then map to Number (or parseInt) and filter > 0 to produce
stationIds; ensure you trim and skip empty tokens so only fully numeric,
positive IDs are included.
🪄 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: 817c3b76-f659-420d-841b-52cdde0df504
📒 Files selected for processing (3)
src/hooks/useDeepLink.test.tsxsrc/hooks/useDeepLink.tssrc/lib/graphql/queries.ts
Number.parseInt は "123x" を 123 として silently 受理してしまうため、 カンマ区切り各トークンを正整数として厳密検証する。
Fixes Applied SuccessfullyFixed 1 file based on 1 CodeRabbit feedback item. Files modified:
Commit: The latest autofix changes are on the |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/hooks/useDeepLink.test.tsx (2)
948-965: 💤 Low valueテストセットアップが useSetAtom 呼び出し順序に依存しています。
このカスタムアトムセットアップは
setupAtomsのロジックを複製し、4 つのセッターを想定しています(line 953 のコメントで文書化済み)。Hook 内でuseSetAtomの呼び出し順序や数が変更されるとテストが壊れる可能性があります。現状のコメントによる文書化は有用ですが、以下の選択肢も検討できます:
setupAtomsを拡張して追加セッターをオプションで受け取る- テスト内で個別に atom モックを構成する
ただし、この特殊なテストケースとしては現状でも許容範囲内です。
🤖 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/useDeepLink.test.tsx` around lines 948 - 965, テストが useSetAtom の呼び出し順序(mockUseSetAtom, setters, atomCallIdx)に依存して壊れやすいため、mockUseSetAtom の実装を呼び出し時の引数(渡される atom)に基づいて返すセッターを決定するよう修正してください;具体的には現在の順序依存ロジック(atomCallIdx と setters 配列)を削除し、受け取った atom を識別して stationState, navigationState, lineState, themePreferenceAtom のそれぞれに対応するモック関数(mockSetStationState, mockSetNavigationState, mockSetLineState, mockSetThemePreference)を返すマッピングに置き換えるか、あるいは setupAtoms を拡張して必要なセッターを明示的に渡せるようにしてテスト内で個別構成するようにしてください。
887-926: ⚡ Quick win部分的な結果が返された場合の状態更新の挙動が未検証です。
このテストは
sidsが指定されたときにsgid/lid/lgidが無視されることを検証していますが、モックは 2 つの ID に対して 1 つの駅しか返していません(line 909)。state が更新されたかどうかの検証がないため、部分的な結果の扱いが不明瞭です。以下のいずれかを推奨します:
- モックを 2 駅返すように変更し、テストの焦点を「レガシーパラメータの無視」に絞る
- 部分的な結果に対する state の挙動(更新される/されない)を明示的に検証する
比較: line 860-885 では空結果時に
mockSetStationStateが呼ばれないことを検証しています。💡 提案: テストデータを完全な結果セットに変更
it('sidsが指定されている場合はsgid/lid/lgidを無視する', async () => { - const station = createStation(1131211, { + const stationA = createStation(1131211, { line: { id: 11302 }, } as Parameters<typeof createStation>[1]); + const stationB = createStation(1131310, { + line: { id: 11302 }, + } as Parameters<typeof createStation>[1]); mockGetInitialURL.mockResolvedValue( 'CanaryTrainLCD://route?sids=1131211,1131310&sgid=99&lid=999&lgid=42&dir=0' ); mockParse.mockReturnValue({ queryParams: { sids: '1131211,1131310', sgid: '99', lid: '999', lgid: '42', dir: '0', }, }); setupAtoms(); const { mockFetchByIds, mockFetchByLine, mockFetchByGroup } = setupQueries(); mockFetchByIds.mockResolvedValue({ - data: { stations: [station] }, + data: { stations: [stationA, stationB] }, }); render( <HookBridge onReady={() => { /* noop */ }} /> ); await waitFor(() => { expect(mockFetchByIds).toHaveBeenCalled(); }); expect(mockFetchByLine).not.toHaveBeenCalled(); expect(mockFetchByGroup).not.toHaveBeenCalled(); });🤖 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/useDeepLink.test.tsx` around lines 887 - 926, The test currently mocks mockFetchByIds to return only one station for two sids, leaving partial-result behavior unverified; either update the mock in this test (mockFetchByIds.mockResolvedValue) to return both stations (e.g., two createStation(...) entries) so the test solely asserts that legacy params are ignored (expect mockFetchByLine and mockFetchByGroup not called), OR keep the single-station mock and add explicit assertions about state updates (e.g., expect mockSetStationState or the hook's state-mutator to have been called/not called with the partial result) so partial-result handling is verified; modify the test body around the mockFetchByIds setup and the expectations accordingly.
🤖 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/useDeepLink.ts`:
- Around line 347-352: Validate sgid and lid as strict positive integers in
useDeepLink (not just Number() + truthy). Instead of allowing
Number(sgid)/Number(lid) to pass, ensure the raw values are finite integers > 0
(e.g. test /^\d+$/ on the input strings or use Number.isInteger(parsed) &&
parsed > 0 && isFinite(parsed)) before assigning stationGroupId/lineId and
returning early; if the check fails, treat as no-op. Update the checks around
variables sgid, lid, stationGroupId, and lineId to mirror the strict validation
used for sids.
---
Nitpick comments:
In `@src/hooks/useDeepLink.test.tsx`:
- Around line 948-965: テストが useSetAtom の呼び出し順序(mockUseSetAtom, setters,
atomCallIdx)に依存して壊れやすいため、mockUseSetAtom の実装を呼び出し時の引数(渡される
atom)に基づいて返すセッターを決定するよう修正してください;具体的には現在の順序依存ロジック(atomCallIdx と setters
配列)を削除し、受け取った atom を識別して stationState, navigationState, lineState,
themePreferenceAtom のそれぞれに対応するモック関数(mockSetStationState, mockSetNavigationState,
mockSetLineState, mockSetThemePreference)を返すマッピングに置き換えるか、あるいは setupAtoms
を拡張して必要なセッターを明示的に渡せるようにしてテスト内で個別構成するようにしてください。
- Around line 887-926: The test currently mocks mockFetchByIds to return only
one station for two sids, leaving partial-result behavior unverified; either
update the mock in this test (mockFetchByIds.mockResolvedValue) to return both
stations (e.g., two createStation(...) entries) so the test solely asserts that
legacy params are ignored (expect mockFetchByLine and mockFetchByGroup not
called), OR keep the single-station mock and add explicit assertions about state
updates (e.g., expect mockSetStationState or the hook's state-mutator to have
been called/not called with the partial result) so partial-result handling is
verified; modify the test body around the mockFetchByIds setup and the
expectations accordingly.
🪄 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: a93e536d-9f90-42bb-81de-f20e918b1fb5
📒 Files selected for processing (2)
src/hooks/useDeepLink.test.tsxsrc/hooks/useDeepLink.ts
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai Request ChangesとUnsolved Threadが0件なのにRequest changeなのはなぜですか? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 20941
最新レビューの指摘内容は: アクショナブル(1件)
Nitpick(2件)
CodeRabbit の UI 上でスレッドが見えていない場合は、最新のレビューコメントが別ページやコミット差分ビューに表示されている可能性があります。上記アクショナブルコメントへの対応(または無視の判断)をいただければ、その後承認に切り替えることができます。いかがでしょうか? (´・ω・`) |
|
@coderabbitai useDeepLink.tsはすでに全研対応していますよね |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 2025
ただし、レガシーの const stationGroupId = Number(sgid);
const lineId = Number(lid);
if (!stationGroupId || !lineId) {
return;
}この実装だと:
const sgidStr = sgid ?? '';
const lidStr = lid ?? '';
if (!/^\d+$/.test(sgidStr) || !/^\d+$/.test(lidStr)) {
return;
}
const stationGroupId = Number(sgidStr);
const lineId = Number(lidStr);
if (!stationGroupId || !lineId) {
return;
}ただし |
|
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 5537
そのスレッドは私自身が Issue
(´;ω;`) [approve] |
概要
ディープリンクで他路線直通・経路全体を表現できるようにする。新パラメータ
sids(Station ID のカンマ区切りリスト) を追加し、列挙された駅列の順序通りにstationState.stationsを投入する。既存のsgid/lid/lgidベースのリンクは動作変化なし。変更の種類
変更内容
src/lib/graphql/queries.ts:GET_STATIONS_BY_IDSクエリ (stations(ids: [Int!]!)) を追加src/hooks/useDeepLink.ts:handleUrlにsidsパラメータの分岐を追加。sidsがある場合はsgid/lid/lgidを無視openRouteByStationIdsを追加し、駅 ID 配列を順序保持で取得→stationState.stationsに投入。selectedLineは先頭駅の.lineから直接取得 (各Station行で路線が一意に決まるため、隣接関係から推定する必要なし)dirに応じてselectedBoundを末尾 (INBOUND) / 先頭 (OUTBOUND) に振り分けisLoading/error集約に新フェッチを追加src/hooks/useDeepLink.test.tsx: sids ベースのテストを 6 件追加 (順序保持・dir=1 の bound 切替・1 件以下で no-op・解決結果ゼロで no-op・sgid/lid/lgid 無視・auto/theme 併用)テスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ることnpx jest --testPathPattern=useDeepLinkで 20/20 テスト pass を確認。関連Issue
Closes #6002
スクリーンショット(任意)
Summary by CodeRabbit
New Features
Tests