diff --git a/admin/app/components/solidus_admin/orders/index/component.html.erb b/admin/app/components/solidus_admin/orders/index/component.html.erb index e423137d3e3..19617576018 100644 --- a/admin/app/components/solidus_admin/orders/index/component.html.erb +++ b/admin/app/components/solidus_admin/orders/index/component.html.erb @@ -19,7 +19,8 @@ id: 'orders-list', model_class: Spree::Order, rows: @page.records, - fade_row_proc: fade_row_proc, + row_fade: row_fade, + row_url: ->(order) { spree.edit_admin_order_path(order) }, search_key: SolidusAdmin::Config[:order_search_key], search_url: solidus_admin.orders_path, batch_actions: batch_actions, diff --git a/admin/app/components/solidus_admin/orders/index/component.rb b/admin/app/components/solidus_admin/orders/index/component.rb index 9cdaaad7eda..b24952b846e 100644 --- a/admin/app/components/solidus_admin/orders/index/component.rb +++ b/admin/app/components/solidus_admin/orders/index/component.rb @@ -5,7 +5,7 @@ def initialize(page:) @page = page end - class_attribute :fade_row_proc, default: ->(order) { order.paid? && order.shipped? } + class_attribute :row_fade, default: ->(order) { order.paid? && order.shipped? } def title Spree::Order.model_name.human.pluralize @@ -105,12 +105,10 @@ def number_column { header: :order, data: ->(order) do - order_path = spree.edit_admin_order_path(order) - - if !fade_row_proc.call(order) - link_to order.number, order_path, class: 'font-semibold' + if !row_fade.call(order) + content_tag :div, order.number, class: 'font-semibold' else - link_to order.number, order_path + content_tag :div, order.number end end } 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 d017f15316e..31310639e31 100644 --- a/admin/app/components/solidus_admin/products/index/component.html.erb +++ b/admin/app/components/solidus_admin/products/index/component.html.erb @@ -19,6 +19,7 @@ id: 'products-list', model_class: Spree::Product, rows: @page.records, + row_url: ->(product) { solidus_admin.product_path(product) }, search_key: SolidusAdmin::Config[:product_search_key], search_url: solidus_admin.products_path, batch_actions: batch_actions, diff --git a/admin/app/components/solidus_admin/products/index/component.rb b/admin/app/components/solidus_admin/products/index/component.rb index 87b9c0b7d49..b72e4ef13c3 100644 --- a/admin/app/components/solidus_admin/products/index/component.rb +++ b/admin/app/components/solidus_admin/products/index/component.rb @@ -74,11 +74,11 @@ def image_column data: ->(product) do image = product.gallery.images.first or return - link_to( - render(component('ui/thumbnail').new(src: image.url(:small), alt: product.name)), - solidus_admin.product_path(product), - class: 'inline-flex overflow-hidden', - tabindex: -1, + render( + component('ui/thumbnail').new( + src: image.url(:small), + alt: product.name + ) ) end } @@ -88,7 +88,7 @@ def name_column { header: :name, data: ->(product) do - link_to product.name, solidus_admin.product_path(product) + content_tag :div, product.name 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 6f1b78dfb74..df6f1474c89 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -116,8 +116,9 @@ <% @rows.each do |row| %> <% @columns.each do |column| %> <%= render_data_cell(column.data, row) %> diff --git a/admin/app/components/solidus_admin/ui/table/component.js b/admin/app/components/solidus_admin/ui/table/component.js index ac0bee5b795..6a517b13972 100644 --- a/admin/app/components/solidus_admin/ui/table/component.js +++ b/admin/app/components/solidus_admin/ui/table/component.js @@ -82,14 +82,29 @@ export default class extends Controller { if (event.target.closest('a') || event.target.tagName === 'BUTTON' || event.target.type === 'checkbox') return const row = event.currentTarget + + if (this.modeValue === 'batch') { + this.toggleCheckbox(row) + } else { + this.navigateToRow(row) + } + } + + toggleCheckbox(row) { const checkbox = this.checkboxTargets.find(selection => row.contains(selection)) if (checkbox) { - checkbox.checked = !checkbox.checked - this.selectRow() + checkbox.checked = !checkbox.checked + this.selectRow() } } + navigateToRow(row) { + const url = row.dataset.primaryUrl + + if (url) window.location.href = url + } + render() { const selectedRows = this.checkboxTargets.filter((checkbox) => checkbox.checked) diff --git a/admin/app/components/solidus_admin/ui/table/component.rb b/admin/app/components/solidus_admin/ui/table/component.rb index a850c423f68..83df04be06e 100644 --- a/admin/app/components/solidus_admin/ui/table/component.rb +++ b/admin/app/components/solidus_admin/ui/table/component.rb @@ -4,7 +4,8 @@ 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 row_fade [Proc, nil] A proc determining if a row should have a faded appearance. + # @param row_url [Proc, nil] A proc that takes a row object as a parameter and returns the URL to navigate to when the row is clicked. # @param search_param [Symbol] The param for searching. # @param search_key [Symbol] The key for searching. # @param search_url [String] The base URL for searching. @@ -36,7 +37,8 @@ def initialize( model_class:, rows:, search_key:, search_url:, search_param: :q, - fade_row_proc: nil, + row_fade: nil, + row_url: nil, columns: [], batch_actions: [], filters: [], @@ -49,7 +51,8 @@ def initialize( @id = id @model_class = model_class @rows = rows - @fade_row_proc = fade_row_proc + @row_fade = row_fade + @row_url = row_url @search_param = search_param @search_key = search_key @search_url = search_url diff --git a/admin/spec/features/products_spec.rb b/admin/spec/features/products_spec.rb index b85ca2255af..0a4cf7a6424 100644 --- a/admin/spec/features/products_spec.rb +++ b/admin/spec/features/products_spec.rb @@ -14,7 +14,7 @@ expect(page).to have_content("$19.99") expect(page).to be_axe_clean - click_on "Just a product" + find('table tbody tr', text: 'Just a product').click expect(page).to have_current_path("/admin/products/just-a-prod") expect(page).to have_content("Manage images")