Skip to content

fix: order variable dropdowns by scale instead of alphabetically - #243

Merged
jackgranatowski merged 2 commits into
mainfrom
fix/variable-dropdown-scale-order
Aug 19, 2026
Merged

fix: order variable dropdowns by scale instead of alphabetically#243
jackgranatowski merged 2 commits into
mainfrom
fix/variable-dropdown-scale-order

Conversation

@jackgranatowski

@jackgranatowski jackgranatowski commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #232 — variables in the admin dropdowns are now grouped and ordered by their semantic scale instead of alphabetically.

Within each category, variables were sorted with a plain natural sort, so scale families came out in a lexicographic jumble — e.g. Spacing rendered as 2xl, 2xs, 3xl, l, m, s, xl, xs instead of small→large. This affected both integrations, since they share Slashed_Inventory::get_variables_by_category():

  • Bricks — entries are injected into the bricks_global_variables option, so the native Variable Manager picker renders in exactly that order.
  • Gutenberg — the same grouped list is passed to the editor token panel.

Change

  • Added a scale-aware comparator to Slashed_Category_Map:
    • scale_order() — rank table for the t-shirt scale (none, px, 2xs, xs, s, m, l, xl, 2xl, 3xl, 4xl …) plus edge keywords (base, full, max).
    • compare() / split_scale() — groups tokens by their "base" (name minus the trailing scale/numeric segment), orders scale members by rank, keeps numeric colour steps (50 … 950) numeric, and falls back to natural order for non-scale tokens so unrelated families stay grouped.
  • get_variables_by_category() now sorts each category with usort() using this comparator (replacing the two sort(..., SORT_NATURAL | SORT_FLAG_CASE) calls).

Result (real inventory)

  • Spacing: none, px, 2xs, xs, s, m, l, xl, 2xl, 3xl, 4xl …
  • Radius: none, 2xs, xs, s, m, l, xl, 2xl, 3xl, 4xl, full …
  • Colors (--sf-color-primary*): bare token → 50, 100, … 950 → variants

Tests

  • 5 new unit tests in tests-php/CategoryMapTest.php covering the t-shirt scale, edge/non-scale keywords, numeric colour steps, family grouping, and scale monotonicity.
  • Full PHP suite: 238 tests pass. PHPStan clean. PHPCS clean on the changed source files.

Notes

  • Fix is entirely server-side; no JS/Svelte or client rebuild needed.
  • scripts/gen-bricks-inventory.js still uses naturalCompare for the committed inventory.json fallback, but PHP re-sorts at runtime, so the dropdown order is fully corrected regardless.

Summary by CodeRabbit

  • Improvements

    • Variable names are now arranged in a more intuitive semantic order, including clothing sizes from smallest to largest.
    • Numeric variants are sorted numerically rather than alphabetically.
    • Related variable families remain grouped together, with non-scale entries placed after scale values.
  • Tests

    • Added coverage for size scales, numeric color steps, edge cases, and family grouping.

Variables grouped per category were sorted with a plain natural sort, so
scale families rendered in a lexicographic jumble (2xl, 2xs, 3xl, l, m, s,
xl, xs) instead of small->large. This affected both the Bricks variable
picker (injected into bricks_global_variables) and the Gutenberg token
panel, which share Slashed_Inventory::get_variables_by_category().

Add a scale-aware comparator to Slashed_Category_Map (scale_order() +
compare()/split_scale()) that groups tokens by base, orders the t-shirt
scale (none, px, 2xs, xs, s, m, l, xl, 2xl, 3xl, 4xl...) by rank, and keeps
numeric colour steps (50..950) numeric. get_variables_by_category() now
sorts each category with usort() using this comparator.

Fixes #232
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jackgranatowski, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: df47dd0b-61cb-4df0-987f-41eb96e6b8bc

📥 Commits

Reviewing files that changed from the base of the PR and between 3a515d6 and 452fcf5.

📒 Files selected for processing (2)
  • SLASHED-for-WP/includes/class-category-map.php
  • tests-php/CategoryMapTest.php

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f0339599-efc2-44c7-8397-24ba7f674a7d

📥 Commits

Reviewing files that changed from the base of the PR and between 0d88b88 and 3a515d6.

📒 Files selected for processing (3)
  • SLASHED-for-WP/includes/class-category-map.php
  • SLASHED-for-WP/includes/class-inventory.php
  • tests-php/CategoryMapTest.php

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds semantic ordering for scale and numeric variable suffixes. It groups related variable families and applies the new comparator to canonical and uncategorized inventory categories. PHPUnit tests cover scale, numeric, and family ordering.

Changes

Semantic variable ordering

Layer / File(s) Summary
Scale and numeric comparison
SLASHED-for-WP/includes/class-category-map.php, tests-php/CategoryMapTest.php
Slashed_Category_Map now ranks scale keywords, parses scale and numeric suffixes, and compares related variables semantically. Tests cover scale order, numeric steps, edge keywords, and family grouping.
Inventory ordering integration
SLASHED-for-WP/includes/class-inventory.php
Canonical and uncategorized inventory buckets now use Slashed_Category_Map::compare() instead of natural sorting. Documentation reflects the new ordering behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 3a515

