Skip to content

Feat/vote dropdown relative label#3447

Merged
KATO-Hiro merged 6 commits into
stagingfrom
feat/vote-dropdown-relative-label
Apr 23, 2026
Merged

Feat/vote dropdown relative label#3447
KATO-Hiro merged 6 commits into
stagingfrom
feat/vote-dropdown-relative-label

Conversation

@river0525
Copy link
Copy Markdown
Collaborator

@river0525 river0525 commented Apr 22, 2026

投票ドロップダウンの相対評価ラベルの実装です。

Summary by CodeRabbit

  • 新機能

    • グレード選択ドロップダウンに日本語の相対評価ラベルを追加。差分に応じた色付けとバッジ表示を導入。
  • Style

    • 非保留グレードのドロップダウン幅と項目間隔を拡張。ラベル領域とチェックアイコン表示を改善。
  • Refactor

    • 相対評価バッジの表示ロジックを整理し、色付けを共通化。
  • Tests

    • 相対評価ラベルと色付けの挙動を検証するテストを追加。

@river0525 river0525 requested a review from KATO-Hiro April 22, 2026 23:05
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c9a6fb9c-f8a5-4ffe-acda-a0bc3115cfa2

📥 Commits

Reviewing files that changed from the base of the PR and between 15a5929 and ad4f082.

📒 Files selected for processing (4)
  • src/features/votes/components/RelativeEvaluationBadge.svelte
  • src/features/votes/components/VotableGrade.svelte
  • src/features/votes/utils/relative_evaluation.test.ts
  • src/features/votes/utils/relative_evaluation.ts

📝 Walkthrough

Walkthrough

グレード選択ドロップダウンのレイアウトを調整し、確定済タスクの各選択肢に差分(-2〜+2)に基づく日本語の相対評価ラベルと色付けを追加。相対評価ユーティリティ群と対応テストを導入し、バッジ表示ロジックを簡素化した。

Changes

Cohort / File(s) Summary
相対評価ユーティリティ & テスト
src/features/votes/utils/relative_evaluation.ts, src/features/votes/utils/relative_evaluation.test.ts
差分を5段階表現へ変換する getRelativeEvaluationLabel、日本語ラベル getRelativeEvaluationJapaneseLabel、テキスト色 getRelativeEvaluationColorClass、バッジ色 getRelativeEvaluationBadgeColorClass を追加。境界・色付け挙動を検証するユニットテストを追加。
ドロップダウンUI改善
src/features/votes/components/VotableGrade.svelte
ドロップダウン幅拡大・各行を gap-2 レイアウトに変更し、選択肢右側に相対評価ラベルを表示(色は差分で切替)。チェックアイコンに shrink-0 を追加。
バッジ表示簡素化
src/features/votes/components/RelativeEvaluationBadge.svelte
差分を一度計算してラベルとバッジ色クラスを取得するように変更。従来のラベル先頭判定ロジックを削除してクラス注入に置換。

Sequence Diagram(s)

(該当なし)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

ドロップダウンに色が差し込む 🌈
差分が囁く、やさしい日本語で
バッジは一度だけ算出されて光る ✨
テストは静かに道筋を照らす — お疲れさま 🎐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトル「Feat/vote dropdown relative label」は、投票ドロップダウンに相対評価ラベルを実装するという主な変更内容を正確に反映しており、明確で具体的です。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ 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 feat/vote-dropdown-relative-label

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

投票ドロップダウン内で、公式グレードとの差分に応じた相対評価ラベル(日本語)を表示できるようにするPRです。

Changes:

  • 相対評価の差分(diff)を日本語ラベルへ変換するユーティリティ関数を追加
  • 追加関数のテストケースを追加
  • 投票ドロップダウンの各グレード行に相対評価ラベル表示とレイアウト調整を追加

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/features/votes/utils/relative_evaluation.ts diff→日本語ラベル変換関数を追加
src/features/votes/utils/relative_evaluation.test.ts 新規ユーティリティ関数のテストを追加
src/features/votes/components/VotableGrade.svelte ドロップダウン項目に相対評価ラベル列を追加し、幅/レイアウトを調整

