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

Chore/admin semantic table rows #5950

Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def name_column
{
header: :name,
data: ->(option_type) do
content_tag :div, option_type.name
link_to option_type.name, row_url(option_type), class: "underline cursor-pointer"
end
}
end
Expand All @@ -64,7 +64,7 @@ def presentation_column
{
header: :presentation,
data: ->(option_type) do
content_tag :div, option_type.presentation
link_to option_type.presentation, row_url(option_type), class: "underline cursor-pointer"
end
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def number_column
header: :order,
data: ->(order) do
if !row_fade(order)
content_tag :div, order.number, class: 'font-semibold'
link_to order.number, row_url(order), class: "font-semibold underline cursor-pointer"
else
content_tag :div, order.number
link_to order.number, row_url(order), class: "underline cursor-pointer"
end
end
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ def columns
{
header: :name,
data: ->(payment_method) do
content_tag :div, payment_method.name
link_to payment_method.name, row_url(payment_method), class: "underline cursor-pointer"
end
},
{
header: :type,
data: ->(payment_method) do
content_tag :div, payment_method.model_name.human
link_to payment_method.model_name.human, row_url(payment_method), class: "underline cursor-pointer"
end
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def name_column
{
header: :name,
data: ->(product) do
content_tag :div, product.name
link_to product.name, row_url(product), class: "underline cursor-pointer"
end
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def name_column
{
header: :name,
data: ->(property) do
content_tag :div, property.name
link_to property.name, row_url(property), class: "underline cursor-pointer"
end
}
end
Expand All @@ -57,7 +57,7 @@ def presentation_column
{
header: :presentation,
data: ->(property) do
content_tag :div, property.presentation
link_to property.presentation, row_url(property), class: "underline cursor-pointer"
end
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ def search_key

def columns
[
:name,
{
header: :name,
data: ->(reimbursement_type) do
reimbursement_type.name
end
},
{
header: :active,
data: ->(reimbursement_type) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def name_column
{
header: :name,
data: ->(stock_item) do
content_tag :div, stock_item.variant.name
link_to stock_item.variant.name, row_url(stock_item), class: "underline cursor-pointer"
end
}
end
Expand All @@ -99,7 +99,7 @@ def sku_column
{
header: :sku,
data: ->(stock_item) do
content_tag :div, stock_item.variant.sku
link_to stock_item.variant.sku, row_url(stock_item), class: "underline cursor-pointer"
end
}
end
Expand All @@ -122,7 +122,9 @@ def variant_column
def stock_location_column
{
header: :stock_location,
data: ->(stock_item) { stock_item.stock_location.name },
data: ->(stock_item) do
content_tag :div, stock_item.stock_location.name
end
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def columns
{
header: :slug,
data: ->(store) do
content_tag :div, store.code
link_to store.code, row_url(store), class: "underline cursor-pointer"
end
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def name_column
{
header: :name,
data: ->(taxonomy) do
content_tag :div, taxonomy.name
link_to taxonomy.name, row_url(taxonomy), class: "underline cursor-pointer"
end
}
end
Expand Down
10 changes: 3 additions & 7 deletions admin/app/components/solidus_admin/ui/table/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,11 @@
>
<% @data.rows.each do |row| %>
<tr
class="border-b border-gray-100 last:border-0 hover:bg-gray-50 cursor-pointer <%= 'bg-gray-15 text-gray-700' if @data.fade&.call(row) %>"
<% if @data.url %>
data-action="click-><%= stimulus_id %>#rowClicked"
data-<%= stimulus_id %>-url-param="<%= @data.url.call(row) %>"
<%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %>
<% end %>
class="border-b border-gray-100 last:border-0 hover:bg-gray-50 <%= 'bg-gray-15 text-gray-700' if @data.fade&.call(row) %>"
<%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %>
>
<% @data.columns.each do |column| %>
<%= render_data_cell(column, row) %>
<%= render_data_cell(column, row, @data.url&.call(row)) %>
MadelineCollier marked this conversation as resolved.
Show resolved Hide resolved
<% end %>
</tr>
<% end %>
Expand Down
12 changes: 1 addition & 11 deletions admin/app/components/solidus_admin/ui/table/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,11 @@ export default class extends Controller {
}

rowClicked(event) {
// If the user clicked on a link, button, input or summary, skip the row url visit
// Skip if the user clicked on a link, button, input or summary
if (event.target.closest("td").contains(event.target.closest("a,select,textarea,button,input,summary"))) return

if (this.modeValue === "batch") {
this.toggleCheckbox(event.currentTarget)
} else {
const url = new URL(event.params.url, "http://dummy.com")
const params = new URLSearchParams(url.search)
const frameId = params.get('_turbo_frame')
const frame = frameId ? { frame: frameId } : {}
// remove the custom _turbo_frame param from url search:
params.delete('_turbo_frame')
url.search = params.toString()

window.Turbo.visit(url.pathname + url.search, frame)
}
}

Expand Down
4 changes: 2 additions & 2 deletions admin/app/components/solidus_admin/ui/table/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def render_header_cell(cell, **attrs)
}, **attrs)
end

def render_data_cell(column, data)
def render_data_cell(column, data, url = nil)
cell = column.data
cell = cell.call(data) if cell.respond_to?(:call)
cell = data.public_send(cell) if cell.is_a?(Symbol)
cell = link_to data.public_send(cell), url, class: "underline cursor-pointer" 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-x-hidden") if column.wrap

Expand Down
12 changes: 9 additions & 3 deletions admin/app/components/solidus_admin/users/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,21 @@ def columns
},
{
header: :order_count,
data: ->(user) { user.order_count },
data: ->(user) do
content_tag :div, user.order_count
end
},
{
header: :lifetime_value,
data: -> { _1.display_lifetime_value.to_html },
data: ->(user) do
content_tag :div, user.display_lifetime_value.to_html
end
},
{
header: :last_active,
data: ->(user) { last_login(user) },
data: ->(user) do
content_tag :div, last_login(user)
end
},
]
end
Expand Down
4 changes: 2 additions & 2 deletions admin/app/components/solidus_admin/users/items/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def number_column
col: { class: "w-[18%]" },
header: t(".number_column_header"),
data: ->(item) do
content_tag :div, item.order.number, class: "font-semibold text-sm"
link_to item.order.number, row_url(item.order), class: "underline cursor-pointer font-semibold text-sm"
end
}
end
Expand All @@ -164,7 +164,7 @@ def item_name_with_variant_and_sku(item)

# The `.html_safe` is required for the description to display as desired.
# rubocop:disable Rails/OutputSafety
safe_join([content_tag(:div, content.join("<br>").html_safe, class: "text-sm")])
safe_join([link_to(content.join("<br>").html_safe, row_url(item.order), class: "underline cursor-pointer text-sm")])
# rubocop:enable Rails/OutputSafety
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def number_column
header: :order,
data: ->(order) do
if !row_fade(order)
content_tag :div, order.number, class: 'font-semibold'
link_to order.number, row_url(order), class: "font-semibold underline cursor-pointer"
else
content_tag :div, order.number
link_to order.number, row_url(order), class: "underline cursor-pointer"
end
end
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ def columns
header: :credited,
col: { class: "w-[12%]" },
data: ->(store_credit) do
content_tag :div, store_credit.display_amount.to_html, class: "text-sm"
link_to store_credit.display_amount.to_html, row_url(store_credit), class: "text-sm underline cursor-pointer"
end
},
{
header: :authorized,
col: { class: "w-[13%]" },
data: ->(store_credit) do
content_tag :div, store_credit.display_amount_authorized.to_html, class: "text-sm"
link_to store_credit.display_amount_authorized.to_html, row_url(store_credit), class: "text-sm underline cursor-pointer"
end
},
{
header: :used,
col: { class: "w-[9%]" },
data: ->(store_credit) do
content_tag :div, store_credit.display_amount_used.to_html, class: "text-sm"
link_to store_credit.display_amount_used.to_html, row_url(store_credit), class: "text-sm underline cursor-pointer"
end
},
{
Expand All @@ -90,9 +90,7 @@ def columns
{
header: :issued_on,
col: { class: "w-[16%]" },
data: ->(store_credit) do
I18n.l(store_credit.created_at.to_date)
end
data: ->(store_credit) { I18n.l(store_credit.created_at.to_date) }
},
{
header: :invalidated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ def update
@stock_item.stock_movements.build(quantity: quantity_adjustment, originator: current_solidus_admin_user)

if @stock_item.save
binding.pry
respond_to do |format|
format.html { redirect_to solidus_admin.stock_items_path, status: :see_other }
format.turbo_stream { render turbo_stream: '<turbo-stream action="refresh" />' }
end
else
binding.pry
respond_to do |format|
format.html { render component('stock_items/edit').new(stock_item: @stock_item, page: @page), status: :unprocessable_entity }
end
Expand Down
2 changes: 1 addition & 1 deletion admin/spec/features/adjustment_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
before do
Spree::AdjustmentReason.create(name: "Good Reason", code: 5999)
visit "/admin/adjustment_reasons#{query}"
find_row("Good Reason").click
within("table tbody") { click_on "Good Reason" }
expect(page).to have_content("Edit Adjustment Reason")
expect(page).to be_axe_clean
end
Expand Down
2 changes: 1 addition & 1 deletion admin/spec/features/refund_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
before do
Spree::RefundReason.create(name: "Return process")
visit "/admin/refund_reasons#{query}"
find_row("Return process").click
within("table tbody") { click_on "Return process" }
expect(page).to have_content("Edit Refund Reason")
expect(page).to be_axe_clean
end
Expand Down
2 changes: 1 addition & 1 deletion admin/spec/features/return_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
before do
Spree::ReturnReason.create(name: "Good Reason")
visit "/admin/return_reasons#{query}"
find_row("Good Reason").click
within("table tbody") { click_on "Good Reason" }
expect(page).to have_content("Edit Return Reason")
expect(page).to be_axe_clean
end
Expand Down
2 changes: 1 addition & 1 deletion admin/spec/features/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
before do
Spree::Role.create(name: "Reviewer", permission_sets: [settings_edit_permission])
visit "/admin/roles#{query}"
find_row("Reviewer").click
within("table tbody") { click_on "Reviewer" }
expect(page).to have_content("Edit Role")
expect(page).to be_axe_clean
expect(Spree::Role.find_by(name: "Reviewer").permission_set_ids)
Expand Down
2 changes: 1 addition & 1 deletion admin/spec/features/shipping_categories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
before do
Spree::ShippingCategory.create(name: "Letter Mail")
visit "/admin/shipping_categories#{query}"
find_row("Letter Mail").click
within("table tbody") { click_on "Letter Mail" }
expect(page).to have_content("Edit Shipping Category")
expect(page).to be_axe_clean
end
Expand Down
1 change: 1 addition & 0 deletions admin/spec/features/stock_items_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'spec_helper'
require 'pry'

describe "Stock Items", :js, type: :feature do
before { sign_in create(:admin_user, email: '[email protected]') }
Expand Down
3 changes: 2 additions & 1 deletion admin/spec/features/store_credit_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
before do
Spree::StoreCreditReason.create(name: "New Customer Reward")
visit "/admin/store_credit_reasons#{query}"
find_row("New Customer Reward").click
within("table tbody") { click_on "New Customer Reward" }

expect(page).to have_content("Edit Store Credit Reason")
expect(page).to be_axe_clean
end
Expand Down
Loading