diff --git a/admin/app/components/solidus_admin/adjustment_reasons/index/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/index/component.html.erb deleted file mode 100644 index 47101b1ebe4..00000000000 --- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -<%= render component('refunds_and_returns').new(current_class: Spree::AdjustmentReason) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_adjustment_reason_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::AdjustmentReason, - rows: @page.records, - url: ->(adjustment_reason) { spree.edit_admin_adjustment_reason_path(adjustment_reason) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.adjustment_reasons_path, - searchbar_key: :name_or_code_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% 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 039cbd27c8d..b432453f6a3 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb @@ -1,22 +1,20 @@ # frozen_string_literal: true -class SolidusAdmin::AdjustmentReasons::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - - def initialize(page:) - @page = page +class SolidusAdmin::AdjustmentReasons::Index::Component < SolidusAdmin::RefundsAndReturns::Component + def model_class + Spree::AdjustmentReason end - def title - Spree::AdjustmentReason.model_name.human.pluralize + def search_url + solidus_admin.adjustment_reasons_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def search_key + :name_or_code_cont end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def row_url(adjustment_reason) + spree.edit_admin_adjustment_reason_path(adjustment_reason) end def batch_actions @@ -30,14 +28,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ :name, diff --git a/admin/app/components/solidus_admin/refund_reasons/index/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/index/component.html.erb deleted file mode 100644 index c29b71d03ef..00000000000 --- a/admin/app/components/solidus_admin/refund_reasons/index/component.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -<%= render component('refunds_and_returns').new(current_class: Spree::RefundReason) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_refund_reason_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::RefundReason, - rows: @page.records, - url: ->(refund_reason) { spree.edit_admin_refund_reason_path(refund_reason) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.refund_reasons_path, - searchbar_key: :name_or_code_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% 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 e6570eb31e7..c5b42d244c2 100644 --- a/admin/app/components/solidus_admin/refund_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.rb @@ -1,22 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::RefundReasons::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::RefundReasons::Index::Component < SolidusAdmin::RefundsAndReturns::Component + def model_class + Spree::RefundReason + end - def initialize(page:) - @page = page + def search_url + solidus_admin.refund_reasons_path end - def title - Spree::RefundReason.model_name.human.pluralize + def search_key + :name_or_code_cont end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(refund_reason) + spree.edit_admin_refund_reason_path(refund_reason) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_refund_reason_path, + icon: "add-line", + class: "align-self-end w-full", + ) end def batch_actions @@ -30,14 +38,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ :name, diff --git a/admin/app/components/solidus_admin/refunds_and_returns/component.html.erb b/admin/app/components/solidus_admin/refunds_and_returns/component.html.erb deleted file mode 100644 index 52d2f801238..00000000000 --- a/admin/app/components/solidus_admin/refunds_and_returns/component.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title safe_join([ - tag.div(t(".title")), - tag.div(t(".subtitle"), class: "font-normal text-sm text-gray-500"), - ]) %> - <% end %> - <%= page_header do %> - <% title = capture do %> - <% tabs.each do |tab_class, href|%> - <%= render component('ui/button').new( - tag: :a, - scheme: :ghost, - href: href, - text: tab_class.model_name.human.pluralize, - "aria-current" => tab_class == @current_class, - ) %> - <% end %> - <% end %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= actions %> - <% end %> - <% end %> - <%= content %> -<% end %> diff --git a/admin/app/components/solidus_admin/refunds_and_returns/component.rb b/admin/app/components/solidus_admin/refunds_and_returns/component.rb index 8d24892c73d..7920c482f73 100644 --- a/admin/app/components/solidus_admin/refunds_and_returns/component.rb +++ b/admin/app/components/solidus_admin/refunds_and_returns/component.rb @@ -1,20 +1,40 @@ # frozen_string_literal: true -class SolidusAdmin::RefundsAndReturns::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - renders_one :actions - - def initialize(current_class:) - @current_class = current_class +class SolidusAdmin::RefundsAndReturns::Component < SolidusAdmin::UI::Pages::Index::Component + def title + page_header_title safe_join([ + tag.div(t(".title")), + tag.div(t(".subtitle"), class: "font-normal text-sm text-gray-500"), + ]) end def tabs - { - Spree::RefundReason => solidus_admin.refund_reasons_path, - Spree::ReimbursementType => solidus_admin.reimbursement_types_path, - Spree::ReturnReason => solidus_admin.return_reasons_path, - Spree::AdjustmentReason => solidus_admin.adjustment_reasons_path, - Spree::StoreCreditReason => solidus_admin.store_credit_reasons_path, - } + [ + { + text: Spree::RefundReason.model_name.human(count: 2), + href: solidus_admin.refund_reasons_path, + current: model_class == Spree::RefundReason, + }, + { + text: Spree::ReimbursementType.model_name.human(count: 2), + href: solidus_admin.reimbursement_types_path, + current: model_class == Spree::ReimbursementType, + }, + { + text: Spree::ReturnReason.model_name.human(count: 2), + href: solidus_admin.return_reasons_path, + current: model_class == Spree::ReturnReason, + }, + { + text: Spree::AdjustmentReason.model_name.human(count: 2), + href: solidus_admin.adjustment_reasons_path, + current: model_class == Spree::AdjustmentReason, + }, + { + text: Spree::StoreCreditReason.model_name.human(count: 2), + href: solidus_admin.store_credit_reasons_path, + current: model_class == Spree::StoreCreditReason, + }, + ] end end diff --git a/admin/app/components/solidus_admin/reimbursement_types/index/component.html.erb b/admin/app/components/solidus_admin/reimbursement_types/index/component.html.erb deleted file mode 100644 index 675fa8637a2..00000000000 --- a/admin/app/components/solidus_admin/reimbursement_types/index/component.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%= render component('refunds_and_returns').new(current_class: Spree::ReimbursementType) do |layout| %> - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::ReimbursementType, - rows: @page.records, - url: nil, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.reimbursement_types_path, - searchbar_key: :name_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/reimbursement_types/index/component.rb b/admin/app/components/solidus_admin/reimbursement_types/index/component.rb index 6465f133e11..39ea3bc77e7 100644 --- a/admin/app/components/solidus_admin/reimbursement_types/index/component.rb +++ b/admin/app/components/solidus_admin/reimbursement_types/index/component.rb @@ -1,34 +1,16 @@ # frozen_string_literal: true -class SolidusAdmin::ReimbursementTypes::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - - def initialize(page:) - @page = page - end - - def title - Spree::ReimbursementType.model_name.human.pluralize - 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 - [] +class SolidusAdmin::ReimbursementTypes::Index::Component < SolidusAdmin::RefundsAndReturns::Component + def model_class + Spree::ReimbursementType end - def scopes - [] + def search_url + solidus_admin.reimbursement_types_path end - def filters - [] + def search_key + :name_cont end def columns diff --git a/admin/app/components/solidus_admin/return_reasons/index/component.html.erb b/admin/app/components/solidus_admin/return_reasons/index/component.html.erb deleted file mode 100644 index d65f815f2d8..00000000000 --- a/admin/app/components/solidus_admin/return_reasons/index/component.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -<%= render component('refunds_and_returns').new(current_class: Spree::ReturnReason) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_return_reason_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::ReturnReason, - rows: @page.records, - url: ->(return_reason) { spree.edit_admin_return_reason_path(return_reason) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.return_reasons_path, - searchbar_key: :name_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/return_reasons/index/component.rb b/admin/app/components/solidus_admin/return_reasons/index/component.rb index 8026101dec0..42baf319fc2 100644 --- a/admin/app/components/solidus_admin/return_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/return_reasons/index/component.rb @@ -1,22 +1,20 @@ # frozen_string_literal: true -class SolidusAdmin::ReturnReasons::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - - def initialize(page:) - @page = page +class SolidusAdmin::ReturnReasons::Index::Component < SolidusAdmin::RefundsAndReturns::Component + def model_class + Spree::ReturnReason end - def title - Spree::ReturnReason.model_name.human.pluralize + def search_url + solidus_admin.return_reasons_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def search_key + :name_cont end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def row_url(return_reason) + spree.edit_admin_return_reason_path(return_reason) end def batch_actions @@ -30,14 +28,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ :name, diff --git a/admin/app/components/solidus_admin/shipping/component.html.erb b/admin/app/components/solidus_admin/shipping/component.html.erb deleted file mode 100644 index 4b719650a67..00000000000 --- a/admin/app/components/solidus_admin/shipping/component.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title safe_join([ - tag.div(t(".title")), - tag.div(t(".subtitle"), class: "font-normal text-sm text-gray-500"), - ]) %> - <% end %> - - <%= page_header do %> - <% title = capture do %> - <% tabs.each do |tab_class, href|%> - <%= render component('ui/button').new( - tag: :a, - scheme: :ghost, - href: href, - text: tab_class.model_name.human.pluralize, - "aria-current" => tab_class == @current_class, - ) %> - <% end %> - <% end %> - - <%= page_header_title title %> - - <%= page_header_actions do %> - <%= actions %> - <% end %> - <% end %> - - <%= content %> -<% end %> diff --git a/admin/app/components/solidus_admin/shipping/component.rb b/admin/app/components/solidus_admin/shipping/component.rb index a9a68ed13e7..f9f6fe39579 100644 --- a/admin/app/components/solidus_admin/shipping/component.rb +++ b/admin/app/components/solidus_admin/shipping/component.rb @@ -1,18 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::Shipping::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - renders_one :actions - - def initialize(current_class:) - @current_class = current_class +class SolidusAdmin::Shipping::Component < SolidusAdmin::UI::Pages::Index::Component + def title + page_header_title safe_join([ + tag.div(t(".title")), + tag.div(t(".subtitle"), class: "font-normal text-sm text-gray-500"), + ]) end def tabs - { - Spree::ShippingMethod => solidus_admin.shipping_methods_path, - Spree::ShippingCategory => solidus_admin.shipping_categories_path, - Spree::StockLocation => solidus_admin.stock_locations_path, - } + [ + { + text: Spree::ShippingMethod.model_name.human.pluralize, + href: solidus_admin.shipping_methods_path, + current: model_class == Spree::ShippingMethod, + }, + { + text: Spree::ShippingCategory.model_name.human.pluralize, + href: solidus_admin.shipping_categories_path, + current: model_class == Spree::ShippingCategory, + }, + { + text: Spree::StockLocation.model_name.human.pluralize, + href: solidus_admin.stock_locations_path, + current: model_class == Spree::StockLocation, + }, + ] end end diff --git a/admin/app/components/solidus_admin/shipping_categories/index/component.html.erb b/admin/app/components/solidus_admin/shipping_categories/index/component.html.erb deleted file mode 100644 index 8745df4afd0..00000000000 --- a/admin/app/components/solidus_admin/shipping_categories/index/component.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -<%= render component('shipping').new(current_class: Spree::ShippingCategory) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_shipping_category_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::ShippingCategory, - rows: @page.records, - url: ->(shipping_category) { spree.edit_admin_shipping_category_path(shipping_category) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.shipping_categories_path, - searchbar_key: :name_or_description_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/shipping_categories/index/component.rb b/admin/app/components/solidus_admin/shipping_categories/index/component.rb index 6883cbf3a8d..7624877004e 100644 --- a/admin/app/components/solidus_admin/shipping_categories/index/component.rb +++ b/admin/app/components/solidus_admin/shipping_categories/index/component.rb @@ -1,22 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::ShippingCategories::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::ShippingCategories::Index::Component < SolidusAdmin::Shipping::Component + def model_class + Spree::ShippingCategory + end - def initialize(page:) - @page = page + def actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_shipping_category_path, + icon: "add-line", + class: "align-self-end w-full", + ) end - def title - Spree::ShippingCategory.model_name.human.pluralize + def row_url(shipping_category) + spree.edit_admin_shipping_category_path(shipping_category) end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def search_key + :name_or_description_cont end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def search_url + solidus_admin.shipping_categories_path end def batch_actions @@ -30,14 +38,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ :name diff --git a/admin/app/components/solidus_admin/shipping_methods/index/component.html.erb b/admin/app/components/solidus_admin/shipping_methods/index/component.html.erb deleted file mode 100644 index 66015aa09b2..00000000000 --- a/admin/app/components/solidus_admin/shipping_methods/index/component.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -<%= render component('shipping').new(current_class: Spree::ShippingMethod) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_shipping_method_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::ShippingMethod, - rows: @page.records, - url: ->(shipping_method) { spree.edit_admin_shipping_method_path(shipping_method) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.shipping_methods_path, - searchbar_key: :name_or_description_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/shipping_methods/index/component.rb b/admin/app/components/solidus_admin/shipping_methods/index/component.rb index 0697a4a5de5..12102bda26c 100644 --- a/admin/app/components/solidus_admin/shipping_methods/index/component.rb +++ b/admin/app/components/solidus_admin/shipping_methods/index/component.rb @@ -1,22 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::ShippingMethods::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::ShippingMethods::Index::Component < SolidusAdmin::Shipping::Component + def model_class + Spree::ShippingMethod + end - def initialize(page:) - @page = page + def row_url(shipping_method) + spree.edit_admin_shipping_method_path(shipping_method) end - def title - Spree::ShippingMethod.model_name.human.pluralize + def search_url + solidus_admin.shipping_methods_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def search_key + :name_or_description_cont end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_shipping_method_path, + icon: "add-line", + class: "align-self-end w-full", + ) end def batch_actions @@ -30,14 +38,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ { diff --git a/admin/app/components/solidus_admin/stock_locations/index/component.html.erb b/admin/app/components/solidus_admin/stock_locations/index/component.html.erb deleted file mode 100644 index ebd7cc78d56..00000000000 --- a/admin/app/components/solidus_admin/stock_locations/index/component.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -<%= render component('shipping').new(current_class: Spree::StockLocation) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_stock_location_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::StockLocation, - rows: @page.records, - url: ->(stock_location) { spree.edit_admin_stock_location_path(stock_location) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.stock_locations_path, - searchbar_key: :name_or_description_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/stock_locations/index/component.rb b/admin/app/components/solidus_admin/stock_locations/index/component.rb index 7ed1bda5164..8b9401681fd 100644 --- a/admin/app/components/solidus_admin/stock_locations/index/component.rb +++ b/admin/app/components/solidus_admin/stock_locations/index/component.rb @@ -1,22 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::StockLocations::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::StockLocations::Index::Component < SolidusAdmin::Shipping::Component + def model_class + Spree::StockLocation + end - def initialize(page:) - @page = page + def actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_stock_location_path, + icon: "add-line", + class: "align-self-end w-full", + ) end - def title - Spree::StockLocation.model_name.human.pluralize + def row_url(stock_location) + spree.edit_admin_stock_location_path(stock_location) end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def search_url + solidus_admin.stock_locations_path end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def search_key + :name_or_description_cont end def batch_actions diff --git a/admin/app/components/solidus_admin/store_credit_reasons/index/component.html.erb b/admin/app/components/solidus_admin/store_credit_reasons/index/component.html.erb deleted file mode 100644 index f70bb34932b..00000000000 --- a/admin/app/components/solidus_admin/store_credit_reasons/index/component.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -<%= render component('refunds_and_returns').new(current_class: Spree::StoreCreditReason) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_store_credit_reason_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::StoreCreditReason, - rows: @page.records, - url: ->(store_credit_reason) { spree.edit_admin_store_credit_reason_path(store_credit_reason) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.store_credit_reasons_path, - searchbar_key: :name_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb index d0373358af1..200ba18d619 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb @@ -1,22 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::StoreCreditReasons::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::StoreCreditReasons::Index::Component < SolidusAdmin::RefundsAndReturns::Component + def model_class + Spree::StoreCreditReason + end - def initialize(page:) - @page = page + def actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_store_credit_reason_path, + icon: "add-line", + class: "align-self-end w-full", + ) end - def title - Spree::StoreCreditReason.model_name.human.pluralize + def row_url(store_credit_reason) + spree.edit_admin_store_credit_reason_path(store_credit_reason) end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def search_url + solidus_admin.store_credit_reasons_path end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def search_key + :name_cont end def batch_actions @@ -30,14 +38,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ :name, diff --git a/admin/app/components/solidus_admin/tax_categories/index/component.html.erb b/admin/app/components/solidus_admin/tax_categories/index/component.html.erb deleted file mode 100644 index 1ca843e0663..00000000000 --- a/admin/app/components/solidus_admin/tax_categories/index/component.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -<%= render component('taxes').new(model_class: Spree::TaxCategory) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_tax_category_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::TaxCategory, - rows: @page.records, - url: ->(tax_category) { spree.edit_admin_tax_category_path(tax_category) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.tax_categories_path, - searchbar_key: :name_or_description_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/tax_categories/index/component.rb b/admin/app/components/solidus_admin/tax_categories/index/component.rb index 235d64d69ae..bab394c2d71 100644 --- a/admin/app/components/solidus_admin/tax_categories/index/component.rb +++ b/admin/app/components/solidus_admin/tax_categories/index/component.rb @@ -1,22 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Component + def row_url(tax_category) + spree.edit_admin_tax_category_path(tax_category) + end - def initialize(page:) - @page = page + def model_class + Spree::TaxCategory end - def title - Spree::TaxCategory.model_name.human.pluralize + def search_url + solidus_admin.tax_categories_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_tax_category_path, + icon: "add-line", + class: "align-self-end w-full", + ) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def search_key + :name_or_description_cont end def batch_actions @@ -30,14 +38,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ :name, diff --git a/admin/app/components/solidus_admin/tax_rates/index/component.html.erb b/admin/app/components/solidus_admin/tax_rates/index/component.html.erb deleted file mode 100644 index 305c10bf791..00000000000 --- a/admin/app/components/solidus_admin/tax_rates/index/component.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -<%= render component('taxes').new(model_class: Spree::TaxRate) do |layout| %> - <% layout.with_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_tax_rate_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::TaxRate, - rows: @page.records, - url: ->(tax_rate) { spree.edit_admin_tax_rate_path(tax_rate) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.tax_rates_path, - searchbar_key: :name_or_description_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/tax_rates/index/component.rb b/admin/app/components/solidus_admin/tax_rates/index/component.rb index 8d9b7bae803..3f73e4f42cd 100644 --- a/admin/app/components/solidus_admin/tax_rates/index/component.rb +++ b/admin/app/components/solidus_admin/tax_rates/index/component.rb @@ -1,22 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::TaxRates::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::TaxRates::Index::Component < SolidusAdmin::Taxes::Component + def row_url(tax_rate) + spree.edit_admin_tax_rate_path(tax_rate) + end - def initialize(page:) - @page = page + def model_class + Spree::TaxRate end - def title - Spree::TaxRate.model_name.human.pluralize + def search_url + solidus_admin.tax_rates_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_tax_rate_path, + icon: "add-line", + class: "align-self-end w-full", + ) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def search_key + :name_or_description_cont end def batch_actions @@ -30,10 +38,6 @@ def batch_actions ] end - def scopes - [] - end - def filters [ { diff --git a/admin/app/components/solidus_admin/taxes/component.html.erb b/admin/app/components/solidus_admin/taxes/component.html.erb deleted file mode 100644 index 3dc1fcaf24e..00000000000 --- a/admin/app/components/solidus_admin/taxes/component.html.erb +++ /dev/null @@ -1,24 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title safe_join([ - tag.div(t(".title")), - tag.div(t(".subtitle"), class: "font-normal text-sm text-gray-500"), - ]) %> - <% end %> - - <%= page_header do %> - <% title = capture do %> - <% tabs.each do %> - <%= render(component('ui/button').new(tag: :a, scheme: :ghost, **_1)) %> - <% end %> - <% end %> - - <%= page_header_title title %> - - <%= page_header_actions do %> - <%= actions %> - <% end %> - <% end %> - - <%= content %> -<% end %> diff --git a/admin/app/components/solidus_admin/taxes/component.rb b/admin/app/components/solidus_admin/taxes/component.rb index 789ea880858..366c193c676 100644 --- a/admin/app/components/solidus_admin/taxes/component.rb +++ b/admin/app/components/solidus_admin/taxes/component.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -class SolidusAdmin::Taxes::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - renders_one :actions - - def initialize(model_class:) - @model_class = model_class +class SolidusAdmin::Taxes::Component < SolidusAdmin::UI::Pages::Index::Component + def title + safe_join([ + tag.div(t(".title")), + tag.div(t(".subtitle"), class: "font-normal text-sm text-gray-500"), + ]) end def tabs @@ -13,12 +13,12 @@ def tabs { text: Spree::TaxCategory.model_name.human.pluralize, href: solidus_admin.tax_categories_path, - "aria-current": @model_class == Spree::TaxCategory, + current: model_class == Spree::TaxCategory, }, { text: Spree::TaxRate.model_name.human.pluralize, href: solidus_admin.tax_rates_path, - "aria-current": @model_class == Spree::TaxRate, + current: model_class == Spree::TaxRate, }, ] end diff --git a/admin/app/components/solidus_admin/ui/pages/index/component.html.erb b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb index e3dab8f216f..e2b31a8c1e5 100644 --- a/admin/app/components/solidus_admin/ui/pages/index/component.html.erb +++ b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb @@ -1,8 +1,28 @@ <%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= page_actions %> + <% if @tabs %> + <%= page_header do %> + <%= page_header_title title %> + <% end %> + + <%= page_header do %> + <% rendered_tabs = capture do %> + <% @tabs.each do %> + <%= render(component("ui/button").new(tag: :a, scheme: :ghost, text: _1.text, 'aria-current': _1.current, href: _1.href)) %> + <% end %> + <% end %> + <%= page_header_title rendered_tabs %> + <%= page_header_actions do %> + <%= page_actions %> + <% end %> + <% end %> + + <% else %> + <%= page_header do %> + <%= page_header_title title %> + + <%= page_header_actions do %> + <%= page_actions %> + <% end %> <% end %> <% end %> diff --git a/admin/app/components/solidus_admin/ui/pages/index/component.rb b/admin/app/components/solidus_admin/ui/pages/index/component.rb index 82717d03abf..616a40475f8 100644 --- a/admin/app/components/solidus_admin/ui/pages/index/component.rb +++ b/admin/app/components/solidus_admin/ui/pages/index/component.rb @@ -3,8 +3,15 @@ class SolidusAdmin::UI::Pages::Index::Component < SolidusAdmin::BaseComponent include SolidusAdmin::Layout::PageHelpers + Tab = Struct.new(:text, :href, :current, keyword_init: true) + + def tabs + nil + end + def initialize(page:) @page = page + @tabs = tabs&.map { |tab| Tab.new(**tab) } end def row_fade(_record)