Skip to content

Commit

Permalink
Merge pull request solidusio#5559 from nebulab/rainerd/admin/uniform-…
Browse files Browse the repository at this point in the history
…admin-components-style

[Admin] Refactor admin components for consistent code style
  • Loading branch information
rainerdema authored Dec 21, 2023
2 parents 993fb59 + 19e0678 commit f1c4920
Show file tree
Hide file tree
Showing 59 changed files with 213 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class: "align-self-end w-full",
) %>
<% end %>

<%= render component('ui/table').new(
id: stimulus_id,
data: {
Expand All @@ -24,8 +25,8 @@
value: params[:q],
url: solidus_admin.adjustment_reasons_path,
searchbar_key: :name_or_code_cont,
filters: filters,
scopes: scopes,
filters: filters,
},
) %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def batch_actions
]
end

def filters
def scopes
[]
end

def scopes
def filters
[]
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Add your component translations here.
# Use the translation in the example in your template with `t(".hello")`.
en:
give_feedback: 'Give feedback'
feedback_description_html: 'We are constantly trying to improve. <br>Please let us know what you think about this admin page.'
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# frozen_string_literal: true

# Account navigation
class SolidusAdmin::Layout::Navigation::Account::Component < SolidusAdmin::BaseComponent
# @param user_label [String]
# @param account_path [String]
# @param logout_path [String]
# @param logout_method [Symbol]
def initialize(user_label:, account_path:, logout_path:, logout_method:)
@user_label = user_label
@account_path = account_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# Renders the sidebar
class SolidusAdmin::Layout::Navigation::Component < SolidusAdmin::BaseComponent
def initialize(
store:,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

# Skip to content link
class SolidusAdmin::Layout::SkipLink::Component < SolidusAdmin::BaseComponent
# @param href [String] the href attribute for the skip link
def initialize(href:)
@href = href
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
<% end %>

<%= render component('ui/table').new(
id: 'option-types-list',
id: stimulus_id,
data: {
class: Spree::OptionType,
rows: @option_types,
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,
},
Expand Down
34 changes: 21 additions & 13 deletions admin/app/components/solidus_admin/option_types/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@
class SolidusAdmin::OptionTypes::Index::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers

def initialize(option_types:)
@option_types = option_types
def initialize(page:)
@page = page
end

def title
Spree::OptionType.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
[
{
display_name: t('.batch_actions.delete'),
action: solidus_admin.option_types_path,
method: :delete,
icon: 'delete-bin-7-line',
},
]
end

def columns
[
name_column,
Expand All @@ -35,15 +54,4 @@ def presentation_column
end
}
end

def batch_actions
[
{
display_name: t('.batch_actions.delete'),
action: solidus_admin.option_types_path,
method: :delete,
icon: 'delete-bin-7-line',
},
]
end
end
2 changes: 0 additions & 2 deletions admin/app/components/solidus_admin/orders/cart/component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Add your component translations here.
# Use the translation in the example in your template with `t(".hello")`.
en:
title: "Cart"
search_placeholder: "Find a variant by name or SKU"
21 changes: 9 additions & 12 deletions admin/app/components/solidus_admin/orders/index/component.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<div class="<%= stimulus_id %> px-4">
<header class="py-6 flex items-center">
<h1 class="font-semibold text-xl">
<%= title %>
</h1>

<div class="ml-auto flex gap-2 items-center">
<%= 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",
) %>
</div>
</header>
<% end %>
<% end %>

<%= render component('ui/table').new(
id: 'orders-list',
id: stimulus_id,
data: {
class: Spree::Order,
rows: @page.records,
Expand All @@ -31,8 +28,8 @@
value: params[:q],
searchbar_key: :number_or_shipments_number_or_bill_address_name_or_email_cont,
url: solidus_admin.orders_path(scope: params[:scope]),
filters: filters,
scopes: scopes,
filters: filters,
},
) %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions admin/app/components/solidus_admin/orders/index/component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class SolidusAdmin::Orders::Index::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers

def initialize(page:)
@page = page
end
Expand Down
2 changes: 0 additions & 2 deletions admin/app/components/solidus_admin/orders/index/component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Add your component translations here.
# Use the translation in the example in your template with `t(".hello")`.
en:
create_order: 'Create Order'
columns:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Add your component translations here.
# Use the translation in the example in your template with `t(".hello")`.
en:
save: Save
cancel: Cancel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
closeMenus() {
this.element.querySelectorAll('details').forEach(details => details.removeAttribute('open'));
this.element.querySelectorAll('details').forEach(details => details.removeAttribute('open'))
}
}
2 changes: 0 additions & 2 deletions admin/app/components/solidus_admin/orders/show/component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Add your component translations here.
# Use the translation in the example in your template with `t(".hello")`.
en:
save: Save
discard: Discard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def scopes
]
end

def filters
[]
end

def columns
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<% end %>

<%= render component('ui/table').new(
id: 'products-list',
id: stimulus_id,
data: {
class: Spree::Product,
rows: @page.records,
Expand All @@ -27,8 +27,8 @@
value: params[:q],
url: solidus_admin.products_path,
searchbar_key: :name_or_variants_including_master_sku_cont,
filters: filters,
scopes: scopes,
filters: filters,
},
) %>
<% end %>
22 changes: 11 additions & 11 deletions admin/app/components/solidus_admin/products/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ def batch_actions
]
end

def scopes
[
{ name: :all, label: t('.scopes.all'), default: true },
{ name: :in_stock, label: t('.scopes.in_stock') },
{ name: :out_of_stock, label: t('.scopes.out_of_stock') },
{ name: :available, label: t('.scopes.available') },
{ name: :discontinued, label: t('.scopes.discontinued') },
{ name: :deleted, label: t('.scopes.deleted') },
]
end

def filters
Spree::OptionType.all.map do |option_type|
{
Expand All @@ -54,17 +65,6 @@ def filters
end
end

def scopes
[
{ name: :all, label: t('.scopes.all'), default: true },
{ name: :in_stock, label: t('.scopes.in_stock') },
{ name: :out_of_stock, label: t('.scopes.out_of_stock') },
{ name: :available, label: t('.scopes.available') },
{ name: :discontinued, label: t('.scopes.discontinued') },
{ name: :deleted, label: t('.scopes.deleted') },
]
end

def columns
[
image_column,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
<% end %>

<%= render component('ui/table').new(
id: 'promotion-categories-list',
id: stimulus_id,
data: {
class: Spree::PromotionCategory,
rows: @promotion_categories,
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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@
class SolidusAdmin::PromotionCategories::Index::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::Layout::PageHelpers

def initialize(promotion_categories:)
@promotion_categories = promotion_categories
def initialize(page:)
@page = page
end

def title
Spree::PromotionCategory.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
[
{
display_name: t('.batch_actions.delete'),
action: solidus_admin.promotion_categories_path,
method: :delete,
icon: 'delete-bin-7-line',
},
]
end

def columns
[
name_column,
Expand All @@ -35,15 +54,4 @@ def code_column
end
}
end

def batch_actions
[
{
display_name: t('.batch_actions.delete'),
action: solidus_admin.promotion_categories_path,
method: :delete,
icon: 'delete-bin-7-line',
},
]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
value: params[:q],
url: solidus_admin.promotions_path,
searchbar_key: :name_or_codes_value_or_path_or_description_cont,
filters: filters,
scopes: scopes,
filters: filters,
},
) %>
<% end %>
Loading

0 comments on commit f1c4920

Please sign in to comment.