solidus_admin 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -7
- data/Rakefile +1 -0
- data/app/assets/builds/solidus_admin/tailwind.css +197 -162
- data/app/assets/stylesheets/solidus_admin/dark.css +1 -0
- data/app/assets/stylesheets/solidus_admin/dimmed.css +1 -0
- data/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +27 -0
- data/app/components/solidus_admin/adjustment_reasons/edit/component.rb +12 -0
- data/app/components/solidus_admin/adjustment_reasons/edit/component.yml +8 -0
- data/app/components/solidus_admin/adjustment_reasons/index/component.rb +26 -19
- data/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +28 -0
- data/app/components/solidus_admin/adjustment_reasons/new/component.rb +12 -0
- data/app/components/solidus_admin/adjustment_reasons/new/component.yml +8 -0
- data/app/components/solidus_admin/base_component.rb +4 -1
- data/app/components/solidus_admin/option_types/index/component.rb +21 -7
- data/app/components/solidus_admin/orders/index/component.rb +28 -23
- data/app/components/solidus_admin/orders/index/component.yml +1 -1
- data/app/components/solidus_admin/orders/show/address/component.html.erb +56 -54
- data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/component.rb +27 -0
- data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_line_item/component.rb +14 -0
- data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_order/component.rb +11 -0
- data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_shipment/component.rb +15 -0
- data/app/components/solidus_admin/orders/show/adjustments/index/component.rb +147 -0
- data/app/components/solidus_admin/orders/show/adjustments/index/component.yml +21 -0
- data/app/components/solidus_admin/orders/show/adjustments/index/source/component.rb +26 -0
- data/app/components/solidus_admin/orders/show/adjustments/index/source/spree_tax_rate/component.rb +17 -0
- data/app/components/solidus_admin/orders/show/adjustments/index/source/spree_unit_cancel/component.rb +7 -0
- data/app/components/solidus_admin/orders/show/component.html.erb +7 -3
- data/app/components/solidus_admin/orders/show/component.rb +8 -0
- data/app/components/solidus_admin/orders/show/email/component.html.erb +18 -13
- data/app/components/solidus_admin/orders/show/email/component.rb +0 -4
- data/app/components/solidus_admin/orders/show/summary/component.html.erb +1 -1
- data/app/components/solidus_admin/payment_methods/index/component.rb +29 -19
- data/app/components/solidus_admin/payment_methods/index/component.yml +0 -5
- data/app/components/solidus_admin/products/index/component.rb +25 -15
- data/app/components/solidus_admin/products/index/component.yml +0 -2
- data/app/components/solidus_admin/products/show/component.html.erb +14 -3
- data/app/components/solidus_admin/products/status/component.rb +4 -1
- data/app/components/solidus_admin/products/status/component.yml +1 -0
- data/app/components/solidus_admin/properties/index/component.rb +18 -19
- data/app/components/solidus_admin/refund_reasons/edit/component.html.erb +27 -0
- data/app/components/solidus_admin/refund_reasons/edit/component.rb +12 -0
- data/app/components/solidus_admin/refund_reasons/edit/component.yml +8 -0
- data/app/components/solidus_admin/refund_reasons/index/component.rb +26 -19
- data/app/components/solidus_admin/refund_reasons/new/component.html.erb +27 -0
- data/app/components/solidus_admin/refund_reasons/new/component.rb +12 -0
- data/app/components/solidus_admin/refund_reasons/new/component.yml +6 -0
- data/app/components/solidus_admin/refunds_and_returns/component.rb +33 -13
- data/app/components/solidus_admin/reimbursement_types/index/component.rb +7 -25
- data/app/components/solidus_admin/return_reasons/edit/component.html.erb +26 -0
- data/app/components/solidus_admin/return_reasons/edit/component.rb +12 -0
- data/app/components/solidus_admin/return_reasons/edit/component.yml +8 -0
- data/app/components/solidus_admin/return_reasons/index/component.rb +27 -19
- data/app/components/solidus_admin/return_reasons/new/component.html.erb +27 -0
- data/app/components/solidus_admin/return_reasons/new/component.rb +12 -0
- data/app/components/solidus_admin/return_reasons/new/component.yml +8 -0
- data/app/components/solidus_admin/roles/edit/component.html.erb +33 -0
- data/app/components/solidus_admin/roles/edit/component.rb +20 -0
- data/app/components/solidus_admin/roles/edit/component.yml +19 -0
- data/app/components/solidus_admin/roles/index/component.rb +70 -0
- data/app/components/solidus_admin/roles/index/component.yml +6 -0
- data/app/components/solidus_admin/roles/new/component.html.erb +33 -0
- data/app/components/solidus_admin/roles/new/component.rb +20 -0
- data/app/components/solidus_admin/roles/new/component.yml +19 -0
- data/app/components/solidus_admin/shipping/component.rb +23 -11
- data/app/components/solidus_admin/shipping_categories/edit/component.html.erb +16 -0
- data/app/components/solidus_admin/shipping_categories/edit/component.rb +12 -0
- data/app/components/solidus_admin/shipping_categories/edit/component.yml +6 -0
- data/app/components/solidus_admin/shipping_categories/index/component.rb +37 -20
- data/app/components/solidus_admin/shipping_categories/new/component.html.erb +17 -0
- data/app/components/solidus_admin/shipping_categories/new/component.rb +12 -0
- data/app/components/solidus_admin/shipping_categories/new/component.yml +6 -0
- data/app/components/solidus_admin/shipping_methods/index/component.rb +19 -19
- data/app/components/solidus_admin/stock_items/edit/component.html.erb +66 -72
- data/app/components/solidus_admin/stock_items/edit/component.rb +0 -5
- data/app/components/solidus_admin/stock_items/index/component.rb +13 -20
- data/app/components/solidus_admin/stock_locations/index/component.rb +19 -11
- data/app/components/solidus_admin/stock_locations/index/component.yml +0 -3
- data/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb +26 -0
- data/app/components/solidus_admin/store_credit_reasons/edit/component.rb +12 -0
- data/app/components/solidus_admin/store_credit_reasons/edit/component.yml +8 -0
- data/app/components/solidus_admin/store_credit_reasons/index/component.rb +26 -19
- data/app/components/solidus_admin/store_credit_reasons/new/component.html.erb +27 -0
- data/app/components/solidus_admin/store_credit_reasons/new/component.rb +12 -0
- data/app/components/solidus_admin/store_credit_reasons/new/component.yml +8 -0
- data/app/components/solidus_admin/stores/index/component.rb +18 -19
- data/app/components/solidus_admin/tax_categories/edit/component.html.erb +28 -0
- data/app/components/solidus_admin/tax_categories/edit/component.rb +12 -0
- data/app/components/solidus_admin/tax_categories/edit/component.yml +8 -0
- data/app/components/solidus_admin/tax_categories/index/component.rb +28 -21
- data/app/components/solidus_admin/tax_categories/new/component.html.erb +28 -0
- data/app/components/solidus_admin/tax_categories/new/component.rb +12 -0
- data/app/components/solidus_admin/tax_categories/new/component.yml +8 -0
- data/app/components/solidus_admin/tax_rates/index/component.rb +21 -17
- data/app/components/solidus_admin/taxes/component.rb +8 -8
- data/app/components/solidus_admin/taxonomies/index/component.rb +18 -12
- data/app/components/solidus_admin/ui/button/component.rb +1 -1
- data/app/components/solidus_admin/ui/checkbox_row/component.html.erb +29 -0
- data/app/components/solidus_admin/ui/checkbox_row/component.rb +11 -0
- data/app/components/solidus_admin/ui/forms/address/component.html.erb +27 -9
- data/app/components/solidus_admin/ui/forms/address/component.js +38 -13
- data/app/components/solidus_admin/ui/forms/search/component.html.erb +2 -3
- data/app/components/solidus_admin/ui/forms/search/component.js +3 -3
- data/app/components/solidus_admin/ui/modal/component.html.erb +7 -7
- data/app/components/solidus_admin/ui/modal/component.js +7 -0
- data/app/components/solidus_admin/ui/modal/component.rb +1 -1
- data/app/components/solidus_admin/ui/pages/index/component.html.erb +44 -0
- data/app/components/solidus_admin/ui/pages/index/component.rb +105 -0
- data/app/components/solidus_admin/ui/panel/component.html.erb +5 -16
- data/app/components/solidus_admin/ui/panel/component.rb +11 -7
- data/app/components/solidus_admin/ui/table/component.html.erb +2 -1
- data/app/components/solidus_admin/ui/table/component.js +31 -2
- data/app/components/solidus_admin/ui/table/component.rb +24 -8
- data/app/components/solidus_admin/ui/table/component.yml +1 -0
- data/app/components/solidus_admin/ui/thumbnail/component.rb +1 -1
- data/app/components/solidus_admin/ui/thumbnail_with_caption/component.html.erb +17 -0
- data/app/components/solidus_admin/ui/thumbnail_with_caption/component.rb +15 -0
- data/app/components/solidus_admin/users/addresses/component.html.erb +46 -0
- data/app/components/solidus_admin/users/addresses/component.rb +61 -0
- data/app/components/solidus_admin/users/addresses/component.yml +14 -0
- data/app/components/solidus_admin/users/edit/api_access/component.html.erb +49 -0
- data/app/components/solidus_admin/users/edit/api_access/component.js +9 -0
- data/app/components/solidus_admin/users/edit/api_access/component.rb +7 -0
- data/app/components/solidus_admin/users/edit/api_access/component.yml +10 -0
- data/app/components/solidus_admin/users/edit/component.html.erb +52 -0
- data/app/components/solidus_admin/users/edit/component.rb +51 -0
- data/app/components/solidus_admin/users/edit/component.yml +12 -0
- data/app/components/solidus_admin/users/index/component.rb +25 -16
- data/app/components/solidus_admin/users/index/component.yml +0 -3
- data/app/components/solidus_admin/users/items/component.html.erb +41 -0
- data/app/components/solidus_admin/users/items/component.rb +170 -0
- data/app/components/solidus_admin/users/items/component.yml +16 -0
- data/app/components/solidus_admin/users/orders/component.html.erb +42 -0
- data/app/components/solidus_admin/users/orders/component.rb +131 -0
- data/app/components/solidus_admin/users/orders/component.yml +12 -0
- data/app/components/solidus_admin/users/stats/component.html.erb +11 -0
- data/app/components/solidus_admin/users/stats/component.rb +9 -0
- data/app/components/solidus_admin/users/stats/component.yml +2 -0
- data/app/components/solidus_admin/users_and_roles/component.rb +24 -0
- data/app/components/solidus_admin/users_and_roles/component.yml +2 -0
- data/app/components/solidus_admin/zones/index/component.rb +19 -11
- data/app/controllers/solidus_admin/addresses_controller.rb +6 -1
- data/app/controllers/solidus_admin/adjustment_reasons_controller.rb +85 -10
- data/app/controllers/solidus_admin/adjustments_controller.rb +57 -0
- data/app/controllers/solidus_admin/customers_controller.rb +5 -1
- data/app/controllers/solidus_admin/orders_controller.rb +5 -1
- data/app/controllers/solidus_admin/products_controller.rb +11 -0
- data/app/controllers/solidus_admin/properties_controller.rb +1 -1
- data/app/controllers/solidus_admin/refund_reasons_controller.rb +85 -10
- data/app/controllers/solidus_admin/reimbursement_types_controller.rb +0 -5
- data/app/controllers/solidus_admin/return_reasons_controller.rb +85 -10
- data/app/controllers/solidus_admin/roles_controller.rb +118 -0
- data/app/controllers/solidus_admin/shipping_categories_controller.rb +87 -10
- data/app/controllers/solidus_admin/shipping_methods_controller.rb +0 -5
- data/app/controllers/solidus_admin/stock_items_controller.rb +6 -6
- data/app/controllers/solidus_admin/stock_locations_controller.rb +0 -5
- data/app/controllers/solidus_admin/store_credit_reasons_controller.rb +85 -10
- data/app/controllers/solidus_admin/stores_controller.rb +0 -5
- data/app/controllers/solidus_admin/tax_categories_controller.rb +89 -10
- data/app/controllers/solidus_admin/tax_rates_controller.rb +0 -5
- data/app/controllers/solidus_admin/users_controller.rb +85 -6
- data/app/controllers/solidus_admin/zones_controller.rb +0 -5
- data/app/helpers/solidus_admin/last_login_helper.rb +16 -0
- data/app/helpers/solidus_admin/permission_sets_helper.rb +32 -0
- data/app/views/layouts/solidus_admin/application.html.erb +2 -1
- data/app/views/layouts/solidus_admin/preview.html.erb +2 -0
- data/config/initializers/view_component.rb +1 -1
- data/config/locales/adjustment_reasons.en.yml +5 -1
- data/config/locales/adjustments.en.yml +10 -0
- data/config/locales/refund_reasons.en.yml +10 -0
- data/config/locales/return_reasons.en.yml +5 -1
- data/config/locales/roles.en.yml +10 -0
- data/config/locales/shipping_categories.en.yml +4 -0
- data/config/locales/store_credit_reasons.en.yml +5 -1
- data/config/locales/tax_categories.en.yml +4 -0
- data/config/locales/users.en.yml +10 -0
- data/config/routes.rb +24 -7
- data/docs/components.md +109 -0
- data/docs/{customizing_view_components.md → customizing_components.md} +2 -7
- data/docs/index_pages.md +146 -0
- data/docs/{customizing_menu_items.md → menu_items.md} +1 -1
- data/docs/stimulusjs.md +85 -0
- data/docs/{customizing_tailwindcss.md → tailwindcss.md} +27 -8
- data/lib/solidus_admin/component_registry.rb +40 -0
- data/lib/solidus_admin/configuration.rb +5 -27
- data/lib/solidus_admin/install_tailwindcss.rb +3 -1
- data/lib/solidus_admin/testing_support/admin_assets.rb +10 -0
- data/lib/solidus_admin/testing_support/component_helpers.rb +27 -0
- data/lib/solidus_admin/testing_support/dummy_app/rake_tasks.rb +60 -0
- data/lib/solidus_admin/testing_support/feature_helpers.rb +34 -0
- data/lib/solidus_admin/version.rb +1 -1
- data/solidus_admin.gemspec +7 -3
- metadata +111 -59
- data/app/components/solidus_admin/adjustment_reasons/index/component.html.erb +0 -32
- data/app/components/solidus_admin/adjustment_reasons/index/component.yml +0 -4
- data/app/components/solidus_admin/option_types/index/component.html.erb +0 -30
- data/app/components/solidus_admin/orders/index/component.html.erb +0 -35
- data/app/components/solidus_admin/payment_methods/index/component.html.erb +0 -38
- data/app/components/solidus_admin/products/index/component.html.erb +0 -34
- data/app/components/solidus_admin/promotion_categories/index/component.html.erb +0 -26
- data/app/components/solidus_admin/promotion_categories/index/component.rb +0 -57
- data/app/components/solidus_admin/promotion_categories/index/component.yml +0 -4
- data/app/components/solidus_admin/promotions/index/component.html.erb +0 -34
- data/app/components/solidus_admin/promotions/index/component.rb +0 -97
- data/app/components/solidus_admin/promotions/index/component.yml +0 -14
- data/app/components/solidus_admin/properties/index/component.html.erb +0 -34
- data/app/components/solidus_admin/properties/index/component.yml +0 -4
- data/app/components/solidus_admin/refund_reasons/index/component.html.erb +0 -31
- data/app/components/solidus_admin/refund_reasons/index/component.yml +0 -4
- data/app/components/solidus_admin/refunds_and_returns/component.html.erb +0 -26
- data/app/components/solidus_admin/reimbursement_types/index/component.html.erb +0 -22
- data/app/components/solidus_admin/reimbursement_types/index/component.yml +0 -4
- data/app/components/solidus_admin/return_reasons/index/component.html.erb +0 -31
- data/app/components/solidus_admin/return_reasons/index/component.yml +0 -4
- data/app/components/solidus_admin/shipping/component.html.erb +0 -30
- data/app/components/solidus_admin/shipping_categories/index/component.html.erb +0 -32
- data/app/components/solidus_admin/shipping_categories/index/component.yml +0 -4
- data/app/components/solidus_admin/shipping_methods/index/component.html.erb +0 -32
- data/app/components/solidus_admin/shipping_methods/index/component.yml +0 -4
- data/app/components/solidus_admin/stock_items/index/component.html.erb +0 -26
- data/app/components/solidus_admin/stock_locations/index/component.html.erb +0 -32
- data/app/components/solidus_admin/store_credit_reasons/index/component.html.erb +0 -31
- data/app/components/solidus_admin/store_credit_reasons/index/component.yml +0 -4
- data/app/components/solidus_admin/stores/index/component.html.erb +0 -34
- data/app/components/solidus_admin/stores/index/component.yml +0 -4
- data/app/components/solidus_admin/tax_categories/index/component.html.erb +0 -32
- data/app/components/solidus_admin/tax_categories/index/component.yml +0 -6
- data/app/components/solidus_admin/tax_rates/index/component.html.erb +0 -32
- data/app/components/solidus_admin/tax_rates/index/component.yml +0 -4
- data/app/components/solidus_admin/taxes/component.html.erb +0 -24
- data/app/components/solidus_admin/taxonomies/index/component.html.erb +0 -28
- data/app/components/solidus_admin/taxonomies/index/component.yml +0 -4
- data/app/components/solidus_admin/users/index/component.html.erb +0 -34
- data/app/components/solidus_admin/zones/index/component.html.erb +0 -35
- data/app/components/solidus_admin/zones/index/component.yml +0 -4
- data/app/controllers/solidus_admin/promotion_categories_controller.rb +0 -38
- data/app/controllers/solidus_admin/promotions_controller.rb +0 -46
- data/config/locales/promotion_categories.en.yml +0 -6
- data/config/locales/promotions.en.yml +0 -6
- data/config/locales/refund_reasons_.en.yml +0 -6
- /data/app/components/solidus_admin/{option_types → ui/pages}/index/component.yml +0 -0
@@ -3,4 +3,8 @@ en:
|
|
3
3
|
return_reasons:
|
4
4
|
title: "Return Reasons"
|
5
5
|
destroy:
|
6
|
-
success: "Return
|
6
|
+
success: "Return reasons were successfully removed."
|
7
|
+
create:
|
8
|
+
success: "Return reason was successfully created."
|
9
|
+
update:
|
10
|
+
success: "Return reason was successfully updated."
|
@@ -3,4 +3,8 @@ en:
|
|
3
3
|
store_credit_reasons:
|
4
4
|
title: "Store Credit Reasons"
|
5
5
|
destroy:
|
6
|
-
success: "Store
|
6
|
+
success: "Store credit reasons were successfully removed."
|
7
|
+
create:
|
8
|
+
success: "Store credit reason was successfully created."
|
9
|
+
update:
|
10
|
+
success: "Store credit reason was successfully updated."
|
data/config/locales/users.en.yml
CHANGED
@@ -4,3 +4,13 @@ en:
|
|
4
4
|
title: "Users"
|
5
5
|
destroy:
|
6
6
|
success: "Users were successfully removed."
|
7
|
+
update_addresses:
|
8
|
+
bill:
|
9
|
+
success: "Billing Address has been successfully updated."
|
10
|
+
ship:
|
11
|
+
success: "Shipping Address has been successfully updated."
|
12
|
+
error: "Address could not be updated."
|
13
|
+
last_login:
|
14
|
+
never: "Never"
|
15
|
+
login_time_ago: "%{last_login_time} ago"
|
16
|
+
invitation_sent: "Invitation sent"
|
data/config/routes.rb
CHANGED
@@ -26,6 +26,14 @@ SolidusAdmin::Engine.routes.draw do
|
|
26
26
|
admin_resources :orders, except: [
|
27
27
|
:destroy, :index
|
28
28
|
], constraints: ->{ SolidusAdmin::Config.enable_alpha_features? } do
|
29
|
+
resources :adjustments, only: [:index] do
|
30
|
+
collection do
|
31
|
+
delete :destroy
|
32
|
+
put :lock
|
33
|
+
put :unlock
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
resources :line_items, only: [:destroy, :create, :update]
|
30
38
|
resource :customer
|
31
39
|
resource :ship_address, only: [:show, :edit, :update], controller: "addresses", type: "ship"
|
@@ -37,24 +45,33 @@ SolidusAdmin::Engine.routes.draw do
|
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
40
|
-
admin_resources :users, only: [:index, :destroy]
|
48
|
+
admin_resources :users, only: [:index, :edit, :destroy] do
|
49
|
+
member do
|
50
|
+
get :addresses
|
51
|
+
put :update_addresses
|
52
|
+
get :orders
|
53
|
+
get :items
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
41
57
|
admin_resources :promotions, only: [:index, :destroy]
|
42
58
|
admin_resources :properties, only: [:index, :destroy]
|
43
59
|
admin_resources :option_types, only: [:index, :destroy], sortable: true
|
44
60
|
admin_resources :taxonomies, only: [:index, :destroy], sortable: true
|
45
61
|
admin_resources :promotion_categories, only: [:index, :destroy]
|
46
|
-
admin_resources :tax_categories,
|
62
|
+
admin_resources :tax_categories, except: [:show]
|
47
63
|
admin_resources :tax_rates, only: [:index, :destroy]
|
48
64
|
admin_resources :payment_methods, only: [:index, :destroy], sortable: true
|
49
65
|
admin_resources :stock_items, only: [:index, :edit, :update]
|
50
66
|
admin_resources :shipping_methods, only: [:index, :destroy]
|
51
|
-
admin_resources :shipping_categories,
|
67
|
+
admin_resources :shipping_categories, except: [:show]
|
52
68
|
admin_resources :stock_locations, only: [:index, :destroy]
|
53
69
|
admin_resources :stores, only: [:index, :destroy]
|
54
70
|
admin_resources :zones, only: [:index, :destroy]
|
55
|
-
admin_resources :refund_reasons,
|
71
|
+
admin_resources :refund_reasons, except: [:show]
|
56
72
|
admin_resources :reimbursement_types, only: [:index]
|
57
|
-
admin_resources :return_reasons,
|
58
|
-
admin_resources :
|
59
|
-
admin_resources :
|
73
|
+
admin_resources :return_reasons, except: [:show]
|
74
|
+
admin_resources :roles, except: [:show]
|
75
|
+
admin_resources :adjustment_reasons, except: [:show]
|
76
|
+
admin_resources :store_credit_reasons, except: [:show]
|
60
77
|
end
|
data/docs/components.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Components
|
2
|
+
|
3
|
+
Components are the main building blocks of the admin interface. They are implemented as ViewComponents and are rendered directly by controllers.
|
4
|
+
|
5
|
+
The following documentation assumes familiariry with ViewComponents. If you are not please refer to the [ViewComponent documentation](https://viewcomponent.org/guide/).
|
6
|
+
|
7
|
+
There are two types of components:
|
8
|
+
|
9
|
+
- **UI components** are the building blocks of the interface. Tipically, they are small components that are used to build more complex components and are generic enough to be reused in various contexts. UI components are located under the `app/components/solidus_admin/ui` folder.
|
10
|
+
- **Page components** are the primary components rendered by the controllers. Generally, they are full-page components rendered directly by the controllers. They are located under the `app/components/solidus_admin` directory following the naming convention of the controller and action names they are used in. For example `app/components/solidus_admin/orders/index/component.rb` is the component that is rendered by the `SolidusAdmin::OrdersController#index` action.
|
11
|
+
|
12
|
+
## Generating components
|
13
|
+
|
14
|
+
Components can be generated using the `solidus_admin:component` generator combined with the `bin/rails` command from the Solidus repository.
|
15
|
+
|
16
|
+
```shell
|
17
|
+
$ bin/rails admin g solidus_admin:component foo
|
18
|
+
create app/components/solidus_admin/foo/component.rb
|
19
|
+
create app/components/solidus_admin/foo/component.html.erb
|
20
|
+
create app/components/solidus_admin/foo/component.yml
|
21
|
+
create app/components/solidus_admin/foo/component.js
|
22
|
+
```
|
23
|
+
|
24
|
+
Using `bin/rails admin` will run the generator from the `solidus_admin` engine, instead of the sandbox application.
|
25
|
+
|
26
|
+
## Coding style
|
27
|
+
|
28
|
+
For UI components in particular, it's preferable to accept only simple Ruby values in the initializer and use alternative constructors to accept more complex objects. This makes components easier to use and test. For example:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# bad
|
32
|
+
|
33
|
+
class SolidusAdmin::UI::OrderStatus::Component < ViewComponent::Base
|
34
|
+
def initialize(order:)
|
35
|
+
@order = order
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# good
|
40
|
+
|
41
|
+
class SolidusAdmin::UI::OrderStatus::Component < ViewComponent::Base
|
42
|
+
def initialize(status:)
|
43
|
+
@status = status
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.for_order(order)
|
47
|
+
new(status: order.status)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
For style variations within the component we use the term `scheme` rather than `variant` to avoid confusion with product variants.
|
53
|
+
|
54
|
+
For size variations we use the term `size` with single letter values, e.g. `s`, `m`, `l`, `xl`, `xxl`.
|
55
|
+
|
56
|
+
For text content we use the term `text` rather than `name` to avoid confusion with the `name` attribute of the HTML tag.
|
57
|
+
|
58
|
+
## Component registry
|
59
|
+
|
60
|
+
Components are registered in the `SolidusAdmin::Config.components` registry. This allows replacing components for customization purposes and components deprecation between versions.
|
61
|
+
|
62
|
+
To retrieve component classes from the registry, use the `component` helper within controllers and components that inherit from `SolidusAdmin::BaseComponent` or include `SolidusAdmin::ComponentHelper`. For example, `component('ui/button')` will fetch `SolidusAdmin::UI::Button::Component`.
|
63
|
+
|
64
|
+
## When to use UI vs. Page components
|
65
|
+
|
66
|
+
Generally new components are built for a specific controller action and are used only within that action. In such cases, it's better to use a Page component and define it under the namespace of the action, e.g. `app/components/solidus_admin/orders/index/payment_status/component.rb`.
|
67
|
+
|
68
|
+
If a component is used by multiple actions of the same controller it can be moved to the controller namespace, e.g. `app/components/solidus_admin/orders/payment_status/component.rb`.
|
69
|
+
|
70
|
+
When a component is used by multiple controllers, you can either duplicate it in multiple places or move it to the `ui` namespace.
|
71
|
+
|
72
|
+
Although it may seem counterintuitive, duplicating the component can often be beneficial. This allows you to modify the component in one place without affecting other components that might be using it. Over time, the two copies may share enough generic code that it can be extracted into a UI component.
|
73
|
+
|
74
|
+
UI components should be very generic and reusable. However, they should not try to anticipate all possible use cases. Instead, they should be extracted from existing components that are already used in multiple places. This has proven to be the most effective way to build UI components. We've found that trying to anticipate theoretical use cases often leads to over-engineered code that eventually needs to be adapted to the actual use cases or is never used at all.
|
75
|
+
|
76
|
+
## Naming conventions
|
77
|
+
|
78
|
+
The project uses a naming convention for components that slightly deviates from ViewComponent defaults. This is done to simplify renaming components and moving them around.
|
79
|
+
|
80
|
+
All files related to a component have a base name of `component`, each with its own extension. These files are placed in a folder named after the component class they define.
|
81
|
+
|
82
|
+
|
83
|
+
E.g. `app/components/solidus_admin/orders/index/payment_status/component.rb` defines the `SolidusAdmin::Orders::Index::PaymentStatus::Component` class.
|
84
|
+
|
85
|
+
With this approach, renaming a component is as simple as renaming the folder and the class name, without the need to change the names of all the files.
|
86
|
+
|
87
|
+
## Translations
|
88
|
+
|
89
|
+
Components can define their own translations in the `component.yml` file and they're expected to be self contained. This means that translations defined in `solidus_core` should not be used in components.
|
90
|
+
|
91
|
+
Please refer to the [ViewComponent documentation](https://viewcomponent.org/guide/translations.html) for more information.
|
92
|
+
|
93
|
+
## Previews and Lookbook
|
94
|
+
|
95
|
+
For UI components we leverage [ViewComponent previews](https://viewcomponent.org/guide/previews.html) combined with [Lookbook](https://lookbook.build) to provide a live preview of the component. This approach is highly beneficial for understanding the component's appearance and how it can be modified using different arguments.
|
96
|
+
|
97
|
+
Creating previews for page components can be challenging and prone to errors, as they often require a more complex context for rendering. Therefore, we typically don't use previews for page components, except for the most basic ones. However, if a component has a wide range of arguments and we want to cover all combinations, we might create a preview for it.
|
98
|
+
|
99
|
+
In order to inspect previews it's enough to visit `/lookbook` in the browser while the server is running.
|
100
|
+
|
101
|
+
## Testing
|
102
|
+
|
103
|
+
Testing methods for components vary depending on whether they are UI or Page components. UI components are tested in isolation, while Page components, which often require a more complex context, are tested through feature specs.
|
104
|
+
|
105
|
+
For UI components, we use previews to achieve maximum coverage. This approach is sufficient for most basic components, but more complex components may require additional specs. This method has proven to minimize maintenance and code churn in the spec code, and it avoids repeating the code needed to render the component with different arguments.
|
106
|
+
|
107
|
+
Page components are tested in the context of the controller action they are used in. For example, `admin/spec/features/orders_spec.rb` covers interactions with the order listing and indirectly tests the `SolidusAdmin::Orders::Index::Component` class, among others.
|
108
|
+
We've found this to be the most effective way to test page components, as recreating the context needed for them in isolation can be difficult and prone to errors.
|
109
|
+
However, this is not a hard rule. If a Page component needs to be tested in isolation, or if a UI component requires a more complex context, you can always write additional specs.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Customizing
|
1
|
+
# Customizing components
|
2
2
|
|
3
3
|
Solidus Admin uses [view components](https://viewcomponent.org/) to render the views. Components are
|
4
4
|
a pattern for breaking up the view layer into small, reusable pieces, easy to
|
@@ -100,14 +100,9 @@ end
|
|
100
100
|
If you need more control, you can explicitly register your component in the
|
101
101
|
Solidus Admin container instead of using an implicit path:
|
102
102
|
|
103
|
-
> ⓘ Right now, that will raise an error when the application is reloaded. We
|
104
|
-
> need to fix it.
|
105
|
-
|
106
103
|
```ruby
|
107
104
|
# config/initalizers/solidus_admin.rb
|
108
|
-
|
109
|
-
SolidusAdmin::Config.components['ui/button'] = MyApplication::Button::Component
|
110
|
-
end
|
105
|
+
SolidusAdmin::Config.components['ui/button'] = "MyApplication::Button::Component"
|
111
106
|
```
|
112
107
|
|
113
108
|
### Tweaking a component
|
data/docs/index_pages.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Adding index pages
|
2
|
+
|
3
|
+
Index pages are common in the admin interface, and they are used to display a list of records for a specific model.
|
4
|
+
|
5
|
+
Since these pages often have a similar appearance, we have a dedicated component to build them. This component helps avoid writing repetitive boilerplate code.
|
6
|
+
|
7
|
+
## The `index` action
|
8
|
+
|
9
|
+
The `index` action is the standard action used to display index pages. It's a standard `GET` action that renders the `index` component.
|
10
|
+
|
11
|
+
To support search scopes and filters the controller should include the `SolidusAdmin::ControllerHelpers::Search` module and call
|
12
|
+
`apply_search_to` as follows:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
class SolidusAdmin::UsersController < SolidusAdmin::BaseController
|
16
|
+
include SolidusAdmin::ControllerHelpers::Search
|
17
|
+
|
18
|
+
def index
|
19
|
+
users = apply_search_to(Spree.user_class.order(id: :desc), param: :q)
|
20
|
+
# ...
|
21
|
+
```
|
22
|
+
|
23
|
+
For pagination support, the index action should also call the `set_page_and_extract_portion_from` method provided by the `geared_pagination` gem. This method sets the `@page` instance variable to the paginated collection and returns the portion of the collection to be displayed on the current page.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
def index
|
27
|
+
users = apply_search_to(Spree.user_class.order(id: :desc), param: :q)
|
28
|
+
set_page_and_extract_portion_from(users)
|
29
|
+
# ...
|
30
|
+
```
|
31
|
+
|
32
|
+
Finally, the index action should render the `index` component passing the `@page` instance variable as the `collection` prop.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
def index
|
36
|
+
users = apply_search_to(Spree.user_class.order(id: :desc), param: :q)
|
37
|
+
set_page_and_extract_portion_from(users)
|
38
|
+
render component('users/index').new(page: @page)
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
## The `ui/pages/index` component
|
43
|
+
|
44
|
+
The `ui/pages/index` component is an abstract component that provides sensible defaults for index pages. It also offers template methods that can be used to customize the behavior of these pages.
|
45
|
+
|
46
|
+
We recommend examining existing index pages and the UI component itself to understand how they work. In this section, we'll cover the most important aspects.
|
47
|
+
|
48
|
+
The index component requires only the `page` argument during initialization, all other parameters are provided through template methods.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
class SolidusAdmin::Users::Index < Solidus::Admin::UI::Pages::Index
|
52
|
+
def model_class
|
53
|
+
Spree.user_class
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
render component('users/index').new(page: @page)
|
58
|
+
```
|
59
|
+
|
60
|
+
## Batch Actions
|
61
|
+
|
62
|
+
Batch actions are operations that can be performed on multiple records simultaneously. The index page internally uses the `ui/table` component and depends on the `batch_actions` method to render the batch actions dropdown.
|
63
|
+
|
64
|
+
In the component, batch actions are provided as an array of hashes, with each hash representing a single batch action. Each hash must contain the following keys:
|
65
|
+
|
66
|
+
- `label`: the name of the batch action, this will be used as the label of the dropdown item
|
67
|
+
- `icon`: the remix icon-name to be used as the icon of the dropdown item (see the `ui/icon` component for more information)
|
68
|
+
- `action`: the name of the action to be performed when the batch action is selected. It can be a URL or a path
|
69
|
+
- `method`: the HTTP method to be used when performing the action, such as `:delete`
|
70
|
+
|
71
|
+
The `batch_actions` method is called in the context of the controller, so you can use any controller method or helper to build the batch actions.
|
72
|
+
|
73
|
+
Batch actions will be submitted to the specified action with an `id` parameter containing the IDs of the selected records. Using `id` as the
|
74
|
+
parameter name allows the same action to support both batch and single-record actions for standard routes.
|
75
|
+
|
76
|
+
E.g.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
# in the component
|
80
|
+
def batch_actions
|
81
|
+
[
|
82
|
+
{
|
83
|
+
label: "Delete",
|
84
|
+
icon: "trash",
|
85
|
+
action: solidus_admin.delete_admin_users_path,
|
86
|
+
method: :delete
|
87
|
+
}
|
88
|
+
]
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
# in the controller
|
94
|
+
def delete
|
95
|
+
@users = Spree.user_class.where(id: params[:id])
|
96
|
+
@users.destroy_all
|
97
|
+
flash[:success] = "Admin users deleted"
|
98
|
+
redirect_to solidus_admin.users_path, status: :see_other
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
## Search Scopes
|
103
|
+
|
104
|
+
Search scopes are used to filter the records displayed on the index page. The index page internally uses the `ui/table` component and relies on the `scopes` method to render the search scope buttons.
|
105
|
+
|
106
|
+
In the component, search scopes are provided as an array of hashes, with each hash representing a single search scope. Each hash must contain the following keys:
|
107
|
+
|
108
|
+
- `label`: the name of the search scope, used as the label of the button
|
109
|
+
- `name`: the name of the search scope, sent via `q[scope]` parameter when the button is clicked
|
110
|
+
- `default`: whether this is the default search scope, used to highlight the button when when the page is loaded
|
111
|
+
|
112
|
+
On the controller side, search scopes can be defined with the `search_scope` helper, provided by `SolidusAdmin::ControllerHelpers::Search`. This helper takes a name, an optional `default` keyword argument, and a block. The block will be called with the current scope and should return a new ActiveRecord scope.
|
113
|
+
E.g.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
module SolidusAdmin
|
117
|
+
class UsersController < SolidusAdmin::BaseController
|
118
|
+
include SolidusAdmin::ControllerHelpers::Search
|
119
|
+
|
120
|
+
search_scope(:customers, default: true) { _1.left_outer_joins(:role_users).where(role_users: { id: nil }) }
|
121
|
+
search_scope(:admin) { _1.joins(:role_users).distinct }
|
122
|
+
search_scope(:with_orders) { _1.joins(:orders).distinct }
|
123
|
+
search_scope(:without_orders) { _1.left_outer_joins(:orders).where(orders: { id: nil }) }
|
124
|
+
search_scope(:all)
|
125
|
+
|
126
|
+
def index
|
127
|
+
users = apply_search_to(Spree.user_class.order(id: :desc), param: :q)
|
128
|
+
# ...
|
129
|
+
```
|
130
|
+
|
131
|
+
## Filters
|
132
|
+
|
133
|
+
Filters are used to narrow down the records displayed on the index page. The index page internally uses the `ui/table/ransack_filter` component and depends on the `filters` method to render the filters dropdown.
|
134
|
+
|
135
|
+
In the component, filters are represented as an array of hashes, with each hash representing a single filter. Each hash must contain the following keys:
|
136
|
+
|
137
|
+
|
138
|
+
- `label`: the name of the filter, used as the label in the filter bar
|
139
|
+
- `attribute`: the name of the ransack-enabled attribute to be filtered
|
140
|
+
- `predicate`: the name of the ransack predicate to be used, e.g. `eq`, `in`, `cont`
|
141
|
+
- `options`: an array of options to be used for the filter, in the standard rails form of `[["label", "value"], ...]`
|
142
|
+
|
143
|
+
On the controller side it's enough to add ransack support to the index action by including `SolidusAdmin::ControllerHelpers::Search` and calling
|
144
|
+
`apply_search_to` as explained in the [Index action](#index-action) section.
|
145
|
+
|
146
|
+
On the controller side, you simply need to add Ransack support to the index action by including the `SolidusAdmin::ControllerHelpers::Search` module and calling the `apply_search_to` method, as explained in the [Index action](#index-action) section.
|
data/docs/stimulusjs.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# StimulusJS
|
2
|
+
|
3
|
+
This project uses [StimulusJS](https://stimulusjs.org) to add interactivity to the admin interface.
|
4
|
+
|
5
|
+
## Using ther `stimulus_id` helper
|
6
|
+
|
7
|
+
All JavaScript files are imported using `import-maps`, eliminating the need for compilation.
|
8
|
+
|
9
|
+
Any `component.js` file is automatically loaded as a StimulusJS controller. The component path is used as the identifier, which is achieved by using `parameterize` and replacing `/` with `--`.
|
10
|
+
For example, `app/components/solidus_admin/foo/component.js` is loaded as `solidus-admin--foo`..
|
11
|
+
|
12
|
+
To simplify the use of StimulusJS controllers in components, a `stimulus_id` helper is provided.
|
13
|
+
This helper ensures that the controller identifier is correctly used every time.
|
14
|
+
|
15
|
+
```erb
|
16
|
+
<div
|
17
|
+
data-controller="<%= stimulus_id %>"
|
18
|
+
data-action="click-><%= stimulus_id %>#doSomething"
|
19
|
+
data-<%= stimulus_id %>-foo-value="123"
|
20
|
+
>
|
21
|
+
...
|
22
|
+
</div>
|
23
|
+
```
|
24
|
+
|
25
|
+
## Coding Style
|
26
|
+
|
27
|
+
Besides the standard StimulusJS conventions, we have a few additional tricks to make the code more readable and maintainable.
|
28
|
+
|
29
|
+
### Separating the state from the DOM
|
30
|
+
|
31
|
+
Whenever the controller gets beyond trivial we try to separate the state from DOM updates using a `render()` method.
|
32
|
+
|
33
|
+
```js
|
34
|
+
import { Controller } from "stimulus"
|
35
|
+
|
36
|
+
export default class extends Controller {
|
37
|
+
static targets = [ "details" ]
|
38
|
+
|
39
|
+
connect() {
|
40
|
+
this.render()
|
41
|
+
}
|
42
|
+
|
43
|
+
show() {
|
44
|
+
this.open = true
|
45
|
+
}
|
46
|
+
|
47
|
+
render() {
|
48
|
+
this.detailsTarget.hidden = !this.open
|
49
|
+
}
|
50
|
+
}
|
51
|
+
```
|
52
|
+
|
53
|
+
### Using values to communicate with the external world
|
54
|
+
|
55
|
+
Values are an excellent tool for communicating with the external environment and representing state.
|
56
|
+
Any change to them will be reflected in the DOM and the change callbacks provided by StimulusJS are a great way to react to state changes.
|
57
|
+
|
58
|
+
```js
|
59
|
+
import { Controller } from "stimulus"
|
60
|
+
|
61
|
+
export default class extends Controller {
|
62
|
+
static values = { open: Boolean }
|
63
|
+
|
64
|
+
connect() {
|
65
|
+
this.render()
|
66
|
+
}
|
67
|
+
|
68
|
+
show() {
|
69
|
+
this.openValue = true
|
70
|
+
}
|
71
|
+
|
72
|
+
openValueChanged() {
|
73
|
+
this.render()
|
74
|
+
}
|
75
|
+
|
76
|
+
render() {
|
77
|
+
this.detailsTarget.hidden = !this.openValue
|
78
|
+
}
|
79
|
+
}
|
80
|
+
```
|
81
|
+
|
82
|
+
## Leveraging stimulus-use
|
83
|
+
|
84
|
+
Solidus Admin leverages [stimulus-use](https://github.com/stimulus-use/stimulus-use/), an external library that offers a collection of composable behaviors for Stimulus Controllers. These mixins greatly simplify the work of developers and can be used when adding new components.
|
85
|
+
For more information, please refer to the project doc. You can also find examples of usage in the Admin codebase (for instance, `useClickOutside` and `useDebounce` mixins are used in admin components).
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Tailwind CSS for the Admin UI
|
2
2
|
|
3
3
|
Solidus Admin uses [Tailwind CSS](https://tailwindcss.com/) for styling. The
|
4
4
|
benefit of using Tailwind is that it allows you to customize the look and feel
|
@@ -12,11 +12,28 @@ In case you need to customize the admin's look and feel, or create custom
|
|
12
12
|
components, you can do so by running Tailwind's build process in your host
|
13
13
|
application.
|
14
14
|
|
15
|
-
This process presumes that you have a working knowledge of Tailwind CSS.
|
16
|
-
are not familiar with Tailwind, please refer to the [Tailwind
|
17
|
-
documentation](https://tailwindcss.com/docs) for more information.
|
15
|
+
This process presumes that you have a working knowledge of Tailwind CSS.
|
16
|
+
If you are not familiar with Tailwind, please refer to the [Tailwind documentation](https://tailwindcss.com/docs) for more information.
|
18
17
|
|
19
|
-
##
|
18
|
+
## Coding Style
|
19
|
+
|
20
|
+
The provided Tailwind CSS configuration is as vanilla as possible, with little to no customizations.
|
21
|
+
We aim to stay within the boundaries of the default Tailwind CSS classes and avoid custom classes.
|
22
|
+
Occasionally, we need to add custom styles and in such cases we try to use dynamic square brackets classes.
|
23
|
+
|
24
|
+
CSS classes are all kept in the HTML templates of the components in order to simplify the configuration.
|
25
|
+
|
26
|
+
The few customizations we have added, are through plugins as they support not only classes but also variants.
|
27
|
+
|
28
|
+
## Releasing with a precompiled Tailwind CSS
|
29
|
+
|
30
|
+
Solidus Admin Tailwind CSS stylesheets are precompiled and included in Solidus gems released to Rubygems.
|
31
|
+
|
32
|
+
This means that there's no need to compile the admin Tailwind CSS file in the host application.
|
33
|
+
|
34
|
+
The compiled file is not included in the git repository, but it is generated and incorporated in the gem as part of the `rake release` task (see releasing instructions). This approach completely removes the potential noise created by committing that file to the repository, and the need to keep it updated in pull requests that should affect it.
|
35
|
+
|
36
|
+
## Customizing TailwindCSS
|
20
37
|
|
21
38
|
In order to customize the admin's look and feel, you'll need to set up a local
|
22
39
|
Tailwind build. This is a two-step process:
|
@@ -48,10 +65,12 @@ Or, to watch for changes and automatically rebuild the CSS file, run:
|
|
48
65
|
bin/rails solidus_admin:tailwindcss:watch
|
49
66
|
```
|
50
67
|
|
51
|
-
##
|
52
|
-
|
53
|
-
### Conflict with sassc-rails
|
68
|
+
## Caveat: Conflict with sassc-rails
|
54
69
|
|
55
70
|
Tailwind uses modern CSS features that are not recognized by the sassc-rails extension that was included by default in the Gemfile for Rails 6. In order to avoid any errors like SassC::SyntaxError, you must remove that gem from your Gemfile.
|
56
71
|
|
57
72
|
*See https://github.com/rails/tailwindcss-rails#conflict-with-sassc-rails.*
|
73
|
+
|
74
|
+
## Development
|
75
|
+
|
76
|
+
The main solidus `bin/dev` command will automatically compile the Tailwind CSS stylesheets and watch for changes.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusAdmin
|
4
|
+
class ComponentRegistry
|
5
|
+
ComponentNotFoundError = Class.new(NameError)
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@names = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def []=(key, value)
|
12
|
+
@names[key] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](key)
|
16
|
+
if @names[key]
|
17
|
+
@names[key].constantize
|
18
|
+
else
|
19
|
+
infer_constant_from(key)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def infer_constant_from(key)
|
26
|
+
"solidus_admin/#{key}/component".classify.constantize
|
27
|
+
rescue NameError
|
28
|
+
prefix = "#{SolidusAdmin::Configuration::ENGINE_ROOT}/app/components/solidus_admin/"
|
29
|
+
suffix = "/component.rb"
|
30
|
+
dictionary = Dir["#{prefix}**#{suffix}"].map { _1.delete_prefix(prefix).delete_suffix(suffix) }
|
31
|
+
corrections = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(key.to_s)
|
32
|
+
|
33
|
+
raise ComponentNotFoundError.new(
|
34
|
+
"Unknown component #{key}#{DidYouMean.formatter.message_for(corrections)}",
|
35
|
+
key.classify,
|
36
|
+
receiver: ::SolidusAdmin
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spree/preferences/configuration'
|
4
|
+
require 'solidus_admin/component_registry'
|
4
5
|
|
5
6
|
module SolidusAdmin
|
6
7
|
# Configuration for the admin interface.
|
@@ -8,7 +9,6 @@ module SolidusAdmin
|
|
8
9
|
# Ensure requiring this file after the Rails application has been created,
|
9
10
|
# as some defaults depend on the application context.
|
10
11
|
class Configuration < Spree::Preferences::Configuration
|
11
|
-
ComponentNotFoundError = Class.new(NameError)
|
12
12
|
ENGINE_ROOT = File.expand_path("#{__dir__}/../..")
|
13
13
|
|
14
14
|
# Path to the logo used in the admin interface.
|
@@ -44,7 +44,9 @@ module SolidusAdmin
|
|
44
44
|
# Setting this to `true` enables access to alpha stage features that might still be in testing or development.
|
45
45
|
# Use with caution, as these features may not be fully stable or complete.
|
46
46
|
# Default: false
|
47
|
-
preference :enable_alpha_features
|
47
|
+
preference :enable_alpha_features, :boolean, default: false
|
48
|
+
|
49
|
+
alias enable_alpha_features? enable_alpha_features
|
48
50
|
|
49
51
|
preference :storefront_product_path_proc, :proc, default: ->(_version) {
|
50
52
|
->(product) { "/products/#{product.slug}" }
|
@@ -109,13 +111,6 @@ module SolidusAdmin
|
|
109
111
|
]
|
110
112
|
},
|
111
113
|
|
112
|
-
{
|
113
|
-
key: "promotions",
|
114
|
-
route: -> { spree.admin_promotions_path },
|
115
|
-
icon: "megaphone-line",
|
116
|
-
position: 30,
|
117
|
-
},
|
118
|
-
|
119
114
|
{
|
120
115
|
key: "stock",
|
121
116
|
route: -> { spree.admin_stock_items_path },
|
@@ -185,24 +180,7 @@ module SolidusAdmin
|
|
185
180
|
end
|
186
181
|
|
187
182
|
def components
|
188
|
-
@components ||=
|
189
|
-
const_name = "solidus_admin/#{k}/component".classify
|
190
|
-
|
191
|
-
unless Object.const_defined?(const_name)
|
192
|
-
prefix = "#{ENGINE_ROOT}/app/components/solidus_admin/"
|
193
|
-
suffix = "/component.rb"
|
194
|
-
dictionary = Dir["#{prefix}**#{suffix}"].map { _1.delete_prefix(prefix).delete_suffix(suffix) }
|
195
|
-
corrections = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(k.to_s)
|
196
|
-
|
197
|
-
raise ComponentNotFoundError.new(
|
198
|
-
"Unknown component #{k}#{DidYouMean.formatter.message_for(corrections)}",
|
199
|
-
k.classify,
|
200
|
-
receiver: ::SolidusAdmin
|
201
|
-
)
|
202
|
-
end
|
203
|
-
|
204
|
-
const_name.constantize
|
205
|
-
end
|
183
|
+
@components ||= ComponentRegistry.new
|
206
184
|
end
|
207
185
|
|
208
186
|
# The method used to authenticate the user in the admin interface, it's expected to redirect the user to the login method
|