Skip to content

Commit

Permalink
wip: semantic tables and forms
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Dec 6, 2024
1 parent dcb0dd8 commit 12f0d59
Show file tree
Hide file tree
Showing 48 changed files with 295 additions and 179 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_adjustment_reason_modal do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @adjustment_reason, url: solidus_admin.adjustment_reason_path(@adjustment_reason), html: { id: form_id } do |f| %>
<%= turbo_frame_tag :edit_adjustment_reason_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title"), close_path: close_path) do |modal| %>
<%= form_for @adjustment_reason, url: solidus_admin.adjustment_reason_path(@adjustment_reason, **search_filter_params), html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
Expand All @@ -17,7 +17,7 @@
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
<%= render component("ui/button").new(scheme: :secondary, tag: :a, text: t('.cancel'), href: close_path) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ def initialize(page:, adjustment_reason:)
def form_id
dom_id(@adjustment_reason, "#{stimulus_id}_edit_adjustment_reason_form")
end

def close_path
solidus_admin.adjustment_reasons_path(**search_filter_params)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def turbo_frames
end

def row_url(adjustment_reason)
spree.edit_admin_adjustment_reason_path(adjustment_reason, _turbo_frame: :edit_adjustment_reason_modal)
edit_path(adjustment_reason)
end

def edit_path(adjustment_reason)
spree.edit_admin_adjustment_reason_path(adjustment_reason, **search_filter_params)
end

def batch_actions
Expand All @@ -47,8 +51,18 @@ def batch_actions

