Add admin-only color override for group subquestions and MC options#5017
Add admin-only color override for group subquestions and MC options#5017aseckin wants to merge 1 commit into
Conversation
Admins (is_superuser) can now set an explicit color per group subquestion and per multiple-choice option in the Create/Edit Question forms, via a small palette swatch picker next to the Subquestion Label field and at the end of each Choices row. - New nullable Question fields: label_color (palette key for group subquestions) and options_colors (dict of option label -> palette key for MC), exposed in read/write serializers with light validation. - Colors are stored as keys of METAC_COLORS["mc-option"] so light/dark theme variants keep working. - Override applied at the choices.ts choke point with fallback to the existing index-based color scale, so all timelines, legends and cards inherit it; unset/unknown keys behave exactly as before. - Option colors keyed by label survive reorders; renames via the admin update-options handler carry the color along. - MC colors stay editable even when options are locked by forecasts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🚀 Preview EnvironmentYour preview environment is ready!
Details
ℹ️ Preview Environment InfoIsolation:
Limitations:
Cleanup:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
front_end/src/app/(main)/questions/components/group_form.tsx (1)
821-826: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAvoid directly mutating the state object.
React state should be treated as immutable. While mutating the object directly and returning it in a new array will trigger a re-render in this component, it can lead to subtle bugs in memoized child components or hooks that rely on referential equality.
Consider returning a cloned object instead.
♻️ Proposed refactor
subQuestions.map((subQuestion, iter_index) => { if (index === iter_index) { - subQuestion["label_color"] = key; + return { ...subQuestion, label_color: key }; } return subQuestion; })🤖 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 `@front_end/src/app/`(main)/questions/components/group_form.tsx around lines 821 - 826, Update the subQuestions mapping in the group form so the item matching iter_index is replaced with a cloned object containing the new label_color, rather than mutating subQuestion directly. Return unchanged subQuestion objects for all other entries and preserve the existing array update behavior.
🤖 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 `@front_end/src/app/`(main)/questions/components/color_picker.tsx:
- Around line 51-66: Add an accessible name to each color swatch button in the
color-picker rendering by deriving a descriptive label from the color/key, and
apply that value to both aria-label and title. Keep the existing selection,
styling, and click behavior unchanged.
---
Nitpick comments:
In `@front_end/src/app/`(main)/questions/components/group_form.tsx:
- Around line 821-826: Update the subQuestions mapping in the group form so the
item matching iter_index is replaced with a cloned object containing the new
label_color, rather than mutating subQuestion directly. Return unchanged
subQuestion objects for all other entries and preserve the existing array update
behavior.
🪄 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: CHILL
Plan: Pro
Run ID: ae2a469d-ac8c-4840-a350-6d5bf50f4d94
📒 Files selected for processing (16)
front_end/messages/cs.jsonfront_end/messages/en.jsonfront_end/messages/es.jsonfront_end/messages/pt.jsonfront_end/messages/zh-TW.jsonfront_end/messages/zh.jsonfront_end/src/app/(main)/questions/components/color_picker.tsxfront_end/src/app/(main)/questions/components/group_form.tsxfront_end/src/app/(main)/questions/components/question_form.tsxfront_end/src/constants/colors.tsfront_end/src/types/question.tsfront_end/src/utils/questions/choices.tsquestions/migrations/0038_question_label_color_question_options_colors.pyquestions/models.pyquestions/serializers/common.pyquestions/services/multiple_choice_handlers.py
Adds an admin-only (
is_superuser) color picker to the Create/Edit Question forms, letting admins override the default index-based colors for question group subquestions and multiple choice options.colorpicker.mp4
UI
mc-optionpalette colors + a reset-to-default cell.Backend
Questionfields + migration:label_color(palette key, group subquestions) andoptions_colors(dict of option label → palette key, MC), exposed in read/write serializers with light shape validation.multiple_choice_rename_option) carry the color along; dict keyed by label is unaffected by reorders.Rendering
METAC_COLORS["mc-option"]palette keys, so light/dark theme variants keep working.generateChoiceItemsFromMultipleChoiceForecast/generateChoiceItemsFromGroupQuestionsinchoices.ts) with fallback to the existing index-based scale — all timelines, legends, and feed/consumer cards inherit it. Unset or unknown keys behave exactly as before.Notes
🤖 Generated with Claude Code
Summary by CodeRabbit