Skip to content

東京メトロ/TY系コンポーネントを小田急テーマ向けに抽象化 - #5696

Merged
TinyKitten merged 4 commits into
devfrom
feature/refactor-east-theme-components
Mar 27, 2026
Merged

TinyKitten merged 4 commits into
devfrom
feature/refactor-east-theme-components

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • HeaderTokyoMetroとHeaderTYの共通構造をHeaderEastに統合し、configオブジェクトで差分を吸収
  • TrainTypeBoxのisTYプロップをlocalTypePrefix/nextTrainTypeColorに汎用化
  • LineBoardEastにシェブロン色ペアのカスタマイズ(chevronColorPair)を追加、ChevronTYにORANGEカラー追加
  • TypeChangeNotifyのMetroBarsをEastBarsにリネームし、グラデーション生成関数(getBarGradient/getBoxGradient)を外部から注入可能に
  • HeaderEast・TypeChangeNotify・LineBoardEastのテストを追加

Test plan

  • npm run typecheck パス
  • npm run lint パス
  • npm test 全145 suites / 1369 tests パス
  • TOKYO_METRO / TOEI / TY テーマの表示が変わっていないことを目視確認

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • 新機能

    • シェヴロンに新色「オレンジ」を追加し、シェヴロン色の組み合わせを指定可能にしました
    • 共通化された新ヘッダーを導入し、テーマ設定で柔軟にカスタマイズできるようになりました(既存ヘッダーは新共通ヘッダーへ委譲)
    • 列車種別表示にローカル接頭辞と「次列車種別」色の外部指定を追加
  • テスト

    • ヘッダーや表示コンポーネントのレンダリングを網羅するテストを追加・拡張しました
  • 改良

    • 種別変更表示のグラデーション生成を外部から制御可能にしました

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

coderabbitai Bot commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

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: a3a11bd6-5403-419d-9e4b-10531a519dcf

📥 Commits

Reviewing files that changed from the base of the PR and between 702026b and f7434ae.

📒 Files selected for processing (1)
  • src/components/LineBoardEast.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/LineBoardEast.test.tsx

📝 Walkthrough

Walkthrough

共有ヘッダーコンポーネント HeaderEast を追加し、HeaderTY/HeaderTokyoMetro を委譲化。ChevronColor 型と chevronColorPair によるシェブロン色制御を導入、TrainTypeBox のプロップAPIを変更、TypeChangeNotify にグラデーション注入を追加。テスト群を複数追加/更新。

Changes

