diff --git a/admin/app/components/solidus_admin/products/index/component.html.erb b/admin/app/components/solidus_admin/products/index/component.html.erb index 823f61b9cb4..dd65e354b21 100644 --- a/admin/app/components/solidus_admin/products/index/component.html.erb +++ b/admin/app/components/solidus_admin/products/index/component.html.erb @@ -20,39 +20,9 @@ rows: @page.records, search_key: SolidusAdmin::Config[:product_search_key], search_url: solidus_admin.products_path, - batch_actions: [ - { - display_name: t('.batch_actions.delete'), - action: solidus_admin.products_path, - method: :delete, - icon: 'delete-bin-7-line', - }, - { - display_name: t('.batch_actions.discontinue'), - action: solidus_admin.discontinue_products_path, - method: :put, - icon: 'pause-circle-line', - }, - { - display_name: t('.batch_actions.activate'), - action: solidus_admin.activate_products_path, - method: :put, - icon: 'play-circle-line', - }, - ], - columns: [ - { - class_name: "w-[72px]", - header: tag.span('aria-label': t('.product_image'), role: 'text'), - data: -> { image_column(_1) }, - }, - { header: :name, data: -> { name_column(_1) } }, - { header: :status, data: -> { status_column(_1) } }, - { header: :price, data: -> { price_column(_1) } }, - { header: :stock, data: -> { stock_column(_1) } } - ], - prev_page_link: prev_page_link, - next_page_link: next_page_link, - ) - %> + batch_actions: batch_actions, + columns: columns, + prev_page_link: prev_page_link, + next_page_link: next_page_link, + ) %> diff --git a/admin/app/components/solidus_admin/products/index/component.rb b/admin/app/components/solidus_admin/products/index/component.rb index 7622fb3d7ee..752faf623a5 100644 --- a/admin/app/components/solidus_admin/products/index/component.rb +++ b/admin/app/components/solidus_admin/products/index/component.rb @@ -24,47 +24,106 @@ def next_page_link @page.last? ? nil : solidus_admin.url_for(host: request.host, port: request.port, **request.params, page: @page.next_param) end - def image_column(product) - image = product.gallery.images.first or return + def batch_actions + [ + { + display_name: t('.batch_actions.delete'), + action: solidus_admin.products_path, + method: :delete, + icon: 'delete-bin-7-line', + }, + { + display_name: t('.batch_actions.discontinue'), + action: solidus_admin.discontinue_products_path, + method: :put, + icon: 'pause-circle-line', + }, + { + display_name: t('.batch_actions.activate'), + action: solidus_admin.activate_products_path, + method: :put, + icon: 'play-circle-line', + }, + ] + end - link_to( - image_tag(image.url(:small), class: 'h-10 w-10 max-w-min rounded border border-gray-100', alt: product.name), - spree.edit_admin_product_path(product), - class: 'inline-flex overflow-hidden', - tabindex: -1, - ) + def columns + [ + image_column, + name_column, + status_column, + price_column, + stock_column, + ] end - def name_column(product) - link_to product.name, spree.edit_admin_product_path(product) + def image_column + { + class_name: "w-[72px]", + header: tag.span('aria-label': t('.product_image'), role: 'text'), + data: ->(product) do + image = product.gallery.images.first or return + + link_to( + image_tag(image.url(:small), class: 'h-10 w-10 max-w-min rounded border border-gray-100', alt: product.name), + spree.edit_admin_product_path(product), + class: 'inline-flex overflow-hidden', + tabindex: -1, + ) + end + } end - def status_column(product) - if product.available? - @badge_component.new(name: t('.status.available'), color: :green) - else - @badge_component.new(name: t('.status.discontinued'), color: :red) - end + def name_column + { + header: :name, + data: ->(product) do + link_to product.name, spree.edit_admin_product_path(product) + end + } end - def stock_column(product) - stock_info = - case (on_hand = product.total_on_hand) - when Float::INFINITY - content_tag :span, t('.stock.in_stock', on_hand: t('.stock.infinity')), class: 'text-forest' - when 1..Float::INFINITY - content_tag :span, t('.stock.in_stock', on_hand: on_hand), class: 'text-forest' - else - content_tag :span, t('.stock.in_stock', on_hand: on_hand), class: 'text-red-500' + def status_column + { + header: :status, + data: ->(product) do + if product.available? + @badge_component.new(name: t('.status.available'), color: :green) + else + @badge_component.new(name: t('.status.discontinued'), color: :red) + end end + } + end + + def stock_column + { + header: :stock, + data: ->(product) do + stock_info = + case (on_hand = product.total_on_hand) + when Float::INFINITY + content_tag :span, t('.stock.in_stock', on_hand: t('.stock.infinity')), class: 'text-forest' + when 1..Float::INFINITY + content_tag :span, t('.stock.in_stock', on_hand: on_hand), class: 'text-forest' + else + content_tag :span, t('.stock.in_stock', on_hand: on_hand), class: 'text-red-500' + end - variant_info = - t('.for_variants', count: product.variants.count) + variant_info = + t('.for_variants', count: product.variants.count) - safe_join([stock_info, variant_info], ' ') + content_tag :div, safe_join([stock_info, variant_info], ' ') + end + } end - def price_column(product) - content_tag :div, product.master.display_price.to_html + def price_column + { + header: :price, + data: ->(product) do + content_tag :div, product.master.display_price.to_html + end + } end end diff --git a/admin/app/components/solidus_admin/ui/table/component.html.erb b/admin/app/components/solidus_admin/ui/table/component.html.erb index aef20f5c3da..ce90a4b607f 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -131,7 +131,7 @@ <% if @prev_page_link || @next_page_link %>