Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ group :development, :test do
gem 'rspec-expectations'
# Drives the dummy app in the tests of active_admin_theme/page_objects. Not on
# RubyGems yet, so pinned to its tag.
gem 'active_admin_page_objects', github: 'activeadmin-plugins/active_admin_page_objects', tag: 'v2.0.0.beta1'
gem 'active_admin_page_objects', github: 'activeadmin-plugins/active_admin_page_objects', tag: 'v2.0.0.beta2'
# Tests the searchable select with its None and Present filter options. Not on RubyGems, so pinned to its tag.
gem 'active_admin_filter_extensions', github: 'activeadmin-plugins/active_admin_filter_extensions', tag: 'v1.3.0'
end
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Theme 4 needs ActiveAdmin 4 (`>= 4.0.0.beta23`) and Ruby 3.3 or newer. To upgrad

| ActiveAdmin | Theme | Install | Docs |
| --- | --- | --- | --- |
| 4 | 4.0.0.beta2 | `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta2"` | this README |
| 4 | 4.0.0.beta3 | `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta3"` | this README |
| 3 | 3.3.0, maintained on the [`3.x`](https://github.com/activeadmin-plugins/active_admin_theme/tree/3.x) branch | `gem "active_admin_theme", "~> 3.3"` (RubyGems) | [v3.3.0 README](https://github.com/activeadmin-plugins/active_admin_theme/blob/v3.3.0/README.md) |

## Screenshots
Expand Down Expand Up @@ -41,7 +41,7 @@ Pages of the demo app in `test/dummy`. `bundle exec rake screenshots` regenerate
Theme 4 is in beta and not on RubyGems yet, so install it from its GitHub tag:

```ruby
gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta2"
gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta3"
```

The gem requires `active_admin` first, so its views and partials win over ActiveAdmin's own. Do not reorder that.
Expand Down Expand Up @@ -496,6 +496,35 @@ end

`group_headings:` on the sidebar decides whether each group gets a heading and its own list. The default, `:auto`, shows headings only when there is more than one group and more than five links, so a short sidebar stays one plain list. `true` always shows them and `false` never does; without headings the links form one list in the order they were declared. A group whose links are all left out disappears with them. The titles are "Related records" and "External links", from `active_admin_theme.sidebars.related_records` and `.external_links`, or from `title:`.

### Sticky table header

From 768px up, the first header row of an index table stays under the top bar while the page scrolls. To turn it off everywhere, set this in an initializer:

```ruby
ActiveAdminTheme.sticky_table_header = false
```

To turn it off for one index, add the `skip-sticky-headers` class:

```ruby
index do |table|
table.add_class "skip-sticky-headers"
# columns
end
```

A table outside a panel or a tab opts in with the `with-sticky-headers` class, as in v3. A panel or a tab scrolls sideways on its own, so the class does nothing there.

### Row click

A click on an index row ticks its batch checkbox, as in ActiveAdmin 4, and a row with a checked box is highlighted. The click also highlights the row and column of the cell. To keep the v3 behavior, where the click only highlights, set this in an initializer:

```ruby
ActiveAdminTheme.row_click_selects = false
```

The setting needs the `active_admin_theme/table_crisscross` script, which is on by default.

### Sticky first column

Add the `with-sticky-rows` class to a wide table, and its first column stays in place while the table scrolls sideways:
Expand Down Expand Up @@ -752,6 +781,7 @@ The sections of active_admin_page_objects then work on theme pages. Their README

- `main_menu` is the top menu on desktop and the drawer on a narrow screen, at any depth. `labels`, `has_item?` and `go` take a label path, and `current_labels` returns one. `click` hovers each parent of the top menu; in the drawer it opens the drawer and each collapsed parent first.
- `ActiveAdminPageObjects::Tabs` drives the theme's `tabs`. Every page has it as `tabs`. `select`, `content`, `has_tab?` and `has_selected?` take a String, the whole title ignoring case, or a Regexp. `select_matching` is `select` for a Regexp.
- `comments.add` works when the comments sit in a tab, even a nested one: after the page reloads, it selects each tab around them. This needs active_admin_page_objects 2.0.0.beta2 or newer.
- `form.field(name)` and `filters.filter(name)` return the searchable select classes for an input rendered `as: :searchable_select`. The theme registers them for that wrapper class with `register_field_class` and `register_filter_class`, so a page object that declares the base gem's `SelectField` or `SelectFilter` for such an input raises `DeclaredClassMismatch`.
- `flashes` also takes `:warning`. The theme renders every flash type, while ActiveAdmin 4 drops all but `notice`, `alert` and `error`. For another type your app sets, call `ActiveAdminTheme::PageObjects.register_flash_type(:info)` in your spec helper; an unregistered type still raises `ArgumentError`.
- `attributes_table.secret(key)` and `row.secret(key)` return the cell's `SecretReveal`. `has_secret_mask?(key, mask = nil)`, `has_secret_value?(key, value)` and their `has_no_` forms wait as Capybara does.
Expand Down
11 changes: 7 additions & 4 deletions app/javascript/active_admin_theme/table_crisscross.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// column with data-selected, so a value in a wide table is easy to trace to its
// headers. The clicked cell gets data-selected-cell.
//
// ActiveAdmin ticks a row's checkbox when any cell is clicked; the handler
// clicks it again to undo that, so highlighting never leaves rows selected for
// batch actions.
// ActiveAdmin ticks a row's checkbox when any cell is clicked. When
// ActiveAdminTheme.row_click_selects is false, the handler clicks it again to
// undo that, so highlighting never leaves rows selected for batch actions.
const MARK = "data-selected"
const CENTER = "data-selected-cell"

Expand All @@ -21,7 +21,7 @@ document.addEventListener("click", (event) => {

// ActiveAdmin's row toggler has already handled this click; revert it.
const checkbox = row.querySelector("input[type=checkbox]")
if (checkbox) checkbox.click()
if (checkbox && !cell.closest("[data-aat-row-click-selects]")) checkbox.click()

clear(table)
const index = cell.cellIndex
Expand All @@ -36,4 +36,7 @@ document.addEventListener("click", (event) => {
document.addEventListener("change", (event) => {
const toggleAll = event.target.closest(".batch-actions-toggle-all")
if (toggleAll) clear(toggleAll.closest("table"))
// ActiveAdmin sets a row's selected class only from the select-all box.
const checkbox = event.target.closest(".batch-actions-resource-selection")
checkbox?.closest("tr")?.classList.toggle("selected", checkbox.checked)
})
44 changes: 41 additions & 3 deletions app/tailwind/active_admin_theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,37 @@
.data-table :where(tbody > tr):hover > td {
background-color: var(--aat-surface-hover);
}
.data-table :where(tbody > tr.selected) > td {
/* ActiveAdmin 4 marks rows selected only from the select-all box, so a
* checked batch checkbox marks its own row. */
.data-table :where(tbody > tr.selected, tbody > tr:has(.batch-actions-resource-selection:checked)) > td {
background-color: var(--aat-selected-row);
}
/* A wide index table widens the page, and the window scrolls sideways, as in
* v3. The main column takes the table's width, and the bars around the
* content stay at the viewport width. layout.js sets --aat-viewport-width,
* which leaves out a classic scrollbar. Below 768px the table scrolls in its
* wrapper. */
* which leaves out a classic scrollbar. A sticky bar is a stacking context:
* the title bar sits above the flashes, the page content and its sticky
* header row, so its dropdowns take clicks over them, and below #site-header.
* Below 768px the table scrolls in its wrapper. */
@media (width >= 48rem) {
:has(> [data-aat-page] .index-as-table) {
min-width: fit-content;
}
:has(> [data-aat-page] .index-as-table) > :not([data-aat-page], #main-menu, script) {
position: sticky;
inset-inline-start: 0;
z-index: 10;
width: var(--aat-viewport-width, 100vw);
}
:has(> [data-aat-page] .index-as-table) > #page-header {
z-index: 20;
}
/* An open confirm_dialog's backdrop is a child of body at z-index 40, so
* the title bar gives up its stacking context while the dialog is open. */
:has(> [data-aat-page] .index-as-table) > #page-header:has(.aat-confirm-modal:not(.hidden)) {
position: relative;
z-index: auto;
}
[data-aat-page][data-aat-has-sidebar]:not([data-aat-sidebar-collapsed]):has(.index-as-table) {
grid-template-columns: 270px minmax(min-content, 1fr);
}
Expand All @@ -206,6 +220,30 @@
.aat-tab-panel:has(> .data-table) {
overflow-x: auto;
}
/* The first header row of an index table stays under the top bar while the
* page scrolls (ActiveAdminTheme.sticky_table_header). As in v3, an index
* opts out with skip-sticky-headers and another table opts in with
* with-sticky-headers, except in a panel or a tab, which scrolls on its own.
* A shadow draws the bottom line, which a sticky cell's collapsed border
* would leave behind. Below 768px the table scrolls in its wrapper, which a
* sticky header cannot leave. */
@media (width >= 48rem) {
[data-aat-sticky-thead] .index-as-table > .data-table:not(.skip-sticky-headers) > thead > tr:first-child > th,
table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table) > thead > tr:first-child > th {
position: sticky;
top: var(--aa-header-height);
z-index: 2;
box-shadow: inset 0 -1px 0 var(--aat-border);
}
table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table) > thead > tr:first-child > th {
background-color: var(--aat-table-header);
}
:is([data-aat-sticky-thead] .index-as-table > .data-table:not(.skip-sticky-headers), table.with-sticky-headers:not(:is(.panel-body, .aat-tab-panel) table)).with-sticky-rows > thead > tr:first-child > th:first-child {
z-index: 3;
box-shadow: inset -1px 0 0 var(--aat-border), inset 0 -1px 0 var(--aat-border);
}
}

/* Opt-in sticky first column. Body cells keep the stripe, hover and selected fills above. */
table.with-sticky-rows :is(td, th):first-child {
position: sticky;
Expand Down
2 changes: 1 addition & 1 deletion app/views/active_admin/_page_content.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= active_admin_theme_config_tag %>
<% has_sidebar = !(skip_sidebar? || sidebar_sections_for_action.blank?) %>
<div data-test-page-content data-aat-page <%= "data-aat-has-sidebar" if has_sidebar %> class="px-2.5 md:px-4 grid grid-cols-1 gap-3 md:gap-4 md:data-aat-has-sidebar:grid-cols-[270px_minmax(0,1fr)] md:data-aat-sidebar-collapsed:grid-cols-1">
<div data-test-page-content data-aat-page <%= "data-aat-has-sidebar" if has_sidebar %> <%= "data-aat-sticky-thead" if ActiveAdminTheme.sticky_table_header %> <%= "data-aat-row-click-selects" if ActiveAdminTheme.row_click_selects %> class="px-2.5 md:px-4 grid grid-cols-1 gap-3 md:gap-4 md:data-aat-has-sidebar:grid-cols-[270px_minmax(0,1fr)] md:data-aat-sidebar-collapsed:grid-cols-1">
<%= render "active_admin/sidebar" %>
<div class="relative min-w-0">
<% if has_sidebar %>
Expand Down
4 changes: 2 additions & 2 deletions docs/migrating-from-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Upgrade ActiveAdmin first, and follow ActiveAdmin's own [upgrade guide](https://

## Checklist

1. In the `Gemfile`, set `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta2"` (the beta is not on RubyGems) and `activeadmin` to 4.0.0.beta23 or newer. Ruby 3.3 or newer is required.
1. In the `Gemfile`, set `gem "active_admin_theme", github: "activeadmin-plugins/active_admin_theme", tag: "v4.0.0.beta3"` (the beta is not on RubyGems) and `activeadmin` to 4.0.0.beta23 or newer. Ruby 3.3 or newer is required.
2. Remove the theme 3 lines from your stylesheet and script manifests:
- `@import "wigu/active_admin_theme";` and any `$skin*` variable assignments
- `//= require wigu/all` (or the individual `wigu/*` files)
Expand Down Expand Up @@ -57,7 +57,7 @@ ActiveAdmin 4 dropped menus deeper than one submenu level, but the theme keeps t
- The theme loads as ES modules through `ActiveAdmin.importmap`, not through Sprockets. A pin in your own `config/importmap.rb` does not load on ActiveAdmin pages; pin your scripts into `ActiveAdmin.importmap` (README, "JavaScript").
- `theme_toggle.js` is rewritten as `active_admin_theme/theme_toggle`. The header switch cycles auto, light and dark, and keeps ActiveAdmin 4's `theme` key in `localStorage`, so a choice made in theme 3 is not carried over.
- `scrollbar_width.js` is gone. The header no longer uses `100vw`, so it is not needed.
- `table_crisscross.js` is rewritten without jQuery as `active_admin_theme/table_crisscross`, and loads by default. The `td.selected` marker is now `td[data-selected]`.
- `table_crisscross.js` is rewritten without jQuery as `active_admin_theme/table_crisscross`, and loads by default. The `td.selected` marker is now `td[data-selected]`. A cell click now also ticks the row's batch checkbox; `ActiveAdminTheme.row_click_selects = false` restores the v3 behavior.
- `server_clock.js` is rewritten as `active_admin_theme/server_clock`. It reads `data-servertime-epoch` and `data-servertime-zone` from `[data-server-clock]`; the old `data-servertime` wall-clock format is not supported.

## DSL
Expand Down
15 changes: 14 additions & 1 deletion lib/active_admin_theme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class << self
# Page size of a searchable_select_options endpoint that declares no per_page:. Nil means 50.
attr_accessor :searchable_select_per_page

attr_writer :javascripts, :searchable_select_all, :searchable_select_min_chars
attr_writer :javascripts, :searchable_select_all, :searchable_select_min_chars, :sticky_table_header,
:row_click_selects
# nil keeps ActiveAdmin's "Powered by" footer; any of the three replaces it.
# footer_extra and site_title_link are a String, or a Proc run in the view.
# site_title_link false or nil leaves the title as plain text.
Expand All @@ -51,6 +52,18 @@ def searchable_select_all
@searchable_select_all.nil? ? true : @searchable_select_all
end

# True when the header row of an index table stays under the top bar while
# the page scrolls, from 768px up. False turns it off.
def sticky_table_header
@sticky_table_header.nil? ? true : @sticky_table_header
end

# True when a click on an index row ticks its batch checkbox, as in
# ActiveAdmin 4. False keeps the v3 behavior: the click only highlights.
def row_click_selects
@row_click_selects.nil? ? true : @row_click_selects
end

# Characters to type before a searchable select asks its endpoint.
def searchable_select_min_chars
@searchable_select_min_chars || 3
Expand Down
25 changes: 25 additions & 0 deletions lib/active_admin_theme/page_objects/tabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,29 @@ def tab_button(title)
end
end

module ActiveAdminTheme
module PageObjects
# Prepended to ActiveAdminPageObjects::Comments. Comments placed in a tab
# are hidden while another tab is selected, so Comments#add selects every
# tab around them after it reloads the page. Shown comments need nothing.
module CommentsPatch
TAB_PANELS_XPATH = "ancestor::*[@role='tabpanel']".freeze

private

def reveal_comments(panel)
return if panel.visible?

# Outermost first: a nested tab's button is hidden until its parent tab shows.
panel.all(:xpath, TAB_PANELS_XPATH, visible: :all, wait: false).each do |tab_panel|
next if tab_panel.visible?

panel.session.find(:css, "[role='tab'][aria-controls='#{tab_panel[:id]}']").click
end
end
end
end
end

ActiveAdminPageObjects::Tabs.prepend(ActiveAdminTheme::PageObjects::TabsPatch)
ActiveAdminPageObjects::Comments.prepend(ActiveAdminTheme::PageObjects::CommentsPatch)
2 changes: 1 addition & 1 deletion lib/active_admin_theme/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveAdminTheme
VERSION = "4.0.0.beta2"
VERSION = "4.0.0.beta3"
end
40 changes: 40 additions & 0 deletions test/dummy/app/admin/menu_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# An index with an action-item dropdown whose items hang over the table
# toolbar, which the batch actions render, a confirm dialog, and a table in a cell
# (test/layout_test.rb).
ActiveAdmin.register Order, as: "MenuOrder" do
menu false
config.batch_actions = true

filter :status, as: :select, collection: Order::STATUSES

# ?flash=1 shows flash messages under the title bar.
controller do
before_action(only: :index) do
flash.now[:notice] = "Export queued" if params[:flash]
flash.now[:alert] = "Another export is running" if params[:flash]
end
end

action_item :new_export, only: :index do
dropdown_menu_tag "New export", id: "new-export" do
item "CSV", "/admin/dropdown_menu/echo?to=csv"
item "XML", "/admin/dropdown_menu/echo?to=xml"
item "JSON", "/admin/dropdown_menu/echo?to=json"
item "PDF", "/admin/dropdown_menu/echo?to=pdf"
end
end

action_item :purge, only: :index do
confirm_dialog_tag "Purge exports", id: "purge-exports", title: "Purge exports?", url: "/admin/confirm_dialog/echo",
class: "action-item-button"
end

index do
selectable_column
id_column
column :reference
column :status
# A table in a cell keeps its own header: only the index header sticks.
column("Lines") { |order| table_for [order.reference], class: "nested-lines" do column("Line") { |line| line } end }
end
end
22 changes: 22 additions & 0 deletions test/dummy/app/admin/tabs_demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@
end
end
end

# Comments markup in a tab of a nested tab, for the page objects' reveal_comments
# (test/page_objects_components_test.rb). The dummy has no comments table.
ActiveAdmin.register_page "Tabbed comments" do
menu false

content do
tabs do
tab("Details") { para "Details" }
tab("History") do
tabs do
tab("Changes") { para "Changes" }
tab("Notes") do
div id: "active-admin-comments-form" do
para "A comment", class: "tabbed-comment"
end
end
end
end
end
end
end
12 changes: 9 additions & 3 deletions test/dummy/app/admin/wide_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@
"<tr>" + row.map { |cell| "<td>#{ERB::Util.html_escape(cell)}</td>" }.join + "</tr>"
end.join
text_node(
# with-sticky-headers: the one place in the repo's test surface where
# the sticky-thead selector matches a real element (AA's own index
# tables need a database-backed resource the dummy doesn't have).
# with-sticky-headers does nothing in a panel: the header scrolls away
# (test/layout_test.rb).
(%(<table class="index_table with-sticky-headers wide-demo">) + head + "<tbody>" + body + "</tbody></table>")
.html_safe
)
end

panel "A table_for with with-sticky-headers, which a panel ignores" do
table_for (1..30).to_a, class: "with-sticky-headers", id: "sticky-table-for" do
column("Row") { |n| "Row #{n}" }
column("Value") { |n| "Value #{n}" }
end
end
end
end
Loading
Loading