Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[admin] Update the admin preview toggle label #5515

Merged
merged 15 commits into from
Nov 22, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Allow to opt-out of cell-wrapping in ui/table
Also changes how `<col>` attributes are provided.
elia committed Nov 22, 2023
commit bf0c4314deb321e733161b43b5a4b4c51b3f04e1
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ def date_column

def customer_column
{
class_name: "w-[400px]",
col: { class: "w-[400px]" },
header: :customer,
data: ->(order) do
customer_email = order.user&.email
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ def columns

def image_column
{
class_name: "w-[72px]",
col: { class: "w-[72px]" },
header: tag.span('aria-label': t('.product_image'), role: 'text'),
data: ->(product) do
image = product.gallery.images.first or return
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@
<table class="table-fixed w-full border-collapse">
<colgroup>
<% @columns.each do |column| %>
<col class="<%= column.class_name %>">
<col <%= tag.attributes(**column.col) if column.col %>">
<% end %>
</colgroup>

@@ -117,7 +117,7 @@
<% end %>
>
<% @columns.each do |column| %>
<%= render_data_cell(column.data, row) %>
<%= render_data_cell(column, row) %>
<% end %>
</tr>
<% end %>
21 changes: 10 additions & 11 deletions admin/app/components/solidus_admin/ui/table/component.rb
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ def initialize(
prev_page_link: nil,
next_page_link: nil
)
@columns = columns.map { Column.new(**_1) }
@columns = columns.map { Column.new(wrap: true, **_1) }
@batch_actions = batch_actions.map { BatchAction.new(**_1) }
@filters = filters.map { Filter.new(**_1) }
@id = id
@@ -86,7 +86,7 @@ def selectable_column
"aria-label": t('.select_row'),
)
},
class_name: 'w-[52px]',
col: { class: 'w-[52px]' },
)
end

@@ -148,21 +148,20 @@ def render_header_cell(cell, **attrs)
}, **attrs)
end

def render_data_cell(cell, data)
def render_data_cell(column, data)
cell = column.data
cell = cell.call(data) if cell.respond_to?(:call)
cell = data.public_send(cell) if cell.is_a?(Symbol)
cell = cell.render_in(self) if cell.respond_to?(:render_in)
cell = tag.div(cell, class: "flex items-center gap-1.5 justify-start overflow-hidden") if column.wrap

tag.td(
tag.div(cell, class: "flex items-center gap-1.5"),
class: "
py-2 px-4 h-10 vertical-align-middle leading-none
[tr:last-child_&:first-child]:rounded-bl-lg [tr:last-child_&:last-child]:rounded-br-lg
",
)
tag.td(cell, class: "
py-2 px-4 h-10 vertical-align-middle leading-none
[tr:last-child_&:first-child]:rounded-bl-lg [tr:last-child_&:last-child]:rounded-br-lg
")
end

Column = Struct.new(:header, :data, :class_name, keyword_init: true)
Column = Struct.new(:header, :data, :col, :wrap, keyword_init: true)
BatchAction = Struct.new(:display_name, :icon, :action, :method, keyword_init: true) # rubocop:disable Lint/StructNewOverride
Filter = Struct.new(:presentation, :combinator, :attribute, :predicate, :options, keyword_init: true)
private_constant :Column, :BatchAction, :Filter