Module: Studio::AdminModelsTableHelper

Defined in:
app/helpers/studio/admin_models_table_helper.rb

Overview

Shared shell for /admin/models tables. Renders the overflow wrapper + thead + tbody + empty state so each consumer ‘_<key>_table` partial only declares its columns. Exposed to consumer admin/models views via the AdminModels concern.

<%= admin_model_table(records, key: "users", min_width: 760,
      headers: ["User", "Role", "Created"], empty: "No users found.") do |user| %>
  <td class="px-4 py-3"><%= user.display_name %></td>
  <td class="px-4 py-3"><%= user.role %></td>
  <td class="px-4 py-3"><%= time_ago_in_words(user.created_at) %> ago</td>
<% end %>

The block yields each record and returns that row’s <td> cells. Output matches the long-standing markup (id=“models-<key>-table”, overflow wrapper, hover rows, colspan empty state) so existing view assertions keep passing.

Instance Method Summary collapse

Instance Method Details

#admin_model_table(records, key:, headers:, min_width: 940, empty: "No records found.", &row) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/studio/admin_models_table_helper.rb', line 19

def admin_model_table(records, key:, headers:, min_width: 940, empty: "No records found.", &row)
  header_row = (:tr, safe_join(headers.map { |label|
    (:th, label, class: "px-4 py-3 text-left font-semibold")
  }))

  body =
    if records.any?
      safe_join(records.map { |record|
        (:tr, capture(record, &row), class: "hover:bg-surface-alt/60 transition")
      })
    else
      (:tr, (:td, empty,
        colspan: headers.size, class: "px-4 py-10 text-center text-muted"))
    end

  table = (:table,
    (:thead, header_row, class: "bg-surface-alt text-muted text-xs uppercase tracking-wide") +
      (:tbody, body, class: "divide-y divide-subtle"),
    id: "models-#{key}-table", class: "w-full min-w-[#{min_width}px] text-sm")

  (:div, table, class: "overflow-x-auto")
end