Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin] Introduce base Index Component #5561

Merged
merged 20 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7c5c12b
Fix top rounded borders on the ui/table component
elia Dec 28, 2023
784ae12
Let the admin alpha features preference setter not have a question mark
elia Dec 29, 2023
8a98d20
Reuse the sandbox Procfile.dev in the main Procfile.dev
elia Dec 29, 2023
a73abe8
Create ui/pages/index component
rainerdema Dec 18, 2023
455bdce
Use ui/pages/index component in products/index component
rainerdema Dec 18, 2023
f25b512
Use ui/pages/index component in orders/index component
rainerdema Dec 18, 2023
7ac8c84
Use ui/pages/index component in option_types/index component
rainerdema Dec 21, 2023
59d7e35
Use ui/pages/index component in zones/index component
rainerdema Dec 21, 2023
13e5d00
Use ui/pages/index component in users/index component
rainerdema Dec 21, 2023
2c32de6
Use ui/pages/index component in taxonomies/index component
rainerdema Dec 21, 2023
a9a15f1
Use ui/pages/index component in stores/index component
rainerdema Dec 21, 2023
6f264b4
Use ui/pages/index component in stock_items/index component
rainerdema Dec 21, 2023
7973173
Use ui/pages/index component in propertiies/index component
rainerdema Dec 21, 2023
5b29bc6
Use ui/pages/index component in promotions/index component
rainerdema Dec 21, 2023
81b3481
Use ui/pages/index component in promotion_categories/index component
rainerdema Dec 21, 2023
a042db7
Use ui/pages/index component in payment_methods/index component
rainerdema Dec 21, 2023
6d63008
Add support for inheritable translations
elia Dec 29, 2023
26074da
Extract common index pages translations to the super component
elia Dec 28, 2023
ed0c6cb
Use ui/pages/index component tabbed index components
elia Dec 29, 2023
c016d80
Add back styles to the preview layout
elia Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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

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