Skip to content

Commit

Permalink
Merge pull request #5561 from nebulab/rainerd+elia/admin/index-component
Browse files Browse the repository at this point in the history
[Admin] Introduce base Index Component
  • Loading branch information
elia authored Jan 3, 2024
2 parents 8411f05 + c016d80 commit e5f001d
Show file tree
Hide file tree
Showing 81 changed files with 673 additions and 1,222 deletions.
5 changes: 2 additions & 3 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -30,14 +28,6 @@ def batch_actions
]
end

def scopes
[]
end

def filters
[]
end

def columns
[
:name,
Expand Down

This file was deleted.

28 changes: 28 additions & 0 deletions admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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])

Expand Down

This file was deleted.

26 changes: 20 additions & 6 deletions admin/app/components/solidus_admin/option_types/index/component.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 0 additions & 35 deletions admin/app/components/solidus_admin/orders/index/component.html.erb

This file was deleted.

35 changes: 20 additions & 15 deletions admin/app/components/solidus_admin/orders/index/component.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
en:
create_order: 'Create Order'
columns:
items:
one: 1 Item
Expand Down

This file was deleted.

Loading

0 comments on commit e5f001d

Please sign in to comment.