diff --git a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb index 2ffda1726c3..8cc79b783f2 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb @@ -1,6 +1,6 @@ -<%= turbo_frame_tag :edit_adjustment_reason_modal do %> +<%= turbo_frame_tag :resource_modal, target: "_top" 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| %> + <%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> <%= render component("ui/forms/field").text_field(f, :code, class: "required") %> @@ -24,4 +24,3 @@ <% end %> <% end %> <% end %> -<%= render component("adjustment_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.rb index e2005a5fb23..29a44bae7b7 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.rb @@ -1,12 +1,4 @@ # frozen_string_literal: true -class SolidusAdmin::AdjustmentReasons::Edit::Component < SolidusAdmin::BaseComponent - def initialize(page:, adjustment_reason:) - @page = page - @adjustment_reason = adjustment_reason - end - - def form_id - dom_id(@adjustment_reason, "#{stimulus_id}_edit_adjustment_reason_form") - end +class SolidusAdmin::AdjustmentReasons::Edit::Component < SolidusAdmin::Resources::Edit::Component end diff --git a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb index 647d97ecc82..a7ae5b6b6db 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb @@ -17,7 +17,8 @@ def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_adjustment_reason_path, data: { turbo_frame: :new_adjustment_reason_modal }, + href: solidus_admin.new_adjustment_reason_path(**search_filter_params), + data: { turbo_frame: :resource_modal }, icon: "add-line", class: "align-self-end w-full", ) @@ -25,20 +26,19 @@ def page_actions def turbo_frames %w[ - new_adjustment_reason_modal - edit_adjustment_reason_modal + resource_modal ] end - def row_url(adjustment_reason) - spree.edit_admin_adjustment_reason_path(adjustment_reason, _turbo_frame: :edit_adjustment_reason_modal) + def edit_path(adjustment_reason) + spree.edit_admin_adjustment_reason_path(adjustment_reason, **search_filter_params) end def batch_actions [ { label: t('.batch_actions.delete'), - action: solidus_admin.adjustment_reasons_path, + action: solidus_admin.adjustment_reasons_path(**search_filter_params), method: :delete, icon: 'delete-bin-7-line', }, @@ -47,8 +47,22 @@ 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', + data: { turbo_frame: :resource_modal } + end + }, + { + header: :code, + data: ->(adjustment_reason) do + link_to adjustment_reason.code, edit_path(adjustment_reason), + class: 'body-link', + data: { turbo_frame: :resource_modal } + end + }, { header: :active, data: ->(adjustment_reason) do diff --git a/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb index f30e26730cd..8cc79b783f2 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb @@ -1,6 +1,6 @@ -<%= turbo_frame_tag :new_adjustment_reason_modal do %> +<%= turbo_frame_tag :resource_modal, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> - <%= form_for @adjustment_reason, url: solidus_admin.adjustment_reasons_path, html: { id: form_id } do |f| %> + <%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> <%= render component("ui/forms/field").text_field(f, :code, class: "required") %> @@ -24,5 +24,3 @@ <% end %> <% end %> <% end %> - -<%= render component("adjustment_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/adjustment_reasons/new/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/new/component.rb index dddf9ddb8a0..2610ee1f356 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/new/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/new/component.rb @@ -1,12 +1,4 @@ # frozen_string_literal: true -class SolidusAdmin::AdjustmentReasons::New::Component < SolidusAdmin::BaseComponent - def initialize(page:, adjustment_reason:) - @page = page - @adjustment_reason = adjustment_reason - end - - def form_id - dom_id(@adjustment_reason, "#{stimulus_id}_new_adjustment_reason_form") - end +class SolidusAdmin::AdjustmentReasons::New::Component < SolidusAdmin::Resources::New::Component end diff --git a/admin/app/components/solidus_admin/base_component.rb b/admin/app/components/solidus_admin/base_component.rb index ba8997e1cd9..e9c3cf3ebcc 100644 --- a/admin/app/components/solidus_admin/base_component.rb +++ b/admin/app/components/solidus_admin/base_component.rb @@ -37,5 +37,6 @@ def self.stimulus_id end delegate :stimulus_id, to: :class + delegate :search_filter_params, to: :helpers end end diff --git a/admin/app/components/solidus_admin/properties/edit/component.html.erb b/admin/app/components/solidus_admin/properties/edit/component.html.erb index e116b899486..b2a90586684 100644 --- a/admin/app/components/solidus_admin/properties/edit/component.html.erb +++ b/admin/app/components/solidus_admin/properties/edit/component.html.erb @@ -1,6 +1,6 @@ -<%= turbo_frame_tag :edit_property_modal do %> +<%= turbo_frame_tag :resource_modal, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> - <%= form_for @property, url: solidus_admin.property_path(@property), html: { id: form_id } do |f| %> + <%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> @@ -14,4 +14,3 @@ <% end %> <% end %> <% end %> -<%= render component("properties/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/properties/edit/component.rb b/admin/app/components/solidus_admin/properties/edit/component.rb index b2ed34d9114..0a2fa7a856b 100644 --- a/admin/app/components/solidus_admin/properties/edit/component.rb +++ b/admin/app/components/solidus_admin/properties/edit/component.rb @@ -1,12 +1,4 @@ # frozen_string_literal: true -class SolidusAdmin::Properties::Edit::Component < SolidusAdmin::BaseComponent - def initialize(page:, property:) - @page = page - @property = property - end - - def form_id - dom_id(@property, "#{stimulus_id}_edit_property_form") - end +class SolidusAdmin::Properties::Edit::Component < SolidusAdmin::Resources::Edit::Component end diff --git a/admin/app/components/solidus_admin/properties/index/component.rb b/admin/app/components/solidus_admin/properties/index/component.rb index 61aca2318c4..9782ba2e624 100644 --- a/admin/app/components/solidus_admin/properties/index/component.rb +++ b/admin/app/components/solidus_admin/properties/index/component.rb @@ -17,22 +17,20 @@ def search_url solidus_admin.properties_path end - def row_url(property) - solidus_admin.edit_property_path(property, _turbo_frame: :edit_property_modal) + def edit_path(property) + solidus_admin.edit_property_path(property, **search_filter_params) end def turbo_frames - %w[ - new_property_modal - edit_property_modal - ] + %w[resource_modal] end def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_property_path, data: { turbo_frame: :new_property_modal }, + href: solidus_admin.new_property_path(**search_filter_params), + data: { turbo_frame: :resource_modal }, icon: "add-line", ) end @@ -41,7 +39,7 @@ def batch_actions [ { label: t('.batch_actions.delete'), - action: solidus_admin.properties_path, + action: solidus_admin.properties_path(**search_filter_params), method: :delete, icon: 'delete-bin-7-line', }, @@ -59,7 +57,9 @@ def name_column { header: :name, data: ->(property) do - content_tag :div, property.name + link_to property.name, edit_path(property), + data: { turbo_frame: :resource_modal }, + class: 'body-link' end } end @@ -68,7 +68,9 @@ def presentation_column { header: :presentation, data: ->(property) do - content_tag :div, property.presentation + link_to property.presentation, edit_path(property), + data: { turbo_frame: :resource_modal }, + class: 'body-link' end } end diff --git a/admin/app/components/solidus_admin/properties/new/component.html.erb b/admin/app/components/solidus_admin/properties/new/component.html.erb index d306cebcf4c..b2a90586684 100644 --- a/admin/app/components/solidus_admin/properties/new/component.html.erb +++ b/admin/app/components/solidus_admin/properties/new/component.html.erb @@ -1,6 +1,6 @@ -<%= turbo_frame_tag :new_property_modal do %> +<%= turbo_frame_tag :resource_modal, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> - <%= form_for @property, url: solidus_admin.properties_path, html: { id: form_id } do |f| %> + <%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> @@ -14,5 +14,3 @@ <% end %> <% end %> <% end %> - -<%= render component("properties/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/properties/new/component.rb b/admin/app/components/solidus_admin/properties/new/component.rb index 55e8806c68f..afd74de491e 100644 --- a/admin/app/components/solidus_admin/properties/new/component.rb +++ b/admin/app/components/solidus_admin/properties/new/component.rb @@ -1,12 +1,4 @@ # frozen_string_literal: true -class SolidusAdmin::Properties::New::Component < SolidusAdmin::BaseComponent - def initialize(page:, property:) - @page = page - @property = property - end - - def form_id - dom_id(@property, "#{stimulus_id}_new_property_form") - end +class SolidusAdmin::Properties::New::Component < SolidusAdmin::Resources::New::Component end diff --git a/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb index 4fab63b28f3..630f10dfd16 100644 --- a/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb @@ -1,6 +1,6 @@ -<%= turbo_frame_tag :edit_refund_reason_modal do %> +<%= turbo_frame_tag :resource_modal, target: "_top" 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| %> + <%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> <%= render component("ui/forms/field").text_field(f, :code, class: "required") %> @@ -24,4 +24,3 @@ <% end %> <% end %> <% end %> -<%= render component("refund_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/refund_reasons/edit/component.rb b/admin/app/components/solidus_admin/refund_reasons/edit/component.rb index 285847dc84d..d23a8d8bd51 100644 --- a/admin/app/components/solidus_admin/refund_reasons/edit/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/edit/component.rb @@ -1,12 +1,4 @@ # frozen_string_literal: true -class SolidusAdmin::RefundReasons::Edit::Component < SolidusAdmin::BaseComponent - def initialize(page:, refund_reason:) - @page = page - @refund_reason = refund_reason - end - - def form_id - dom_id(@refund_reason, "#{stimulus_id}_edit_refund_reason_form") - end +class SolidusAdmin::RefundReasons::Edit::Component < SolidusAdmin::Resources::Edit::Component end diff --git a/admin/app/components/solidus_admin/refund_reasons/index/component.rb b/admin/app/components/solidus_admin/refund_reasons/index/component.rb index 0cc0bf4f443..62d4f6b9d06 100644 --- a/admin/app/components/solidus_admin/refund_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.rb @@ -13,14 +13,13 @@ def search_key :name_or_code_cont end - def row_url(refund_reason) - spree.edit_admin_refund_reason_path(refund_reason, _turbo_frame: :edit_refund_reason_modal) + def edit_path(refund_reason) + spree.edit_admin_refund_reason_path(refund_reason, **search_filter_params) end def turbo_frames %w[ - new_refund_reason_modal - edit_refund_reason_modal + resource_modal ] end @@ -28,7 +27,8 @@ def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_refund_reason_path, data: { turbo_frame: :new_refund_reason_modal }, + href: solidus_admin.new_refund_reason_path(**search_filter_params), + data: { turbo_frame: :resource_modal }, icon: "add-line", class: "align-self-end w-full", ) @@ -38,7 +38,7 @@ def batch_actions [ { label: t('.batch_actions.delete'), - action: solidus_admin.refund_reasons_path, + action: solidus_admin.refund_reasons_path(**search_filter_params), method: :delete, icon: 'delete-bin-7-line', }, @@ -47,8 +47,22 @@ def batch_actions def columns [ - :name, - :code, + { + header: :name, + data: ->(refund_reason) do + link_to refund_reason.name, edit_path(refund_reason), + data: { turbo_frame: :resource_modal }, + class: 'body-link' + end + }, + { + header: :code, + data: ->(refund_reason) do + link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason), + data: { turbo_frame: :resource_modal }, + class: 'body-link' + end + }, { header: :active, data: ->(refund_reason) do diff --git a/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb index ef1a44999d2..72a6b996d7c 100644 --- a/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb @@ -1,6 +1,6 @@ -<%= turbo_frame_tag :new_refund_reason_modal do %> +<%= turbo_frame_tag :resource_modal, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> - <%= form_for @refund_reason, url: solidus_admin.refund_reasons_path, html: { id: form_id } do |f| %> + <%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> <%= render component("ui/forms/field").text_field(f, :code, class: "required") %> @@ -23,5 +23,3 @@ <% end %> <% end %> <% end %> - -<%= render component("refund_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/refund_reasons/new/component.rb b/admin/app/components/solidus_admin/refund_reasons/new/component.rb index 686fc0e9ade..938307f0144 100644 --- a/admin/app/components/solidus_admin/refund_reasons/new/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/new/component.rb @@ -1,12 +1,4 @@ # frozen_string_literal: true -class SolidusAdmin::RefundReasons::New::Component < SolidusAdmin::BaseComponent - def initialize(page:, refund_reason:) - @page = page - @refund_reason = refund_reason - end - - def form_id - dom_id(@refund_reason, "#{stimulus_id}_new_refund_reason_form") - end +class SolidusAdmin::RefundReasons::New::Component < SolidusAdmin::Resources::New::Component end diff --git a/admin/app/components/solidus_admin/resources/base_component.rb b/admin/app/components/solidus_admin/resources/base_component.rb new file mode 100644 index 00000000000..904e0d66590 --- /dev/null +++ b/admin/app/components/solidus_admin/resources/base_component.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class SolidusAdmin::Resources::BaseComponent < SolidusAdmin::BaseComponent + def initialize(resource) + @resource = resource + instance_variable_set("@#{resource_name}", resource) + end + + def back_url + solidus_admin.send("#{plural_resource_name}_path") + end + + def resource_name + @resource.model_name.singular_route_key + end + + def plural_resource_name + @resource.model_name.route_key + end +end diff --git a/admin/app/components/solidus_admin/resources/edit/component.rb b/admin/app/components/solidus_admin/resources/edit/component.rb new file mode 100644 index 00000000000..a25afd5195f --- /dev/null +++ b/admin/app/components/solidus_admin/resources/edit/component.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class SolidusAdmin::Resources::Edit::Component < SolidusAdmin::Resources::BaseComponent + def form_id + dom_id(@resource, "#{stimulus_id}_edit_#{resource_name}_form") + end + + def form_url + solidus_admin.send("#{resource_name}_path", @resource, **search_filter_params) + end +end diff --git a/admin/app/components/solidus_admin/resources/new/component.rb b/admin/app/components/solidus_admin/resources/new/component.rb new file mode 100644 index 00000000000..92286d82ccd --- /dev/null +++ b/admin/app/components/solidus_admin/resources/new/component.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class SolidusAdmin::Resources::New::Component < SolidusAdmin::Resources::BaseComponent + def form_id + dom_id(@resource, "#{stimulus_id}_new_#{resource_name}_form") + end + + def form_url + solidus_admin.send("#{plural_resource_name}_path", **search_filter_params) + end +end diff --git a/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb index 8782aa23c43..e1c6af09dc0 100644 --- a/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb @@ -1,6 +1,6 @@ -<%= turbo_frame_tag :edit_return_reason_modal do %> +<%= turbo_frame_tag :resource_modal, target: "_top" 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| %> + <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>