Cohort / File(s) Summary
HeaderEast と設定 / テスト
src/components/HeaderEast/HeaderEast.tsx, src/components/HeaderEast/config.ts, src/components/HeaderEast/index.ts, src/components/HeaderEast/HeaderEast.test.tsx
新規メモ化コンポーネント HeaderEast と HeaderEastThemeConfig、tokyoMetroConfig/tyConfig を追加。アニメーション・LinearGradient・NumberingIcon/TrainTypeBox の条件付きレンダリングとテストを実装。
既存ヘッダーの委譲化
src/components/HeaderTY.tsx, src/components/HeaderTokyoMetro.tsx, src/components/HeaderTokyoMetro.test.tsx, src/components/HeaderTY.test.tsx
HeaderTY/HeaderTokyoMetro のインライン実装を削除し、HeaderEast をラップして各設定を渡す薄いラッパーに置換。テストモックを jest.fn に変更して呼び出し検証を追加。
Chevron 型 & LineBoard の更新
src/components/ChevronTY.tsx, src/components/LineBoardEast.tsx, src/components/LineBoardEast.test.tsx
ChevronColor 型 (`'RED'
TrainTypeBox API 変更
src/components/TrainTypeBox.tsx, src/components/HeaderTY.test.tsx, src/components/HeaderTokyoMetro.test.tsx
isTY を削除し、localTypePrefix?: string と nextTrainTypeColor?: string を導入(デフォルト '' / '#444')。ローカライズキー生成と次列車ラベル色の算出を prefix ベースへ変更。テストで呼び出し引数検証を追加。
TypeChangeNotify のグラデーション抽象化
src/components/TypeChangeNotify.tsx, src/components/TypeChangeNotify.test.tsx
デフォルトのバー表示を EastBars に切替え。ColorGradientFn 型と getBarGradient/getBoxGradient 注入を追加し、EastBars 側で安全にグラデーション色を決定するようにリファクタ。テスト追加。

Sequence Diagram(s)

sequenceDiagram
    participant Client as 呼び出し元
    participant HeaderEast as HeaderEast
    participant Atoms as JotaiAtoms
    participant Anim as useHeaderAnimation
    participant Gradient as LinearGradient
    participant TrainType as TrainTypeBox
    participant Numbering as NumberingIcon

    Client ->> HeaderEast: render(props, config)
    HeaderEast ->> Atoms: read currentLine, headerState, stationNumber
    HeaderEast ->> Anim: request animated styles (headerState, config)
    Anim -->> HeaderEast: animated styles
    HeaderEast ->> Gradient: render with config.gradient (animated styles)
    Gradient ->> TrainType: render TrainTypeBox (props ← config)
    HeaderEast ->> Numbering: condition付きで NumberingIcon を render
    HeaderEast ->> HeaderEast: render station/bound texts and divider
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 分

Possibly related PRs

🐰 東風に乗りて新ヘッダー奏でる
シェブロンは橙に跳ね、色を巡るよ 🧡
箱は軽やかに設定を抱え、
テストは駆けて、縁を確かめる、
ぴょんと祝おう、リファクタの朝。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PRタイトルは、HeaderTokyoMetroとHeaderTYの共通構造をHeaderEastに統合し、設定オブジェクトで差分を吸収するという主要な変更を正確に反映しており、簡潔で明確です。
Description check ✅ Passed PR説明には、変更の要旨、各コンポーネントの具体的な変更内容、テスト計画、および検証状況が明記されており、テンプレートの主要項目がカバーされています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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/refactor-east-theme-components

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

@TinyKitten TinyKitten self-assigned this Mar 27, 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: 2

🧹 Nitpick comments (3)
src/components/LineBoardEast.test.tsx (1)

207-218: テストのアサーションを強化することを検討してください。

このテストは ChevronTY が呼び出されたことのみを検証していますが、カスタム chevronColorPair (['ORANGE', 'BLUE']) が実際に渡されたかどうかを確認していません。デフォルト値のテスト(220-235行目)と同様に、color プロパティの値も検証した方がより堅牢なテストになります。

🔧 アサーションを強化する提案
   it('カスタムchevronColorPairでレンダリングされる', () => {
     const { ChevronTY } = require('./ChevronTY');
     render(
       <LineBoardEast
         stations={mockStations}
         lineColors={['#9acd32', '#9acd32']}
         hasTerminus={false}
         chevronColorPair={['ORANGE', 'BLUE']}
       />
     );
-    expect(ChevronTY).toHaveBeenCalled();
+    expect(ChevronTY).toHaveBeenCalledWith(
+      expect.objectContaining({
+        color: expect.stringMatching(/^(ORANGE|BLUE)$/),
+      }),
+      undefined
+    );
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/LineBoardEast.test.tsx` around lines 207 - 218, The test
currently only asserts that the mocked ChevronTY was called; update the test for
LineBoardEast (the 'カスタムchevronColorPairでレンダリングされる' case) to also assert that
ChevronTY received the expected color props derived from chevronColorPair
(['ORANGE','BLUE']). In the test locate the mocked ChevronTY (ChevronTY) and
inspect its last call/props (e.g., ChevronTY.mock.calls or
ChevronTY.mock.lastCall) and add assertions that the prop responsible for the
rendered color (the color or colors prop passed by LineBoardEast to ChevronTY)
equals the expected values for 'ORANGE' and 'BLUE', mirroring how the
default-value test (lines ~220-235) verifies color props.
src/components/TypeChangeNotify.test.tsx (1)

26-28: このテストではグラデーション周りの回帰を拾えません。

LinearGradient モックが colors を捨てていて、各ケースも「クラッシュしないこと」だけを見ています。今回の差分である EastBars の色計算やデフォルト分岐の差し替えが壊れても通ってしまうので、少なくとも 1 ケースは colors prop まで検証したいです。

Also applies to: 95-151

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

In `@src/components/TypeChangeNotify.test.tsx` around lines 26 - 28, The current
LinearGradient mock used in TypeChangeNotify.test.tsx swallows the colors prop
so gradient-related regressions (like color calc changes in EastBars and
default-branch swaps) aren't detected; update the mock to capture the colors
prop (e.g., make LinearGradient a jest.fn that returns children but stores its
last call props) and add at least one assertion in the existing tests to verify
the expected colors array for the EastBars rendering (or whichever test case
covers default branching), so the test fails if colors change unexpectedly.
src/components/HeaderTY.test.tsx (1)

138-143: 存在確認だけだと TY 固有の受け渡しは守れません。

TrainTypeBox モックが引数を捨てていて、ここも描画有無しか見ていないので、localTypePrefix="ty" や nextTrainTypeColor の受け渡しが外れても気づけません。今回の変更点なら呼び出し引数まで検証したいです。

Also applies to: 157-160

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

In `@src/components/HeaderTY.test.tsx` around lines 138 - 143, The current
TrainTypeBox mock (MockTrainTypeBox) discards its props so tests can't detect
TY-specific prop passing (e.g., localTypePrefix and nextTrainTypeColor); update
the jest.mock for TrainTypeBox so the mock component accepts props and either
(a) renders them into identifiable attributes/text (e.g., <View
testID="TrainTypeBox" accessibilityLabel={props.localTypePrefix} /* or include
color */ />) so existing render-based assertions can verify values, or (b)
replace the mock with a jest.fn wrapper that records calls and assert it was
called with the expected props (check/mock the component by name TrainTypeBox
and assert props.localTypePrefix === "ty" and props.nextTrainTypeColor matches
expected). Ensure both occurrences of the mock (the block around
MockTrainTypeBox and the similar block at lines noted in the review) are
changed.
🤖 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/HeaderEast/HeaderEast.tsx`:
- Around line 23-28: styles.gradientRoot に overflow: 'hidden' があるため tyConfig の
gradientRootExtraStyle に shadow を指定すると iOS で影がクリップされます。修正するには
gradientRootExtraStyle に shadow を入れる代わりに、影用スタイルを config.rootStyle(または新しい別 prop
例えば shadowStyle)に移動して styles.root にマージするように変更してください;対象となる識別子は gradientRoot,
gradientRootExtraStyle, styles.gradientRoot, styles.root, config.rootStyle(参考実装:
tokyoMetroConfig)です。

In `@src/components/TypeChangeNotify.tsx`:
- Around line 193-206: EastBars currently accepts getBarGradient/getBoxGradient
but is only used internally with fixed arguments, so expose these theme hooks on
the parent TypeChangeNotify: add optional props getBarGradient?: ColorGradientFn
and getBoxGradient?: ColorGradientFn to TypeChangeNotify (defaulting to
defaultBarGradient/defaultBoxGradient), then pass those props through when
rendering EastBars (and the other internal instance mentioned) so external
themes can inject gradients while preserving existing defaults (use the same
defaultBarGradient/defaultBoxGradient symbols).

---

Nitpick comments:
In `@src/components/HeaderTY.test.tsx`:
- Around line 138-143: The current TrainTypeBox mock (MockTrainTypeBox) discards
its props so tests can't detect TY-specific prop passing (e.g., localTypePrefix
and nextTrainTypeColor); update the jest.mock for TrainTypeBox so the mock
component accepts props and either (a) renders them into identifiable
attributes/text (e.g., <View testID="TrainTypeBox"
accessibilityLabel={props.localTypePrefix} /* or include color */ />) so
existing render-based assertions can verify values, or (b) replace the mock with
a jest.fn wrapper that records calls and assert it was called with the expected
props (check/mock the component by name TrainTypeBox and assert
props.localTypePrefix === "ty" and props.nextTrainTypeColor matches expected).
Ensure both occurrences of the mock (the block around MockTrainTypeBox and the
similar block at lines noted in the review) are changed.

In `@src/components/LineBoardEast.test.tsx`:
- Around line 207-218: The test currently only asserts that the mocked ChevronTY
was called; update the test for LineBoardEast (the
'カスタムchevronColorPairでレンダリングされる' case) to also assert that ChevronTY received
the expected color props derived from chevronColorPair (['ORANGE','BLUE']). In
the test locate the mocked ChevronTY (ChevronTY) and inspect its last call/props
(e.g., ChevronTY.mock.calls or ChevronTY.mock.lastCall) and add assertions that
the prop responsible for the rendered color (the color or colors prop passed by
LineBoardEast to ChevronTY) equals the expected values for 'ORANGE' and 'BLUE',
mirroring how the default-value test (lines ~220-235) verifies color props.

In `@src/components/TypeChangeNotify.test.tsx`:
- Around line 26-28: The current LinearGradient mock used in
TypeChangeNotify.test.tsx swallows the colors prop so gradient-related
regressions (like color calc changes in EastBars and default-branch swaps)
aren't detected; update the mock to capture the colors prop (e.g., make
LinearGradient a jest.fn that returns children but stores its last call props)
and add at least one assertion in the existing tests to verify the expected
colors array for the EastBars rendering (or whichever test case covers default
branching), so the test fails if colors change unexpectedly.
🪄 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: 75fc9531-806e-405d-92df-9d06b170c22d

📥 Commits

Reviewing files that changed from the base of the PR and between 25f13e6 and b91386b.

📒 Files selected for processing (13)
  • src/components/ChevronTY.tsx
  • src/components/HeaderEast/HeaderEast.test.tsx
  • src/components/HeaderEast/HeaderEast.tsx
  • src/components/HeaderEast/config.ts
  • src/components/HeaderEast/index.ts
  • src/components/HeaderTY.test.tsx
  • src/components/HeaderTY.tsx
  • src/components/HeaderTokyoMetro.tsx
  • src/components/LineBoardEast.test.tsx
  • src/components/LineBoardEast.tsx
  • src/components/TrainTypeBox.tsx
  • src/components/TypeChangeNotify.test.tsx
  • src/components/TypeChangeNotify.tsx

Comment thread src/components/TypeChangeNotify.tsx Resolved

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

🧹 Nitpick comments (1)
src/components/LineBoardEast.test.tsx (1)

207-240: アサーションをより厳密にすることを検討してください

useInterval がモックされており実際には発火しないため、chevronColor の初期値は常に chevronColorPair[1] になります(context snippet 1 参照)。正規表現によるマッチングだと、初期値として常に index 0 の値が使われるバグがあっても検出できません。

🔧 より厳密なアサーションの提案
  it('カスタムchevronColorPairでレンダリングされる', () => {
    const { ChevronTY } = require('./ChevronTY');
    render(
      <LineBoardEast
        stations={mockStations}
        lineColors={['#9acd32', '#9acd32']}
        hasTerminus={false}
        chevronColorPair={['ORANGE', 'BLUE']}
      />
    );
    expect(ChevronTY).toHaveBeenCalledWith(
      expect.objectContaining({
-        color: expect.stringMatching(/^(ORANGE|BLUE)$/),
+        color: 'BLUE', // 初期値は chevronColorPair[1]
      }),
      undefined
    );
  });

  it('chevronColorPair未指定時はデフォルトのRED/BLUEが使われる', () => {
    const { ChevronTY } = require('./ChevronTY');
    render(
      <LineBoardEast
        stations={mockStations}
        lineColors={['#9acd32', '#9acd32']}
        hasTerminus={false}
      />
    );
    expect(ChevronTY).toHaveBeenCalledWith(
      expect.objectContaining({
-        color: expect.stringMatching(/^(RED|BLUE)$/),
+        color: 'BLUE', // 初期値は chevronColorPair[1]
      }),
      undefined
    );
  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/LineBoardEast.test.tsx` around lines 207 - 240, The assertions
are too loose; because useInterval is mocked so chevronColor never advances, the
initial chevronColor is always chevronColorPair[1], so update the tests that
reference ChevronTY to assert the exact initial color: in the test using
chevronColorPair (LineBoardEast prop chevronColorPair), assert ChevronTY was
called with color strictly equal to the second element of that array
(chevronColorPair[1]); in the test without chevronColorPair, assert ChevronTY
was called with color strictly equal to the default second color (the default
BLUE used by LineBoardEast). Reference ChevronTY and the LineBoardEast prop
chevronColorPair when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/LineBoardEast.test.tsx`:
- Around line 207-240: The assertions are too loose; because useInterval is
mocked so chevronColor never advances, the initial chevronColor is always
chevronColorPair[1], so update the tests that reference ChevronTY to assert the
exact initial color: in the test using chevronColorPair (LineBoardEast prop
chevronColorPair), assert ChevronTY was called with color strictly equal to the
second element of that array (chevronColorPair[1]); in the test without
chevronColorPair, assert ChevronTY was called with color strictly equal to the
default second color (the default BLUE used by LineBoardEast). Reference
ChevronTY and the LineBoardEast prop chevronColorPair when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c85ed709-3d9e-497c-9606-07ef64c67d13

📥 Commits

Reviewing files that changed from the base of the PR and between b91386b and 702026b.

📒 Files selected for processing (5)
  • src/components/HeaderEast/config.ts
  • src/components/HeaderTY.test.tsx
  • src/components/HeaderTokyoMetro.test.tsx
  • src/components/LineBoardEast.test.tsx
  • src/components/TypeChangeNotify.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/TypeChangeNotify.tsx

@TinyKitten
TinyKitten merged commit 7b5adbb into dev Mar 27, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the feature/refactor-east-theme-components branch March 27, 2026 13:19
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