Skip to content

Add numeric_range filter input - #9121

Open
Fivell wants to merge 2 commits into
masterfrom
numeric-range-filter
Open

Fivell wants to merge 2 commits into
masterfrom
numeric-range-filter

Conversation

@Fivell

@Fivell Fivell commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Two commits:

Add numeric_range filter input — two number fields for the lower and upper
bound, the numeric counterpart of the existing :date_range. Opt-in via as:;
default_input_type is unchanged, so existing apps are unaffected.

filter :position, as: :numeric_range                       # 2 <= position <= 6
filter :position, as: :numeric_range, filters: [:gt, :lt]  # 2 <  position <  6

Note that filters: means something different here than on the string and
numeric inputs: there it is an unordered set of predicates for a dropdown, here
it is a positional [lower, upper] pair. Anything but exactly two raises
ArgumentError rather than silently producing a dead filter.

Add a decimal column to the test schema and cover it — the schema had no
:decimal or :float column anywhere, so step: any and the
when :integer, :float, :decimal branch of default_input_type had no coverage
against real decimal data. Adds stores.revenue and two specs.

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.12%. Comparing base (a1b7051) to head (6feaa23).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9121   +/-   ##
=======================================
  Coverage   99.11%   99.12%           
=======================================
  Files         139      140    +1     
  Lines        4071     4115   +44     
=======================================
+ Hits         4035     4079   +44     
  Misses         36       36           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Fivell

Fivell commented Sep 30, 2026

Copy link
Copy Markdown
Member Author
numeric-range-filter-decimals numeric-range-filter-sidebar

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The implementation is focused and well tested; only minor documentation wording remains.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds an explicit numeric range filter using inclusive Ransack bounds.

Changes:

  • Adds NumericRangeInput with configurable number fields.
  • Adds unit and feature coverage.
  • Documents the new filter type.
File Description
lib/​active_admin/​inputs/​filters/​numeric_range_input.rb Implements the range input.
lib/​active_admin/​inputs.rb Registers the input class.
spec/​helpers/​filter_form_helper_spec.rb Tests rendering and options.
features/​index/​filters.feature Tests end-to-end filtering.
features/​step_definitions/​filter_steps.rb Adds range-filter assertion.
features/​step_definitions/​factory_steps.rb Creates positioned test posts.
spec/​support/​templates_with_data/​admin/​posts.rb Configures a numeric range filter.
docs/​3-index-pages.md Documents the filter type.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/3-index-pages.md Resolved
@Fivell
Fivell force-pushed the numeric-range-filter branch 2 times, most recently from fde3d83 to 51739b6 Compare September 30, 2026 14:07
@Fivell
Fivell requested a balanced review from Copilot September 30, 2026 15:12

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The upper-bound field lacks a reliable accessible label, and the documentation examples misstate what the declarations configure.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
Resolved since last review (1)

Comment thread docs/3-index-pages.md Resolved
@Fivell
Fivell requested a balanced review from Copilot October 1, 2026 06:09
@Fivell Fivell changed the title WIP: Add numeric_range filter input Add numeric_range filter input Oct 1, 2026

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Custom labels are not reflected in the fields’ accessible names.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)

Comment on lines +64 to +66
def attribute_label
localized_label || humanized_method_name
end

@tagliala tagliala Oct 1, 2026 •

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.

Astra here — this specific finding is a false positive. The gemspec at the reviewed revision requires formtastic >= 6.0: 6.0 is the minimum, not an exclusive major-version constraint. Older Formtastic releases are outside this branch's supported range. I checked Formtastic 6.0.0, the minimum supported release, where localized_label already calls label_from_options:

def localized_label
  localized_string(method, label_from_options || method, :label)
end

I rendered the input at 6587a30 with label: "Rank" and checked the parsed HTML attributes, not just the visible label. The two inputs have aria-label="Rank From" and aria-label="Rank To", not “Position From/To”. A proc label also passes through ActiveAdmin's label_from_options override correctly. No extra call to label_from_options is needed for this case.

There is a separate double-escaping issue for labels containing ampersands/apostrophes, documented in this finding.

AI reviewer: openai-codex/gpt-6-astra · reasoning: high

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

One accessibility issue to fix: labels containing HTML-sensitive characters are double-escaped in the new aria-label attributes (inline example below).

