Skip to content

Commit

Permalink
Use semantic UI elements in admin table rows
Browse files Browse the repository at this point in the history
All over the new admin we use divs or simply text to display the
resource and rely on a complex Stimulus click event handler to open the
edit route. This is not semantic at all and makes it necessary to use a
fully JS enabled browser under all circumstances to test the new admin
interface which leads to flaky and slow tests.

We should use links instead and probably remove the stimulus click event
handler. Also, links are not visually highlighted, which leads to a11y
issues. So, this commit adds underlines to links in table rows.

solidusio#5944
  • Loading branch information
MadelineCollier committed Nov 27, 2024
1 parent c560453 commit eb8b834
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 33 deletions.
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
4 changes: 2 additions & 2 deletions admin/app/components/solidus_admin/orders/index/component.rb
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 @@ -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
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
4 changes: 2 additions & 2 deletions admin/app/components/solidus_admin/users/orders/component.rb
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 @@ -40,7 +40,7 @@ def name_column
{
header: :name,
data: ->(promotion_category) do
content_tag :div, promotion_category.name
content_tag :a, promotion_category.name, href: row_url(promotion_category)
end
}
end
Expand All @@ -49,7 +49,7 @@ def code_column
{
header: :code,
data: ->(promotion_category) do
content_tag :div, promotion_category.code
content_tag :a, promotion_category.code, href: row_url(promotion_category)
end
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def columns
{
header: :name,
data: ->(promotion) do
content_tag :div, promotion.name
link_to promotion.name, row_url(promotion), class: "underline cursor-pointer"
end
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def name_column
{
header: :name,
data: ->(promotion_category) do
content_tag :div, promotion_category.name
content_tag :a, promotion_category.name, href: row_url(promotion_category)
end
}
end
Expand All @@ -49,7 +49,7 @@ def code_column
{
header: :code,
data: ->(promotion_category) do
content_tag :div, promotion_category.code
content_tag :a, promotion_category.code, href: row_url(promotion_category)
end
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def columns
{
header: :name,
data: ->(promotion) do
link_to promotion.name, row_url(promotion)
link_to promotion.name, row_url(promotion), class: "underline cursor-pointer"
end
},
{
Expand Down

0 comments on commit eb8b834

Please sign in to comment.