This PR changes variable ordering to use semantic scale grouping and includes passing tests and static checks; no actionable merge-blocking risk remains.

Possibly related PRs

Suggested labels: codex

Suggested reviewers: claude

🚥 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 The title clearly summarizes the main change: semantic scale ordering for variable dropdowns.
Linked Issues check ✅ Passed The changes group related variables and order scale values semantically, satisfying issue #232.
Out of Scope Changes check ✅ Passed The comparator, inventory integration, and tests directly support the dropdown ordering objective with no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 fix/variable-dropdown-scale-order

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.

@coderabbitai coderabbitai Bot added the codex label Aug 19, 2026
@greptile-apps

greptile-apps Bot commented Aug 19, 2026

Copy link
Copy Markdown

Greptile Summary

The PR replaces natural sorting of inventory variables with a shared semantic comparator for the Bricks and Gutenberg dropdowns.

  • Adds ranked t-shirt-scale and numeric-step ordering to Slashed_Category_Map
  • Applies the comparator to categorized and fallback inventory buckets
  • Adds unit coverage for scale ordering, numeric colors, edge keywords, and family grouping

Confidence Score: 4/5

The PR should not merge until reserved suffixes are distinguished from identical words used by existing non-scale variables.

The comparator currently shortens and ranks every variable ending in a known keyword, causing real inventory entries such as --sf-color-base and --sf-duration-none to move away from their natural family positions.

Files Needing Attention: SLASHED-for-WP/includes/class-category-map.php

Important Files Changed

Filename Overview
SLASHED-for-WP/includes/class-category-map.php Adds the semantic comparator, but globally interpreting reserved suffixes misclassifies existing non-scale variables and changes their family ordering.
SLASHED-for-WP/includes/class-inventory.php Routes all inventory buckets through the new comparator, exposing its suffix classification behavior to both integrations.
tests-php/CategoryMapTest.php Covers intended scale behavior but omits non-scale variables whose final segment collides with reserved keywords.

Reviews (1): Last reviewed commit: "fix: order variable dropdowns by scale i..." | Re-trigger Greptile

Comment on lines +288 to +294
$scale = self::scale_order();
$key = strtolower( $suffix );
if ( isset( $scale[ $key ] ) ) {
return array(
'base' => $base,
'rank' => $scale[ $key ],
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Reserved suffixes misclassify tokens

When an existing non-scale variable ends in a reserved keyword, split_scale() unconditionally strips and ranks that suffix, causing entries such as --sf-color-base and --sf-duration-none to move away from their natural family positions in both integrations.

Addresses review feedback on the scale-ordering comparator. The first
version stripped a trailing scale keyword and re-based every variable,
which misclassified real tokens whose name merely contains a size-like
word: --sf-color-base (the colour "base" family) was reparsed as a size of
--sf-color and scattered from its own --sf-color-base-* steps, and
--sf-duration-none jumped to the front of the duration keywords.

Rework Slashed_Category_Map::compare() to walk names segment by segment,
classing each segment as scale size / numeric step / plain word, so sizes
order by rank, numbers numerically and everything else naturally. A name
that is a prefix of another (bare family token vs its steps) sorts first.
This is transitive (a strict weak ordering, unlike a mixed rank/string
compare) and keeps size-word-named families contiguous and in place.

Restrict scale_order() to unambiguous size keywords (px, 4xs…7xl) and drop
the ambiguous none/base/full/max so they stay beside their family. Add
regression tests for the --sf-color-base and --sf-duration-none cases.

Refs #232

Copy link
Copy Markdown
Contributor Author

Addressed the Greptile P1 (reserved suffixes misclassifying tokens) in 452fcf5.

Problem: the first comparator stripped a trailing scale keyword and re-based each variable, so tokens whose name merely contains a size-like word were misread as sizes:

  • --sf-color-base (the colour base family) was re-based to --sf-color and split from its own --sf-color-base-50 … -950 steps;
  • --sf-duration-none jumped to the front of the duration keywords.

Fix: Slashed_Category_Map::compare() now walks names segment by segment, classing each segment as scale-size / numeric-step / plain-word (sizes by rank, numbers numerically, the rest naturally). A name that is a prefix of another (a bare family token vs its numbered steps) sorts first. This is a proper transitive strict-weak-ordering — the earlier mixed rank/string approach could produce non-transitive comparisons that usort() does not tolerate. scale_order() is now restricted to unambiguous size keywords (px, 4xs…7xl); the ambiguous none/base/full/max were removed so they stay beside their family.

Verified on the real inventory:

  • --sf-color-base stays contiguous (base → 50 … 950 → variants) and in natural alphabetical position among the colour families;
  • --sf-duration-none keeps its natural spot (fast, instant, none, normal, slow, slower);
  • the t-shirt scales are still correct, e.g. Spacing px, 2xs, xs, s, m, l, xl, 2xl, 3xl, 4xl.

Added regression tests for both flagged cases. Full PHP suite: 240 passing; PHPStan clean; PHPCS clean on the changed source files.

@jackgranatowski
jackgranatowski merged commit b42edb5 into main Aug 19, 2026
9 checks passed
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.

variables in dropdowns in correct order

2 participants