Skip to content

Commit

Permalink
Add 'fade_row_proc' condition to Table Component
Browse files Browse the repository at this point in the history
- Introduced a 'fade_row_proc' parameter to the table component to determine
if rows should be faded or not based on a condition.
- Updated YARD documentation for the `SolidusAdmin::UI::Table::Component` class
to include the new attribute.
  • Loading branch information
rainerdema committed Aug 23, 2023
1 parent 57bd09c commit 37cad8e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
id: 'orders-list',
model_class: Spree::Order,
rows: @page.records,
fade_row_proc: fade_row_proc,
search_key: SolidusAdmin::Config[:order_search_key],
search_url: solidus_admin.orders_path,
batch_actions: batch_actions,
Expand Down
10 changes: 9 additions & 1 deletion admin/app/components/solidus_admin/orders/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def initialize(
@feedback_component = feedback_component
end

class_attribute :fade_row_proc, default: ->(order) { order.paid? && order.shipped? }

def title
Spree::Order.model_name.human.pluralize
end
Expand Down Expand Up @@ -59,7 +61,13 @@ def number_column
{
header: :order,
data: ->(order) do
link_to order.number, spree.edit_admin_order_path(order)
order_path = spree.edit_admin_order_path(order)

if !fade_row_proc.call(order)
content_tag(:a, order.number, href: order_path, class: 'font-semibold')
else
link_to order.number, order_path
end
end
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

<tbody class="bg-white text-3.5 line-[150%] text-black">
<% @rows.each do |row| %>
<tr class="border-b border-gray-100">
<tr class="<%= row_class_for(row) %>">
<% @columns.each do |column| %>
<%= render_data_cell(column.data, row) %>
<% end %>
Expand Down
10 changes: 10 additions & 0 deletions admin/app/components/solidus_admin/ui/table/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SolidusAdmin::UI::Table::Component < SolidusAdmin::BaseComponent
# @param id [String] A unique identifier for the table component.
# @param model_class [ActiveModel::Translation] The model class used for translations.
# @param rows [Array] The collection of objects that will be passed to columns for display.
# @param fade_row_proc [Proc, nil] A proc determining if a row should have a faded appearance.
# @param search_key [Symbol] The key for searching.
# @param search_url [String] The base URL for searching.
#
Expand Down Expand Up @@ -38,6 +39,7 @@ def initialize(
rows:,
search_key:,
search_url:,
fade_row_proc: nil,
columns: [],
batch_actions: [],
filters: [],
Expand All @@ -55,6 +57,7 @@ def initialize(
@id = id
@model_class = model_class
@rows = rows
@fade_row_proc = fade_row_proc
@search_key = search_key
@search_url = search_url
@prev_page_link = prev_page_link
Expand Down Expand Up @@ -150,6 +153,13 @@ def render_data_cell(cell, data)
content_tag(:td, content_tag(:div, cell, class: "flex items-center gap-1.5"), class: "py-2 px-4 h-10 vertical-align-middle leading-none")
end

def row_class_for(row)
classes = ['border-b', 'border-gray-100']
classes << ['bg-gray-15', 'text-gray-700'] if @fade_row_proc&.call(row)

classes.join(' ')
end

Column = Struct.new(:header, :data, :class_name, keyword_init: true)
BatchAction = Struct.new(:display_name, :icon, :action, :method, keyword_init: true) # rubocop:disable Lint/StructNewOverride
Filter = Struct.new(:name, :value, :label, keyword_init: true)
Expand Down

0 comments on commit 37cad8e

Please sign in to comment.