Skip to content

Support Active Admin 4 - #9

Open
senid231 wants to merge 9 commits into
mainfrom
activeadmin-v4
Open

senid231 wants to merge 9 commits into
mainfrom
activeadmin-v4

Conversation

@senid231

@senid231 senid231 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Adds Active Admin 4 support while keeping Active Admin 3 behaviour unchanged. On v4 the gem crashed at boot, because it prepended ActiveAdmin::Filters::ViewHelper and ActiveAdmin::Filters::ActiveSidebar, and Active Admin 4 removed both.

Decisions the diff does not make obvious:

  • The v3 prepends now run only on v3. On v4 the gem prepends ActiveAdmin::FormHelper#active_admin_filters_form_for and wraps the if: of active_search_sidebar_section, so Current Filters still shows when only defaults apply.
  • The v4 filters section keeps Active Admin's own h3.filters-form-title and adds no second title. With active_admin_theme v4, the panel title is the only visible heading, because the theme hides .panel .filters-form-title.
  • The Active Admin 4 layout renders only the :error, :alert and :notice flash keys. On v4 the with: and require_any_filter warnings go to :alert; on v3 they still go to :warning. An arriving :alert wins.
  • New data-filter-extensions-form and data-filter-extensions-title hooks.
  • The gem ships no JS or CSS, so hosts load nothing new. The gemspec now allows < 5.0.0.a, so this is a minor release. The version is not bumped here.

Verified: full suite green on AA 3.5.2 (Rails 8.0) and AA 4.0.0.beta23 (Rails 8.0 and 8.1). CI adds 4.0.0.beta23 to the matrix.

Active Admin 4 removed Filters::ViewHelper and Filters::ActiveSidebar, so
those prepends now run only on v3. On v4 the gem hooks FormHelper and the
active_search section's condition, and sends warnings to :alert, the only
warning-like key the v4 layout renders.

Co-Authored-By: Clanker
Co-Authored-By: Clanker
Co-Authored-By: Clanker
@senid231 senid231 self-assigned this Nov 12, 2026
@senid231
senid231 requested a balanced review from Copilot November 12, 2026 10:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Both Ransack call sites omit Active Admin 4’s authorization object, causing context-dependent allowlists to reject permitted filters or silently leave searches unfiltered.

1 open issue
What changed in this PR

Adds Active Admin 4 compatibility to the filter extensions gem while preserving the Active Admin 3 integration.

Changes:

  • Selects version-specific form and sidebar hooks and warning flash keys.
  • Adds stable form/title data hooks and sidebar integration coverage.
  • Expands dependency support and CI coverage, with separate generated test apps per Active Admin major version.
File Description
tasks/​test.rake Separates generated test apps by Active Admin major version.
spec/​support/​rails_template.rb Adds a v4 test-app flash partial for custom keys.
spec/​rails_helper.rb Loads the version-specific test app.
spec/​integration/​with_spec.rb Checks the version-specific warning flash key.
spec/​integration/​sidebar_spec.rb Tests sidebar visibility, titles, and form hooks.
README.md Documents v4 support, flash behavior, and data hooks.
lib/​active_admin_filter_extensions/​policies.rb Uses version-specific warning flash keys.
lib/​active_admin_filter_extensions/​filters_form.rb Adds v4 sidebar integration and stable data hooks.
lib/​active_admin_filter_extensions.rb Selects integration modules by Active Admin version.
Gemfile Selects asset dependencies for each supported major version.
active_admin_filter_extensions.gemspec Expands the Active Admin dependency range to below v5.
.github/​workflows/​ci.yml Adds Active Admin 4 beta to the test matrix.

Review effort: Balanced

Comment thread active_admin_filter_extensions.gemspec Resolved
Active Admin 4 hands Ransack its authorization adapter, so a model's
ransackable_attributes can depend on the admin. Both of this gem's Ransack
calls dropped it, which could leave a permitted filter unapplied or fail
key derivation for a defaulted filter.

Co-Authored-By: Clanker
RubyGems treats 5.0.0.beta1 as satisfying "< 5".

Co-Authored-By: Clanker
On Active Admin 4 the warnings share :alert with the app's own messages, so an action's alert on the redirect was overwritten.

Co-Authored-By: Clanker

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The fallback can show an empty Current Filters section after a blank submission with defaults, and the flash-key test can pass even when the stock AA4 layout hides the warning.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Avoid showing default filters after a blank submission

lib/​active_admin_filter_extensions/​filters_form.rb:42

On v4, a blank submission such as /admin/string_posts?commit=Filter deliberately suppresses optional defaults and has no q, but filter_default_values still contains the configured default. This fallback therefore shows an empty Current Filters section on an unfiltered page. Check the effective filtering_params instead, and add a regression case for a blank submission on a resource with defaults.

Medium severity Test version-specific warning flash keys independently

spec/​integration/​with_spec.rb:51

The AA4 test app renders every flash key, and this assertion derives its expected key from the same helper that writes the warning. Returning :warning on AA4 would therefore still pass, although the stock layout would hide the warning. Assert the literal :alert key on v4 and :warning on v3 independently of warning_flash_key.

1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

On Active Admin 4, blank filter submissions incorrectly display the Current Filters panel, while the sidebar tests follow a redirect that prevents them from exercising the defaults-only behavior.

2 open issues

Review effort: Balanced

shown = section.options[:if]
section.options[:if] = lambda {
instance_exec(&shown) ||
(active_admin_config.current_filters_enabled? && filter_default_values.present?)
Comment on lines +18 to +24
visit "/admin/string_posts"

expect(page).to have_css(current_filters, text: "keep")
end

it "keeps the Current Filters panel off where the resource turned it off" do
visit "/admin/quiet_default_posts"
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