diff --git a/Procfile.dev b/Procfile.dev index 852b4d3dee3..18a61e0ede6 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,3 +1,2 @@ -web: env RUBY_DEBUG_OPEN=true bin/rails server -css: bin/rails tailwindcss:watch -admin_tailwind: bundle exec rake -C admin tailwindcss:watch +sandbox: foreman start -d sandbox -f sandbox/Procfile.dev +admin: bundle exec rake -C admin tailwindcss:watch 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/adjustment_reasons/index/component.yml b/admin/app/components/solidus_admin/adjustment_reasons/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' diff --git a/admin/app/components/solidus_admin/base_component.rb b/admin/app/components/solidus_admin/base_component.rb index 6e5483e9e98..97de174fa9b 100644 --- a/admin/app/components/solidus_admin/base_component.rb +++ b/admin/app/components/solidus_admin/base_component.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +require "view_component/version" +require "view_component/translatable" + module SolidusAdmin # BaseComponent is the base class for all components in Solidus Admin. class BaseComponent < ViewComponent::Base @@ -10,6 +13,31 @@ def icon_tag(name, **attrs) render component("ui/icon").new(name: name, **attrs) end + module InheritableTranslations + def build_i18n_backend + return if compiled? + + # We need to load the translations files from the ancestors so a component + # can inherit translations from its parent and is able to overwrite them. + translation_files = ancestors.reverse_each.with_object([]) do |ancestor, files| + if ancestor.is_a?(Class) && ancestor < ViewComponent::Base + files.concat(ancestor.sidecar_files(%w[yml yaml].freeze)) + end + end + + # In development it will become nil if the translations file is removed + self.i18n_backend = if translation_files.any? + ViewComponent::Translatable::I18nBackend.new( + i18n_scope: i18n_scope, + load_paths: translation_files + ) + end + end + end + + # Can be removed once https://github.com/ViewComponent/view_component/pull/1934 is released + extend InheritableTranslations unless Gem::Version.new(ViewComponent::VERSION::STRING) >= Gem::Version.new("3.9") + def missing_translation(key, options) keys = I18n.normalize_keys(options[:locale] || I18n.locale, key, options[:scope]) diff --git a/admin/app/components/solidus_admin/option_types/index/component.html.erb b/admin/app/components/solidus_admin/option_types/index/component.html.erb deleted file mode 100644 index 29819fb60d4..00000000000 --- a/admin/app/components/solidus_admin/option_types/index/component.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_option_type_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::OptionType, - rows: @page.records, - url: ->(option_type) { spree.edit_admin_option_type_path(option_type) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - sortable: { - url: ->(option_type) { solidus_admin.move_option_type_path(option_type) }, - param: 'position', - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/option_types/index/component.rb b/admin/app/components/solidus_admin/option_types/index/component.rb index f98d454a7a6..1cad137da0d 100644 --- a/admin/app/components/solidus_admin/option_types/index/component.rb +++ b/admin/app/components/solidus_admin/option_types/index/component.rb @@ -1,14 +1,28 @@ # frozen_string_literal: true -class SolidusAdmin::OptionTypes::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::OptionTypes::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::OptionType + end + + def row_url(option_type) + spree.edit_admin_option_type_path(option_type) + end - def initialize(page:) - @page = page + def sortable_options + { + url: ->(option_type) { solidus_admin.move_option_type_path(option_type) }, + param: 'position', + } end - def title - Spree::OptionType.model_name.human.pluralize + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_option_type_path, + icon: "add-line", + ) end def prev_page_path diff --git a/admin/app/components/solidus_admin/orders/index/component.html.erb b/admin/app/components/solidus_admin/orders/index/component.html.erb deleted file mode 100644 index 3f66b26df60..00000000000 --- a/admin/app/components/solidus_admin/orders/index/component.html.erb +++ /dev/null @@ -1,35 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.create_order'), - href: spree.new_admin_order_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::Order, - rows: @page.records, - fade: row_fade, - url: ->(order) { spree.edit_admin_order_path(order) }, - batch_actions: batch_actions, - columns: columns, - prev: prev_page_path, - next: next_page_path, - }, - search: { - name: :q, - value: params[:q], - searchbar_key: :number_or_shipments_number_or_bill_address_name_or_email_cont, - url: solidus_admin.orders_path(scope: params[:scope]), - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/orders/index/component.rb b/admin/app/components/solidus_admin/orders/index/component.rb index 25033a23738..c75436888ae 100644 --- a/admin/app/components/solidus_admin/orders/index/component.rb +++ b/admin/app/components/solidus_admin/orders/index/component.rb @@ -1,28 +1,33 @@ # frozen_string_literal: true -class SolidusAdmin::Orders::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - - def initialize(page:) - @page = page +class SolidusAdmin::Orders::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::Order end - class_attribute :row_fade, default: ->(order) { order.paid? && order.shipped? } + def search_key + :number_or_shipments_number_or_bill_address_name_or_email_cont + end - def title - Spree::Order.model_name.human.pluralize + def search_url + solidus_admin.orders_path(scope: params[:scope]) end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(order) + spree.edit_admin_order_path(order) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def row_fade(order) + order.paid? && order.shipped? end - def batch_actions - [] + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_order_path, + icon: "add-line", + ) end def scopes @@ -100,7 +105,7 @@ def number_column { header: :order, data: ->(order) do - if !row_fade.call(order) + if !row_fade(order) content_tag :div, order.number, class: 'font-semibold' else content_tag :div, order.number diff --git a/admin/app/components/solidus_admin/orders/index/component.yml b/admin/app/components/solidus_admin/orders/index/component.yml index bcfbf6c6b69..e40bbe916f3 100644 --- a/admin/app/components/solidus_admin/orders/index/component.yml +++ b/admin/app/components/solidus_admin/orders/index/component.yml @@ -1,5 +1,4 @@ en: - create_order: 'Create Order' columns: items: one: 1 Item diff --git a/admin/app/components/solidus_admin/payment_methods/index/component.html.erb b/admin/app/components/solidus_admin/payment_methods/index/component.html.erb deleted file mode 100644 index c756e69f054..00000000000 --- a/admin/app/components/solidus_admin/payment_methods/index/component.html.erb +++ /dev/null @@ -1,38 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_payment_method_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::PaymentMethod, - rows: @page.records, - prev: prev_page_path, - next: next_page_path, - url: ->(payment_method) { spree.edit_admin_payment_method_path(payment_method) }, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.payment_methods_path, - searchbar_key: :name_or_description_cont, - scopes: scopes, - filters: filters, - }, - sortable: { - url: ->(payment_method) { solidus_admin.move_payment_method_path(payment_method) }, - param: 'position', - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/payment_methods/index/component.rb b/admin/app/components/solidus_admin/payment_methods/index/component.rb index 13f4bbe8add..9639b5fd80d 100644 --- a/admin/app/components/solidus_admin/payment_methods/index/component.rb +++ b/admin/app/components/solidus_admin/payment_methods/index/component.rb @@ -1,22 +1,36 @@ # frozen_string_literal: true -class SolidusAdmin::PaymentMethods::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::PaymentMethods::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::PaymentMethod + end + + def search_key + :name_or_description_cont + end - def initialize(page:) - @page = page + def search_url + solidus_admin.payment_methods_path end - def title - Spree::PaymentMethod.model_name.human.pluralize + def row_url(payment_method) + spree.edit_admin_payment_method_path(payment_method) end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def sortable_options + { + url: ->(payment_method) { solidus_admin.move_payment_method_path(payment_method) }, + param: 'position', + } end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_payment_method_path, + icon: "add-line", + ) end def batch_actions @@ -40,10 +54,6 @@ def scopes ] end - def filters - [] - end - def columns [ { @@ -62,9 +72,9 @@ def columns header: :available_to_users, data: ->(payment_method) do if payment_method.available_to_users? - component('ui/badge').new(name: t('.yes'), color: :green) + component('ui/badge').yes else - component('ui/badge').new(name: t('.no'), color: :graphite_light) + component('ui/badge').no end end }, @@ -72,9 +82,9 @@ def columns header: :available_to_admin, data: ->(payment_method) do if payment_method.available_to_admin? - component('ui/badge').new(name: t('.yes'), color: :green) + component('ui/badge').yes else - component('ui/badge').new(name: t('.no'), color: :graphite_light) + component('ui/badge').no end end }, diff --git a/admin/app/components/solidus_admin/payment_methods/index/component.yml b/admin/app/components/solidus_admin/payment_methods/index/component.yml index 34acf86bda7..110ef0756a7 100644 --- a/admin/app/components/solidus_admin/payment_methods/index/component.yml +++ b/admin/app/components/solidus_admin/payment_methods/index/component.yml @@ -1,7 +1,4 @@ en: - add: 'Add new' - "yes": "Yes" - "no": "No" status: active: Active inactive: Inactive @@ -11,5 +8,3 @@ en: admin: Admin storefront: Storefront all: All - batch_actions: - delete: 'Delete' diff --git a/admin/app/components/solidus_admin/products/index/component.html.erb b/admin/app/components/solidus_admin/products/index/component.html.erb deleted file mode 100644 index 312a613a1fe..00000000000 --- a/admin/app/components/solidus_admin/products/index/component.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_product_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::Product, - rows: @page.records, - url: ->(product) { solidus_admin.product_path(product) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.products_path, - searchbar_key: :name_or_variants_including_master_sku_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/products/index/component.rb b/admin/app/components/solidus_admin/products/index/component.rb index 74ef36f62c1..5dbbdfc6a4e 100644 --- a/admin/app/components/solidus_admin/products/index/component.rb +++ b/admin/app/components/solidus_admin/products/index/component.rb @@ -1,22 +1,29 @@ # frozen_string_literal: true -class SolidusAdmin::Products::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::Products::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::Product + end - def initialize(page:) - @page = page + def search_key + :name_or_variants_including_master_sku_cont end - def title - Spree::Product.model_name.human.pluralize + def search_url + solidus_admin.products_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(product) + solidus_admin.product_path(product) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_product_path, + icon: "add-line", + ) end def batch_actions diff --git a/admin/app/components/solidus_admin/products/index/component.yml b/admin/app/components/solidus_admin/products/index/component.yml index 8ae8270bd25..c533d4319a7 100644 --- a/admin/app/components/solidus_admin/products/index/component.yml +++ b/admin/app/components/solidus_admin/products/index/component.yml @@ -1,8 +1,6 @@ en: image: 'Image' - add: 'Add new' batch_actions: - delete: 'Delete' discontinue: 'Discontinue' activate: 'Activate' filters: diff --git a/admin/app/components/solidus_admin/promotion_categories/index/component.html.erb b/admin/app/components/solidus_admin/promotion_categories/index/component.html.erb deleted file mode 100644 index 84be1f3128b..00000000000 --- a/admin/app/components/solidus_admin/promotion_categories/index/component.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_promotion_category_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::PromotionCategory, - rows: @page.records, - url: ->(promotion_category) { spree.edit_admin_promotion_category_path(promotion_category) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/promotion_categories/index/component.rb b/admin/app/components/solidus_admin/promotion_categories/index/component.rb index 4a20c7d1db8..a5ee76493dc 100644 --- a/admin/app/components/solidus_admin/promotion_categories/index/component.rb +++ b/admin/app/components/solidus_admin/promotion_categories/index/component.rb @@ -1,22 +1,21 @@ # frozen_string_literal: true -class SolidusAdmin::PromotionCategories::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - - def initialize(page:) - @page = page - end - - def title - Spree::PromotionCategory.model_name.human.pluralize +class SolidusAdmin::PromotionCategories::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::PromotionCategory end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(promotion_category) + spree.edit_admin_promotion_category_path(promotion_category) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_promotion_category_path, + icon: "add-line", + ) end def batch_actions diff --git a/admin/app/components/solidus_admin/promotion_categories/index/component.yml b/admin/app/components/solidus_admin/promotion_categories/index/component.yml deleted file mode 100644 index fe07d079a52..00000000000 --- a/admin/app/components/solidus_admin/promotion_categories/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - batch_actions: - delete: 'Delete' - add: 'Add new' diff --git a/admin/app/components/solidus_admin/promotions/index/component.html.erb b/admin/app/components/solidus_admin/promotions/index/component.html.erb deleted file mode 100644 index 2e43eb92892..00000000000 --- a/admin/app/components/solidus_admin/promotions/index/component.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_promotion_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::Promotion, - rows: @page.records, - url: ->(promotion) { spree.admin_promotion_path(promotion) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.promotions_path, - searchbar_key: :name_or_codes_value_or_path_or_description_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/promotions/index/component.rb b/admin/app/components/solidus_admin/promotions/index/component.rb index 60a2dd0cc7e..09e4810d71f 100644 --- a/admin/app/components/solidus_admin/promotions/index/component.rb +++ b/admin/app/components/solidus_admin/promotions/index/component.rb @@ -1,22 +1,29 @@ # frozen_string_literal: true -class SolidusAdmin::Promotions::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::Promotions::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::Promotion + end - def initialize(page:) - @page = page + def search_key + :name_or_codes_value_or_path_or_description_cont end - def title - Spree::Promotion.model_name.human.pluralize + def search_url + solidus_admin.promotions_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(promotion) + spree.admin_promotion_path(promotion) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_promotion_path, + icon: "add-line", + ) end def batch_actions diff --git a/admin/app/components/solidus_admin/promotions/index/component.yml b/admin/app/components/solidus_admin/promotions/index/component.yml index cdb40f9455b..7ba70160390 100644 --- a/admin/app/components/solidus_admin/promotions/index/component.yml +++ b/admin/app/components/solidus_admin/promotions/index/component.yml @@ -1,8 +1,4 @@ en: - promotion_image: 'Image' - add: 'Add new' - batch_actions: - delete: 'Delete' scopes: active: Active draft: Draft diff --git a/admin/app/components/solidus_admin/properties/index/component.html.erb b/admin/app/components/solidus_admin/properties/index/component.html.erb deleted file mode 100644 index bc8ad4e511f..00000000000 --- a/admin/app/components/solidus_admin/properties/index/component.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_property_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::Property, - rows: @page.records, - url: ->(property) { solidus_admin.properties_path(property) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.properties_path, - searchbar_key: :name_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/properties/index/component.rb b/admin/app/components/solidus_admin/properties/index/component.rb index 9bc2b810c13..2f0af1141b2 100644 --- a/admin/app/components/solidus_admin/properties/index/component.rb +++ b/admin/app/components/solidus_admin/properties/index/component.rb @@ -1,22 +1,29 @@ # frozen_string_literal: true -class SolidusAdmin::Properties::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::Properties::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::Property + end - def initialize(page:) - @page = page + def search_key + :name_cont end - def title - Spree::Property.model_name.human.pluralize + def search_url + solidus_admin.properties_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(property) + spree.admin_property_path(property) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_property_path, + icon: "add-line", + ) end def batch_actions @@ -30,14 +37,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ name_column, diff --git a/admin/app/components/solidus_admin/properties/index/component.yml b/admin/app/components/solidus_admin/properties/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/properties/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' 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/refund_reasons/index/component.yml b/admin/app/components/solidus_admin/refund_reasons/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/refund_reasons/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' 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/reimbursement_types/index/component.yml b/admin/app/components/solidus_admin/reimbursement_types/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/reimbursement_types/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' 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/return_reasons/index/component.yml b/admin/app/components/solidus_admin/return_reasons/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/return_reasons/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' 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_categories/index/component.yml b/admin/app/components/solidus_admin/shipping_categories/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/shipping_categories/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' 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/shipping_methods/index/component.yml b/admin/app/components/solidus_admin/shipping_methods/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/shipping_methods/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' diff --git a/admin/app/components/solidus_admin/stock_items/index/component.html.erb b/admin/app/components/solidus_admin/stock_items/index/component.html.erb deleted file mode 100644 index ac0a951f8b0..00000000000 --- a/admin/app/components/solidus_admin/stock_items/index/component.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::StockItem, - rows: @page.records, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - url: -> { solidus_admin.edit_stock_item_path(_1, page: params[:page], q: permitted_query_params) }, - }, - search: { - name: :q, - value: permitted_query_params, - url: solidus_admin.stock_items_path, - searchbar_key: :variant_product_name_or_variant_sku_or_variant_option_values_name_or_variant_option_values_presentation_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/stock_items/index/component.rb b/admin/app/components/solidus_admin/stock_items/index/component.rb index 929d6d5c3eb..11f7fd521d9 100644 --- a/admin/app/components/solidus_admin/stock_items/index/component.rb +++ b/admin/app/components/solidus_admin/stock_items/index/component.rb @@ -1,26 +1,20 @@ # frozen_string_literal: true -class SolidusAdmin::StockItems::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - - def initialize(page:) - @page = page - end - - def title - Spree::StockItem.model_name.human.pluralize +class SolidusAdmin::StockItems::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::StockItem end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def search_key + :variant_product_name_or_variant_sku_or_variant_option_values_name_or_variant_option_values_presentation_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.stock_items_path end - def batch_actions - [] + def row_url(stock_item) + solidus_admin.edit_stock_item_path(stock_item, page: params[:page], q: permitted_query_params) end def scopes 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/stock_locations/index/component.yml b/admin/app/components/solidus_admin/stock_locations/index/component.yml index 72183961309..746dbf1ffec 100644 --- a/admin/app/components/solidus_admin/stock_locations/index/component.yml +++ b/admin/app/components/solidus_admin/stock_locations/index/component.yml @@ -1,6 +1,3 @@ en: active: 'Active' inactive: 'Inactive' - add: 'Add new' - batch_actions: - delete: 'Delete' 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/store_credit_reasons/index/component.yml b/admin/app/components/solidus_admin/store_credit_reasons/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/store_credit_reasons/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' diff --git a/admin/app/components/solidus_admin/stores/index/component.html.erb b/admin/app/components/solidus_admin/stores/index/component.html.erb deleted file mode 100644 index d179f04ccb5..00000000000 --- a/admin/app/components/solidus_admin/stores/index/component.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_store_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::Store, - rows: @page.records, - url: ->(store) { spree.edit_admin_store_path(store) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.stores_path, - searchbar_key: :name_or_url_or_code_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/stores/index/component.rb b/admin/app/components/solidus_admin/stores/index/component.rb index 14a6bff249e..bad5a948575 100644 --- a/admin/app/components/solidus_admin/stores/index/component.rb +++ b/admin/app/components/solidus_admin/stores/index/component.rb @@ -1,22 +1,29 @@ # frozen_string_literal: true -class SolidusAdmin::Stores::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::Stores::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::Store + end - def initialize(page:) - @page = page + def search_key + :name_or_url_or_code_cont end - def title - Spree::Store.model_name.human.pluralize + def search_url + solidus_admin.stores_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(store) + spree.edit_admin_store_path(store) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_store_path, + icon: "add-line", + ) end def batch_actions @@ -30,14 +37,6 @@ def batch_actions ] end - def scopes - [] - end - - def filters - [] - end - def columns [ :name, diff --git a/admin/app/components/solidus_admin/stores/index/component.yml b/admin/app/components/solidus_admin/stores/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/stores/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' 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 897a585e672..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, @@ -47,9 +47,9 @@ def columns header: :is_default, data: ->(tax_category) { if tax_category.is_default? - component('ui/badge').new(name: t('.yes'), color: :green) + component('ui/badge').yes else - component('ui/badge').new(name: t('.no'), color: :graphite_light) + component('ui/badge').no end }, }, diff --git a/admin/app/components/solidus_admin/tax_categories/index/component.yml b/admin/app/components/solidus_admin/tax_categories/index/component.yml deleted file mode 100644 index faff41bc439..00000000000 --- a/admin/app/components/solidus_admin/tax_categories/index/component.yml +++ /dev/null @@ -1,6 +0,0 @@ -en: - "yes": "Yes" - "no": "No" - add: 'Add new' - batch_actions: - delete: 'Delete' 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/tax_rates/index/component.yml b/admin/app/components/solidus_admin/tax_rates/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/tax_rates/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' 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/taxonomies/index/component.html.erb b/admin/app/components/solidus_admin/taxonomies/index/component.html.erb deleted file mode 100644 index dd1a03e1ff6..00000000000 --- a/admin/app/components/solidus_admin/taxonomies/index/component.html.erb +++ /dev/null @@ -1,28 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_taxonomy_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::Taxonomy, - rows: @page.records, - url: ->(taxonomy) { spree.edit_admin_taxonomy_path(taxonomy) }, - columns: columns, - batch_actions: batch_actions, - }, - sortable: { - url: ->(taxonomy) { solidus_admin.move_taxonomy_path(taxonomy) }, - param: 'position', - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/taxonomies/index/component.rb b/admin/app/components/solidus_admin/taxonomies/index/component.rb index 8841631209e..fcee55250a4 100644 --- a/admin/app/components/solidus_admin/taxonomies/index/component.rb +++ b/admin/app/components/solidus_admin/taxonomies/index/component.rb @@ -1,22 +1,28 @@ # frozen_string_literal: true -class SolidusAdmin::Taxonomies::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers - - def initialize(page:) - @page = page +class SolidusAdmin::Taxonomies::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::Taxonomy end - def title - Spree::Taxonomy.model_name.human.pluralize + def row_url(taxonomy) + spree.edit_admin_taxonomy_path(taxonomy) end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def sortable_options + { + url: ->(taxonomy) { solidus_admin.move_taxonomy_path(taxonomy) }, + param: 'position', + } end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_taxonomy_path, + icon: "add-line", + ) end def batch_actions diff --git a/admin/app/components/solidus_admin/taxonomies/index/component.yml b/admin/app/components/solidus_admin/taxonomies/index/component.yml deleted file mode 100644 index fe07d079a52..00000000000 --- a/admin/app/components/solidus_admin/taxonomies/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - batch_actions: - delete: 'Delete' - add: 'Add new' 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 new file mode 100644 index 00000000000..e2b31a8c1e5 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb @@ -0,0 +1,30 @@ +<%= page do %> + <% 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 %> + + <%= render_table %> +<% 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 new file mode 100644 index 00000000000..616a40475f8 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/pages/index/component.rb @@ -0,0 +1,119 @@ +# frozen_string_literal: true + +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) + false + end + + def model_class + nil + end + + def title + model_class.model_name.human.pluralize + end + + def search_key + nil + end + + def search_params + params[:q] + end + + def search_name + :q + end + + def search_url + nil + end + + def table_id + stimulus_id + end + + def rows + @page.records + end + + def row_url(_record) + nil + end + + def batch_actions + [] + end + + def scopes + [] + end + + def filters + [] + end + + def columns + [] + 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 search_options + return unless search_url + + { + name: search_name, + value: search_params, + url: search_url, + searchbar_key: search_key, + filters: filters, + scopes: scopes, + } + end + + def sortable_options + nil + end + + def render_table + render component('ui/table').new( + id: stimulus_id, + data: { + class: model_class, + rows: rows, + fade: -> { row_fade(_1) }, + prev: prev_page_path, + next: next_page_path, + columns: columns, + batch_actions: batch_actions, + url: -> { row_url(_1) }, + }, + search: search_options, + sortable: sortable_options, + ) + end + + def page_actions + nil + end +end diff --git a/admin/app/components/solidus_admin/option_types/index/component.yml b/admin/app/components/solidus_admin/ui/pages/index/component.yml similarity index 100% rename from admin/app/components/solidus_admin/option_types/index/component.yml rename to admin/app/components/solidus_admin/ui/pages/index/component.yml diff --git a/admin/app/components/solidus_admin/ui/table/component.html.erb b/admin/app/components/solidus_admin/ui/table/component.html.erb index e0b79da9819..69a155cd66d 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -3,6 +3,7 @@ rounded-lg border border-gray-100 + <%= 'overflow-hidden' unless @search %> " data-controller="<%= stimulus_id %>" data-<%= stimulus_id %>-selected-row-class="bg-gray-15" @@ -111,7 +112,7 @@ - <% if @data.batch_actions %> + <% if @data.batch_actions && @data.rows.any? %> -target="batchHeader" class="bg-white color-black text-xs leading-none text-left" diff --git a/admin/app/components/solidus_admin/ui/table/component.rb b/admin/app/components/solidus_admin/ui/table/component.rb index 0bf5536b0a5..86a8517f48c 100644 --- a/admin/app/components/solidus_admin/ui/table/component.rb +++ b/admin/app/components/solidus_admin/ui/table/component.rb @@ -59,7 +59,7 @@ def value def initialize(id:, data:, search: nil, sortable: nil) @id = id @data = Data.new(**data) - @data.columns.unshift selectable_column if @data.batch_actions.present? + @data.columns.unshift selectable_column if @data.batch_actions.present? && @data.rows.present? @search = Search.new(**search) if search @sortable = Sortable.new(**sortable) if sortable end diff --git a/admin/app/components/solidus_admin/users/index/component.html.erb b/admin/app/components/solidus_admin/users/index/component.html.erb deleted file mode 100644 index fb69176fabf..00000000000 --- a/admin/app/components/solidus_admin/users/index/component.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_user_path, - icon: "add-line", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree.user_class, - rows: @page.records, - url: ->(user) { spree.admin_user_path(user) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.users_path, - searchbar_key: :email_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/users/index/component.rb b/admin/app/components/solidus_admin/users/index/component.rb index 359ae861a2f..9a4d6d4c8ca 100644 --- a/admin/app/components/solidus_admin/users/index/component.rb +++ b/admin/app/components/solidus_admin/users/index/component.rb @@ -1,22 +1,29 @@ # frozen_string_literal: true -class SolidusAdmin::Users::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::Users::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree.user_class + end - def initialize(page:) - @page = page + def search_key + :email_cont end - def title - Spree.user_class.model_name.human.pluralize + def search_url + solidus_admin.users_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(user) + spree.admin_user_path(user) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_user_path, + icon: "add-line", + ) end def batch_actions diff --git a/admin/app/components/solidus_admin/users/index/component.yml b/admin/app/components/solidus_admin/users/index/component.yml index 6a7fa4eaab4..ba63d2d41f6 100644 --- a/admin/app/components/solidus_admin/users/index/component.yml +++ b/admin/app/components/solidus_admin/users/index/component.yml @@ -1,8 +1,5 @@ en: - promotion_image: 'Image' - add: 'Add new' batch_actions: - delete: 'Delete' discontinue: 'Discontinue' activate: 'Activate' filters: diff --git a/admin/app/components/solidus_admin/zones/index/component.html.erb b/admin/app/components/solidus_admin/zones/index/component.html.erb deleted file mode 100644 index 1162d7d7fbe..00000000000 --- a/admin/app/components/solidus_admin/zones/index/component.html.erb +++ /dev/null @@ -1,35 +0,0 @@ -<%= page do %> - <%= page_header do %> - <%= page_header_title title %> - <%= page_header_actions do %> - <%= render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_zone_path, - icon: "add-line", - class: "align-self-end w-full", - ) %> - <% end %> - <% end %> - - <%= render component('ui/table').new( - id: stimulus_id, - data: { - class: Spree::Zone, - rows: @page.records, - url: ->(zone) { spree.edit_admin_zone_path(zone) }, - prev: prev_page_path, - next: next_page_path, - columns: columns, - batch_actions: batch_actions, - }, - search: { - name: :q, - value: params[:q], - url: solidus_admin.zones_path, - searchbar_key: :name_or_description_cont, - scopes: scopes, - filters: filters, - }, - ) %> -<% end %> diff --git a/admin/app/components/solidus_admin/zones/index/component.rb b/admin/app/components/solidus_admin/zones/index/component.rb index fe5d7e58f8b..eff2c73358d 100644 --- a/admin/app/components/solidus_admin/zones/index/component.rb +++ b/admin/app/components/solidus_admin/zones/index/component.rb @@ -1,22 +1,30 @@ # frozen_string_literal: true -class SolidusAdmin::Zones::Index::Component < SolidusAdmin::BaseComponent - include SolidusAdmin::Layout::PageHelpers +class SolidusAdmin::Zones::Index::Component < SolidusAdmin::UI::Pages::Index::Component + def model_class + Spree::Zone + end - def initialize(page:) - @page = page + def search_key + :name_or_description_cont end - def title - Spree::Zone.model_name.human.pluralize + def search_url + solidus_admin.zones_path end - def prev_page_path - solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + def row_url(zone) + spree.edit_admin_zone_path(zone) end - def next_page_path - solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_zone_path, + icon: "add-line", + class: "align-self-end w-full", + ) end def batch_actions diff --git a/admin/app/components/solidus_admin/zones/index/component.yml b/admin/app/components/solidus_admin/zones/index/component.yml deleted file mode 100644 index 54418702ad3..00000000000 --- a/admin/app/components/solidus_admin/zones/index/component.yml +++ /dev/null @@ -1,4 +0,0 @@ -en: - add: 'Add new' - batch_actions: - delete: 'Delete' diff --git a/admin/app/views/layouts/solidus_admin/preview.html.erb b/admin/app/views/layouts/solidus_admin/preview.html.erb index 19e4e2f5b0f..9f49be0b71a 100644 --- a/admin/app/views/layouts/solidus_admin/preview.html.erb +++ b/admin/app/views/layouts/solidus_admin/preview.html.erb @@ -1,6 +1,8 @@ + <%= stylesheet_link_tag SolidusAdmin::Config.theme_path(session[:admin_light_theme]), media: '(prefers-color-scheme: light)', "data-turbo-track": "reload" %> + <%= stylesheet_link_tag SolidusAdmin::Config.theme_path(session[:admin_dark_theme]), media: '(prefers-color-scheme: dark)', "data-turbo-track": "reload" %> <%= javascript_importmap_tags "solidus_admin/application", shim: false, importmap: SolidusAdmin.importmap %> diff --git a/admin/lib/solidus_admin/configuration.rb b/admin/lib/solidus_admin/configuration.rb index 0c5f7b34f61..921ba5d5cd9 100644 --- a/admin/lib/solidus_admin/configuration.rb +++ b/admin/lib/solidus_admin/configuration.rb @@ -44,7 +44,9 @@ class Configuration < Spree::Preferences::Configuration # Setting this to `true` enables access to alpha stage features that might still be in testing or development. # Use with caution, as these features may not be fully stable or complete. # Default: false - preference :enable_alpha_features?, :boolean, default: false + preference :enable_alpha_features, :boolean, default: false + + alias enable_alpha_features? enable_alpha_features preference :storefront_product_path_proc, :proc, default: ->(_version) { ->(product) { "/products/#{product.slug}" } diff --git a/admin/spec/components/previews/solidus_admin/ui/pages/index/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/pages/index/component_preview.rb new file mode 100644 index 00000000000..37e3b3e6d6c --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/ui/pages/index/component_preview.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +# @component "ui/pages/index" +class SolidusAdmin::UI::Pages::Index::ComponentPreview < ViewComponent::Preview + include SolidusAdmin::Preview + + def overview + records = Spree::Order.all + page = GearedPagination::Recordset.new(records).page(1) + + component_subclcass = Class.new(component("ui/pages/index")) do + def self.name + "SolidusAdmin::MyIndex::Component" + end + + def model_class + Spree::Order + end + + def search_key + :number_cont + end + + def search_url + "/admin/orders" + end + + def columns + [:number] + end + + def page_actions + render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_order_path, + icon: "add-line", + ) + end + + def batch_actions + [{ + display_name: "Print", + action: "print", + }] + end + end + + render component_subclcass.new(page: page) + end +end diff --git a/admin/spec/components/solidus_admin/ui/pages/index/component_spec.rb b/admin/spec/components/solidus_admin/ui/pages/index/component_spec.rb new file mode 100644 index 00000000000..91bed20f526 --- /dev/null +++ b/admin/spec/components/solidus_admin/ui/pages/index/component_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe SolidusAdmin::UI::Pages::Index::Component, type: :component do + it "renders the overview preview" do + render_preview(:overview) + end +end