Skip to content

Support Active Admin 4 with a vanilla JavaScript rewrite - #24

Open
senid231 wants to merge 7 commits into
masterfrom
activeadmin-v4
Open

senid231 wants to merge 7 commits into
masterfrom
activeadmin-v4

Conversation

@senid231

@senid231 senid231 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Makes the plugin run on Active Admin 3 and 4 from one plain JavaScript file with no jQuery. Active Admin 4 has no jQuery or Sprockets, so the old plugin did not load there.

Decisions

  • One file, no duplicated logic: vendor/assets/javascripts/active_admin_date_range_preset.js is a classic script with no imports or exports. Sprockets loads it through the existing //= require. On v4 the engine pins it into ActiveAdmin.importmap, and an ES module with no exports runs the same code. Both expose window.ActiveAdminDateRangePreset (init, defaults).
  • On v4, hosts import the module with javascript_import_module_tag in an _html_head override, or via ActiveAdminTheme.javascripts. When javascript_modules (Add javascript_modules setting to import modules on every page activeadmin/activeadmin#9148) exists, the gem registers itself. CSS is now plain CSS with .dark support. Hosts link it with stylesheet_link_tag (Propshaft serves it) or @import it into their Tailwind entry.
  • The value format follows input.type: YYYY-MM-DD for date, YYYY-MM-DDTHH:MM for datetime-local, unchanged for text inputs. This matches active_admin_datetimepicker#97 (div.filter_date_time_range).
  • A .datetime_preset_pair wrapper holding both inputs fills its own first and last input.
  • New hooks: data-date-range-preset-toggle, -menu, data-date-range-preset="<key>".

Release impact: major (1.0.0). $.fn.date_range_ext_preset is removed. README and CHANGELOG show the replacement, including show_time.

Verified: full suite on AA 3.2/Rails 8.1, 3.5/8.0, 4.0.0.beta23/8.0 and 8.1, all green.

Ransack 6 raises when ransackable_associations is undefined, which
failed every filter page in the suite.

Co-Authored-By: Clanker
One classic script with no imports or exports, so Sprockets and an
import map can both load it. $.fn.date_range_ext_preset becomes
ActiveAdminDateRangePreset.init and .defaults; options keep their names.
Native date and datetime-local inputs get the ISO value their type needs.

Co-Authored-By: Clanker
The engine pins the module into ActiveAdmin.importmap. The suite now
also runs on Active Admin 4.0.0.beta23 with a Tailwind build that
imports the gem's CSS.

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

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

Automatic initialization can ignore host-configured defaults, while opening and selecting presets fails to manage keyboard focus correctly.

No open issues 🎉

What changed in this PR

Adds Active Admin 4 support while retaining Active Admin 3 compatibility through one dependency-free JavaScript implementation.

Changes:

  • Replaces the jQuery API with ActiveAdminDateRangePreset.init and adds import-map integration.
  • Supports native date inputs, two-input wrappers, dark mode, and data-attribute hooks.
  • Updates migration guidance, browser coverage, and CI for both Active Admin generations.
File Description
vendor/​assets/​stylesheets/​active_admin_date_range_preset.scss Removes the Sass stylesheet.
vendor/​assets/​stylesheets/​active_admin_date_range_preset.css Adds plain CSS with dark-mode styling.
vendor/​assets/​javascripts/​active_admin_date_range_preset.js Rewrites the plugin without jQuery.
spec/​week_boundaries_spec.rb Uses cross-version filter helpers.
spec/​support/​tailwind.rb Builds test styles for Active Admin 4.
spec/​support/​rails_template.rb Configures version-specific test-app assets.
spec/​support/​page_helpers.rb Shares cross-version selectors and input helpers.
spec/​support/​browser_time.rb Updates comments about clock-read timing.
spec/​support/​admin.rb Adds range-wrapper and native-picker fixtures.
spec/​spec_helper.rb Loads the new test support modules.
spec/​popup_binding_spec.rb Updates selectors for both versions.
spec/​per_element_options_spec.rb Uses the replacement initialization API.
spec/​outside_click_spec.rb Uses cross-version filter controls.
spec/​native_inputs_spec.rb Tests native formats, hooks, and dark mode.
spec/​link_placement_spec.rb Uses the shared filter selector.
spec/​init_once_spec.rb Tests reinitialization through the new API.
spec/​datetimepicker_markup_spec.rb Tests datetimepicker-style range markup.
spec/​date_range_preset_spec.rb Adds two-input wrapper coverage.
README.md Documents installation, migration, and usage.
package.json Points the style entry to plain CSS.
lib/​active_admin_date_range_preset.rb Adds Active Admin 4 module registration.
Gemfile Selects version-specific asset dependencies.
config/​importmap.rb Declares the JavaScript module pin.
CHANGELOG.md Records breaking changes and new capabilities.
active_admin_date_range_preset.gemspec Allows Active Admin 4 dependencies.
.github/​workflows/​ci.yml Adds Active Admin 4 to the CI matrix.

Review effort: Balanced

On Active Admin 4 the module's auto-init runs before a host module that
imports it, so defaults set there never reached auto-initialised pairs.

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

Co-Authored-By: Clanker
With date_to_human_readable the end is 23:59:59, and cutting it to 23:59
dropped the last minute from an inclusive lteq filter. Seconds are only
written when the input's step permits them, since the default 60-second
step rejects such a value and blocks the submit.

Co-Authored-By: Clanker
Only a .datetime_preset_pair looks for its end input in the next
sibling again, as before the rewrite, so init() on any other element
cannot write into an unrelated field. Tabbing out closes the menu,
ArrowUp with no preset focused starts at the bottom, a replaced
defaults object and jQuery input options are honoured, and the npm
build puts the CSS where package.json's style field points.

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 date-range preset can generate values that violate native input step constraints and block submission, while suppressed compiler stderr hides the cause of pre-suite build failures.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve compiler stderr when the Tailwind build fails

spec/​support/​tailwind.rb:34

Redirecting the compiler's stderr to File::NULL discards the diagnostic explaining a failed build. Since this runs before the suite, CI then stops with only tailwindcss build failed, hiding the missing import, CSS error, or other cause. Please preserve stderr or capture it and include it in the exception.

Review effort: Balanced

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