Comment on lines +39 to +68
* Returns an empty string when the diff falls outside the expected ±2 range.
*
* | diff | label |
* | ---- | ------------ |
* | ≤ −3 | `''` |
* | −2 | `易しい` |
* | −1 | `やや易しい` |
* | 0 | `ふつう` |
* | +1 | `やや難しい` |
* | +2 | `難しい` |
* | ≥ +3 | `''` |
*
* @param diff - A grade difference (e.g., from {@link calcGradeDiff}).
* @returns The Japanese label string, or `''` if out of expected range.
*/
export function getRelativeEvaluationJapaneseLabel(diff: number): string {
switch (diff) {
case -2:
return '易しい';
case -1:
return 'やや易しい';
case 0:
return 'ふつう';
case 1:
return 'やや難しい';
case 2:
return '難しい';
default:
return '';
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRelativeEvaluationJapaneseLabel returns an empty string for diff <= -3 / diff >= 3, but calcGradeDiff can legitimately produce those values (e.g., Q11↔D6 is ±16) and this function is used in VotableGrade for every grade option. As a result, most dropdown items may show no relative label even though the existing relative-evaluation logic clamps to the extremes (e.g., getRelativeEvaluationLabel(16) => ++). Consider clamping here as well (e.g., treat diff <= -2 as '易しい' and diff >= 2 as '難しい') or derive the Japanese label from getRelativeEvaluationLabel(diff) to keep behavior consistent.

Suggested change
* Returns an empty string when the diff falls outside the expected ±2 range.
*
* | diff | label |
* | ---- | ------------ |
* | −3 | `''` |
* | −2 | `易しい` |
* | −1 | `やや易しい` |
* | 0 | `ふつう` |
* | +1 | `やや難しい` |
* | +2 | `難しい` |
* | +3 | `''` |
*
* @param diff - A grade difference (e.g., from {@link calcGradeDiff}).
* @returns The Japanese label string, or `''` if out of expected range.
*/
export function getRelativeEvaluationJapaneseLabel(diff: number): string {
switch (diff) {
case -2:
return '易しい';
case -1:
return 'やや易しい';
case 0:
return 'ふつう';
case 1:
return 'やや難しい';
case 2:
return '難しい';
default:
return '';
}
* Values outside the central ±1 range are clamped to the nearest extreme label.
*
* | diff | label |
* | ------ | ------------ |
* | −2 | `易しい` |
* | −1 | `やや易しい` |
* | 0 | `ふつう` |
* | +1 | `やや難しい` |
* | +2 | `難しい` |
*
* @param diff - A grade difference (e.g., from {@link calcGradeDiff}).
* @returns The Japanese label string.
*/
export function getRelativeEvaluationJapaneseLabel(diff: number): string {
if (diff <= -2) {
return '易しい';
}
if (diff === -1) {
return 'やや易しい';
}
if (diff === 0) {
return 'ふつう';
}
if (diff === 1) {
return 'やや難しい';
}
return '難しい';

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBグレードと中央値の差が±3より大きいとき、相対ラベルが付けられていない件の話ですね。
これに関しては意図的で、運営とユーザーのグレード乖離が±2を超えることは想定していないためです。
もちろん、投票自体は可能です。

@KATO-Hiro この件に関してはこのままでよろしいでしょうか?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かに正規分布にしたがうと仮定して±2σ相当と考えれば、大半のケースはカバーできていそうです。
このまま進めましょう。
実際の投票状況を確認して、必要に応じて軌道修正する方向で良さそうです。

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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/features/votes/components/VotableGrade.svelte`:
- Around line 219-231: The template in VotableGrade.svelte embeds nested ternary
color-class logic for diff; extract that mapping into a shared helper (e.g., add
getRelativeEvaluationColorClass(diff) in relative_evaluation.ts or utils) and
replace the inline ternary in VotableGrade.svelte (where calcGradeDiff and
getRelativeEvaluationJapaneseLabel are used) with a call to that helper; also
update RelativeEvaluationBadge to consume the same helper so both components use
one source of truth for color classes.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 06daf2e3-21cc-4a55-bc83-ebc78d9dc64e

📥 Commits

Reviewing files that changed from the base of the PR and between db69d06 and 15a5929.

📒 Files selected for processing (1)
  • src/features/votes/components/VotableGrade.svelte

Comment thread src/features/votes/components/VotableGrade.svelte
KATO-Hiro and others added 2 commits April 23, 2026 11:32
…badge

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@KATO-Hiro KATO-Hiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます
LGTMです

マージします

@KATO-Hiro KATO-Hiro merged commit 705baf6 into staging Apr 23, 2026
3 checks passed
@KATO-Hiro KATO-Hiro deleted the feat/vote-dropdown-relative-label branch April 23, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants