Skip to content

Fixes issue #2415 - Subcategories are not alphabetically ordered like Categories#2429

Open
HairyHook wants to merge 4 commits into
we-promise:mainfrom
HairyHook:fix-subcategory-ordering
Open

Fixes issue #2415 - Subcategories are not alphabetically ordered like Categories#2429
HairyHook wants to merge 4 commits into
we-promise:mainfrom
HairyHook:fix-subcategory-ordering

Conversation

@HairyHook

@HairyHook HairyHook commented Jun 21, 2026

Copy link
Copy Markdown

Details in #2415 (comment)

Fully tested the fix and the subcategories are now alphabetically ordered, following the same logic as Categories.

Summary by CodeRabbit

  • Bug Fixes
    • The category management interface in settings has been improved to display categories in hierarchical order instead of simple alphabetical order, providing better organization and easier navigation through your category structure.
    • Subcategories now consistently display in alphabetical order by name throughout the application, ensuring a more organized and predictable user experience.

First change required to fix subcategories not sorted alphabetically.

Signed-off-by: HairyHook <63165721+HairyHook@users.noreply.github.com>
Signed-off-by: HairyHook <63165721+HairyHook@users.noreply.github.com>
Signed-off-by: HairyHook <63165721+HairyHook@users.noreply.github.com>
@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

@coderabbitai

coderabbitai Bot commented Jun 21, 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: a66134a7-10a8-4828-bb08-4b119614df77

📥 Commits

Reviewing files that changed from the base of the PR and between fdcd0c7 and 571eace.

📒 Files selected for processing (2)
  • app/controllers/categories_controller.rb
  • app/models/category.rb

📝 Walkthrough

Walkthrough

The subcategories association on Category gains an explicit -> { order(:name) } scope. The CategoriesController#index action switches from alphabetically to alphabetically_by_hierarchy when building @categories.

Changes

Category Hierarchy Ordering

Layer / File(s) Summary
Subcategory ordering scope and controller index method
app/models/category.rb, app/controllers/categories_controller.rb
has_many :subcategories adds -> { order(:name) } to keep subcategories sorted by name; CategoriesController#index switches @categories assignment from alphabetically to alphabetically_by_hierarchy.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 Hippity-hop through the category tree,
Names now sorted for all to see!
Subcategories line up, neat in a row,
Hierarchy blooms wherever we go.
A tidy warren — what a lovely show! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: fixing alphabetical ordering of subcategories to match categories ordering, which directly corresponds to the modifications in both the controller and model files.
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 unit tests (beta)
  • Create PR with unit tests

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.

jjmata commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

The -> { order(:name) } default scope on has_many :subcategories is the right fix — any code that loads the association (outside the settings page) now gets alphabetically ordered subcategories consistently.

One thing to flag explicitly: the controller change from .alphabetically to .alphabetically_by_hierarchy does more than reorder subcategories — it changes the layout of the categories settings page from a flat alphabetical list to a grouped/hierarchical list (subcategories appear adjacent to their parent rather than in their own alphabetical position). For example, a subcategory "Alcohol" under "Food & Drink" would previously appear near the top of the list; it now appears under "Food & Drink."

That's probably the correct UX (and matches how the deletion confirmation page already renders categories), just confirming it's the intended behavior per issue #2415 rather than an accidental scope swap.


Generated by Claude Code

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.

2 participants