def columns
[
:name,
:code,
{
header: :name,
data: ->(adjustment_reason) do
link_to adjustment_reason.name, edit_path(adjustment_reason), class: "body-link"
end
},
{
header: :code,
data: ->(adjustment_reason) do
link_to adjustment_reason.code, edit_path(adjustment_reason), class: "body-link"
end
},
{
header: :active,
data: ->(adjustment_reason) do
Expand Down
18 changes: 7 additions & 11 deletions admin/app/components/solidus_admin/option_types/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ def model_class
end

def row_url(option_type)
spree.edit_admin_option_type_path(option_type)
edit_path(option_type)
end

def edit_path(option_type)
spree.edit_admin_option_type_path(option_type, **search_filter_params)
end

def sortable_options
Expand All @@ -25,14 +29,6 @@ def page_actions
)
end

def prev_page_path
solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first?
end

def next_page_path
solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last?
end

def batch_actions
[
{
Expand All @@ -55,7 +51,7 @@ def name_column
{
header: :name,
data: ->(option_type) do
content_tag :div, option_type.name
link_to option_type.name, edit_path(option_type), class: "body-link"
end
}
end
Expand All @@ -64,7 +60,7 @@ def presentation_column
{
header: :presentation,
data: ->(option_type) do
content_tag :div, option_type.presentation
link_to option_type.presentation, edit_path(option_type), class: "body-link"
end
}
end
Expand Down
12 changes: 6 additions & 6 deletions admin/app/components/solidus_admin/orders/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def search_url
end

def row_url(order)
spree.edit_admin_order_path(order)
edit_path(order)
end

def edit_path(order)
spree.edit_admin_order_path(order, **search_filter_params)
end

def row_fade(order)
Expand Down Expand Up @@ -105,11 +109,7 @@ def number_column
{
header: :order,
data: ->(order) do
if !row_fade(order)
content_tag :div, order.number, class: 'font-semibold'
else
content_tag :div, order.number
end
link_to order.number, edit_path(order), class: row_fade(order) ? 'body-link' : 'body-link font-semibold'
end
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def search_url
end

def row_url(payment_method)
spree.edit_admin_payment_method_path(payment_method)
edit_path(payment_method)
end

def edit_path(payment_method)
spree.edit_admin_payment_method_path(payment_method, **search_filter_params)
end

def sortable_options
Expand Down Expand Up @@ -59,7 +63,7 @@ def columns
{
header: :name,
data: ->(payment_method) do
content_tag :div, payment_method.name
link_to payment_method.name, edit_path(payment_method), class: "body-link"
end
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def search_url
end

def row_url(product)
solidus_admin.product_path(product)
edit_path(product)
end

def edit_path(product)
solidus_admin.edit_product_path(product, **search_filter_params)
end

def page_actions
Expand Down Expand Up @@ -106,7 +110,7 @@ def name_column
{
header: :name,
data: ->(product) do
content_tag :div, product.name
link_to product.name, edit_path(product), class: "body-link"
end
}
end
Expand Down
10 changes: 7 additions & 3 deletions admin/app/components/solidus_admin/properties/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def search_url
end

def row_url(property)
spree.admin_property_path(property)
edit_path(property)
end

def edit_path(property)
spree.admin_property_path(property, **search_filter_params)
end

def page_actions
Expand Down Expand Up @@ -48,7 +52,7 @@ def name_column
{
header: :name,
data: ->(property) do
content_tag :div, property.name
link_to property.name, edit_path(property), class: "body-link"
end
}
end
Expand All @@ -57,7 +61,7 @@ def presentation_column
{
header: :presentation,
data: ->(property) do
content_tag :div, property.presentation
link_to property.presentation, edit_path(property), class: "body-link"
end
}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_refund_reason_modal do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @refund_reason, url: solidus_admin.refund_reason_path(@refund_reason), html: { id: form_id } do |f| %>
<%= turbo_frame_tag :edit_refund_reason_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title"), close_path: close_path) do |modal| %>
<%= form_for @refund_reason, url: solidus_admin.refund_reason_path(@refund_reason, **search_filter_params), html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
Expand All @@ -17,7 +17,7 @@
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
<%= render component("ui/button").new(scheme: :secondary, tag: :a, href: close_path, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ def initialize(page:, refund_reason:)
def form_id
dom_id(@refund_reason, "#{stimulus_id}_edit_refund_reason_form")
end

def close_path
solidus_admin.refund_reasons_path(**search_filter_params)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def search_key
end

def row_url(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason, _turbo_frame: :edit_refund_reason_modal)
edit_path(refund_reason)
end

def edit_path(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason, **search_filter_params)
end

def turbo_frames
Expand Down Expand Up @@ -47,7 +51,12 @@ def batch_actions

def columns
[
:name,
{
header: :name,
data: ->(refund_reason) do
link_to refund_reason.name, edit_path(refund_reason), class: "body-link"
end
},
:code,
{
header: :active,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_return_reason_modal do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @return_reason, url: solidus_admin.return_reason_path(@return_reason), html: { id: form_id } do |f| %>
<%= turbo_frame_tag :edit_return_reason_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title"), close_path: close_path) do |modal| %>
<%= form_for @return_reason, url: solidus_admin.return_reason_path(@return_reason, **search_filter_params), html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<label class="flex gap-2 items-center">
Expand All @@ -16,7 +16,7 @@
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
<%= render component("ui/button").new(scheme: :secondary, tag: :a, text: t('.cancel'), href: close_path) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ def initialize(page:, return_reason:)
def form_id
dom_id(@return_reason, "#{stimulus_id}_edit_return_reason_form")
end

def close_path
solidus_admin.return_reasons_path(**search_filter_params)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def search_key
end

def row_url(return_reason)
spree.edit_admin_return_reason_path(return_reason, _turbo_frame: :edit_return_reason_modal)
edit_path(return_reason)
end

def edit_path(return_reason)
spree.edit_admin_return_reason_path(return_reason, **search_filter_params)
end

def turbo_frames
Expand Down Expand Up @@ -48,7 +52,12 @@ def batch_actions

def columns
[
:name,
{
header: :name,
data: ->(return_reason) do
link_to return_reason.name, edit_path(return_reason), class: "body-link"
end
},
{
header: :active,
data: ->(return_reason) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= turbo_frame_tag :edit_role_modal do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @role, url: solidus_admin.role_path(@role), html: { id: form_id } do |f| %>
<%= turbo_frame_tag :edit_role_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title"), close_path: close_path) do |modal| %>
<%= form_for @role, url: solidus_admin.role_path(@role, **search_filter_params), html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<%= render component("ui/forms/field").text_field(f, :description) %>
Expand All @@ -22,7 +22,7 @@

<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
<%= render component("ui/button").new(scheme: :secondary, tag: :a, href: close_path, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions admin/app/components/solidus_admin/roles/edit/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def form_id
dom_id(@role, "#{stimulus_id}_edit_role_form")
end

def close_path
solidus_admin.roles_path(**search_filter_params)
end

private

def permission_set_options
Expand Down
12 changes: 9 additions & 3 deletions admin/app/components/solidus_admin/roles/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def search_url
end

def row_url(role)
solidus_admin.edit_role_path(role, _turbo_frame: :edit_role_modal)
edit_path(role)
end

def edit_path(role)
solidus_admin.edit_role_path(role, **search_filter_params)
end

def page_actions
Expand Down Expand Up @@ -58,8 +62,10 @@ def filters
def columns
[
{
header: :role,
data: :name,
header: :name,
data: ->(role) do
link_to role.name, edit_path(role), class: "body-link"
end
},
{
header: :description,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<%= turbo_frame_tag :edit_shipping_category_modal do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @shipping_category, url: solidus_admin.shipping_category_path(@shipping_category), html: { id: form_id } do |f| %>
<%= turbo_frame_tag :edit_shipping_category_modal, target: "_top" do %>
<%= render component("ui/modal").new(title: t(".title"), close_path: close_path) do |modal| %>
<%= form_for @shipping_category, url: solidus_admin.shipping_category_path(@shipping_category, **search_filter_params), html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name) %>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
<%= render component("ui/button").new(scheme: :secondary, tag: :a, href: close_path, text: t('.cancel')) %>
</form>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
Expand Down
Loading

0 comments on commit 12f0d59

Please sign in to comment.