I could not reproduce Copilot's outstanding label: "Rank" finding: Formtastic 6's localized_label already calls label_from_options, including ActiveAdmin's proc handling. Both a string label and a proc label rendered matching accessible names in an isolated check.

The same check reproduced the escaping defect with Formtastic 6.0.0 / Action View 8.1.3.1 / Ruby 4.0.7 at this commit; assertions comparing parsed input attributes with the visible label failed for Profit & Loss and Player's rank, while the plain-string/proc controls passed. Required CI is green; I did not rerun the full suite.

AI reviewer: openai-codex/gpt-6-astra · reasoning: high

input_html_options.merge(
id: dom_id_for(input_name),
placeholder: placeholder,
"aria-label": "#{attribute_label} #{placeholder}",

@tagliala tagliala Oct 1, 2026 •

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.

[P2] Avoid double-escaping the accessible label

localized_label returns HTML-escaped text by default. Interpolating it into a regular string here and passing it through number_field escapes it again. For example, filter :position, as: :numeric_range, label: "Profit & Loss" renders aria-label="Profit &amp;amp; Loss From"; after HTML parsing the accessible name is literally Profit &amp; Loss From, whereas the visible label is Profit & Loss. For an English apostrophe example, label: "Player's rank" renders aria-label="Player&amp;#39;s rank From", whose parsed value is literally Player&#39;s rank From. This affects both bounds and makes assistive technologies receive entity syntax rather than the displayed label.

Please derive a plain-text accessible label before Rails performs attribute escaping (or reference the visible label with aria-labelledby) and cover ampersands/apostrophes in a regression test. Do not mark the whole interpolated attribute HTML-safe, since attribute escaping must remain intact.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@tagliala thanks.

I could not avoid the escaping, so the fix undoes it. Localizer#localize escapes
unconditionally — String :label at line 64, i18n result at line 109 — and the only
switch, escape_html_entities_in_hints_and_labels, is global (form_builder.rb:33),
so flipping it would change every label in the gem.

def attribute_label
  CGI.unescapeHTML(localized_label || humanized_method_name)
end
label: visible announced
"Profit & Loss" Profit & Loss Profit & Loss From
"Bob's rank" Bob's rank Bob's rank From
proc { "A & B" } A & B A & B From

aria-labelledby would need extra hidden elements, since one label serves both
bounds. Rebuilding the name from a second lookup could drift from the visible label —
Formtastic also resolves the formtastic.labels.* scopes — and matching it is the
point. Not elegant, happy to switch if you see a cleaner seam. The attribute is not
marked html_safe.

Regression test covers both characters; reverting the fix fails it:

expected to find css "[aria-label=\"Bob's profit & loss From\"]" but there were no matches

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.

Astra here — @tagliala, the human maintainer, favored this compromise and asked me to challenge it. After inspecting the implementation and regression test, I agree on technical grounds, not simply because it was his preference. 🙂

This keeps Formtastic's label resolution intact, reverses its HTML escaping locally, and leaves Rails responsible for escaping the final attribute. It neither changes global configuration nor marks the attribute html_safe. The explanatory comment and regression test make the workaround clear and maintainable.

I would accept this approach rather than require extra markup or a parallel localization lookup just to avoid CGI.unescapeHTML. This is agreement with the implementation approach; verification of the updated revision remains separate from that judgment.

AI reviewer: openai-codex/gpt-6-astra · reasoning: high

@Fivell
Fivell force-pushed the numeric-range-filter branch 3 times, most recently from 8c5cfa2 to a51297f Compare October 1, 2026 07:24
@Fivell
Fivell requested a balanced review from Copilot October 1, 2026 07:30

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The implementation is scoped, backward-compatible, documented, and comprehensively tested.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@Fivell
Fivell force-pushed the numeric-range-filter branch from a51297f to 77be741 Compare October 1, 2026 07:34

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

AI reviewer: openai-codex/gpt-6-astra · reasoning: high

@Fivell
Fivell requested a review from javierjulio October 1, 2026 07:56
@Fivell
Fivell force-pushed the numeric-range-filter branch 3 times, most recently from 8f1ad82 to 2f88c76 Compare October 1, 2026 09:36
@Fivell

Fivell commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

rebasing to test agains ransack 5 merged to main

@Fivell
Fivell force-pushed the numeric-range-filter branch from 2f88c76 to 6feaa23 Compare October 1, 2026 09:45
@Fivell

Fivell commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

@javierjulio whats your opinion here?

This branch has not been deployed

No deployments
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