solidus_admin 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +60 -6
  3. data/Rakefile +1 -0
  4. data/app/assets/builds/solidus_admin/tailwind.css +198 -163
  5. data/app/assets/stylesheets/solidus_admin/dark.css +1 -0
  6. data/app/assets/stylesheets/solidus_admin/dimmed.css +1 -0
  7. data/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +27 -0
  8. data/app/components/solidus_admin/adjustment_reasons/edit/component.rb +12 -0
  9. data/app/components/solidus_admin/adjustment_reasons/edit/component.yml +8 -0
  10. data/app/components/solidus_admin/adjustment_reasons/index/component.rb +19 -2
  11. data/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +28 -0
  12. data/app/components/solidus_admin/adjustment_reasons/new/component.rb +12 -0
  13. data/app/components/solidus_admin/adjustment_reasons/new/component.yml +8 -0
  14. data/app/components/solidus_admin/base_component.rb +0 -25
  15. data/app/components/solidus_admin/option_types/index/component.rb +1 -1
  16. data/app/components/solidus_admin/orders/index/component.rb +8 -8
  17. data/app/components/solidus_admin/orders/index/component.yml +1 -0
  18. data/app/components/solidus_admin/orders/show/address/component.html.erb +56 -54
  19. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/component.rb +27 -0
  20. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_line_item/component.rb +14 -0
  21. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_order/component.rb +11 -0
  22. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_shipment/component.rb +15 -0
  23. data/app/components/solidus_admin/orders/show/adjustments/index/component.rb +147 -0
  24. data/app/components/solidus_admin/orders/show/adjustments/index/component.yml +21 -0
  25. data/app/components/solidus_admin/orders/show/adjustments/index/source/component.rb +26 -0
  26. data/app/components/solidus_admin/orders/show/adjustments/index/source/spree_tax_rate/component.rb +17 -0
  27. data/app/components/solidus_admin/orders/show/adjustments/index/source/spree_unit_cancel/component.rb +7 -0
  28. data/app/components/solidus_admin/orders/show/component.html.erb +7 -3
  29. data/app/components/solidus_admin/orders/show/component.rb +8 -0
  30. data/app/components/solidus_admin/orders/show/email/component.html.erb +18 -13
  31. data/app/components/solidus_admin/orders/show/email/component.rb +0 -4
  32. data/app/components/solidus_admin/orders/show/summary/component.html.erb +1 -1
  33. data/app/components/solidus_admin/payment_methods/index/component.rb +1 -1
  34. data/app/components/solidus_admin/products/index/component.rb +8 -5
  35. data/app/components/solidus_admin/products/show/component.html.erb +14 -3
  36. data/app/components/solidus_admin/products/status/component.rb +4 -1
  37. data/app/components/solidus_admin/products/status/component.yml +1 -0
  38. data/app/components/solidus_admin/properties/index/component.rb +1 -1
  39. data/app/components/solidus_admin/refund_reasons/edit/component.html.erb +27 -0
  40. data/app/components/solidus_admin/refund_reasons/edit/component.rb +12 -0
  41. data/app/components/solidus_admin/refund_reasons/edit/component.yml +8 -0
  42. data/app/components/solidus_admin/refund_reasons/index/component.rb +11 -4
  43. data/app/components/solidus_admin/refund_reasons/new/component.html.erb +27 -0
  44. data/app/components/solidus_admin/refund_reasons/new/component.rb +12 -0
  45. data/app/components/solidus_admin/refund_reasons/new/component.yml +6 -0
  46. data/app/components/solidus_admin/return_reasons/edit/component.html.erb +26 -0
  47. data/app/components/solidus_admin/return_reasons/edit/component.rb +12 -0
  48. data/app/components/solidus_admin/return_reasons/edit/component.yml +8 -0
  49. data/app/components/solidus_admin/return_reasons/index/component.rb +20 -2
  50. data/app/components/solidus_admin/return_reasons/new/component.html.erb +27 -0
  51. data/app/components/solidus_admin/return_reasons/new/component.rb +12 -0
  52. data/app/components/solidus_admin/return_reasons/new/component.yml +8 -0
  53. data/app/components/solidus_admin/roles/edit/component.html.erb +33 -0
  54. data/app/components/solidus_admin/roles/edit/component.rb +20 -0
  55. data/app/components/solidus_admin/roles/edit/component.yml +19 -0
  56. data/app/components/solidus_admin/roles/index/component.rb +70 -0
  57. data/app/components/solidus_admin/roles/index/component.yml +6 -0
  58. data/app/components/solidus_admin/roles/new/component.html.erb +33 -0
  59. data/app/components/solidus_admin/roles/new/component.rb +20 -0
  60. data/app/components/solidus_admin/roles/new/component.yml +19 -0
  61. data/app/components/solidus_admin/shipping_categories/edit/component.html.erb +16 -0
  62. data/app/components/solidus_admin/shipping_categories/edit/component.rb +12 -0
  63. data/app/components/solidus_admin/shipping_categories/edit/component.yml +6 -0
  64. data/app/components/solidus_admin/shipping_categories/index/component.rb +20 -3
  65. data/app/components/solidus_admin/shipping_categories/new/component.html.erb +17 -0
  66. data/app/components/solidus_admin/shipping_categories/new/component.rb +12 -0
  67. data/app/components/solidus_admin/shipping_categories/new/component.yml +6 -0
  68. data/app/components/solidus_admin/shipping_methods/index/component.rb +2 -2
  69. data/app/components/solidus_admin/stock_items/edit/component.html.erb +66 -72
  70. data/app/components/solidus_admin/stock_items/edit/component.rb +0 -5
  71. data/app/components/solidus_admin/stock_items/index/component.rb +5 -6
  72. data/app/components/solidus_admin/stock_locations/index/component.rb +1 -1
  73. data/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb +26 -0
  74. data/app/components/solidus_admin/store_credit_reasons/edit/component.rb +12 -0
  75. data/app/components/solidus_admin/store_credit_reasons/edit/component.yml +8 -0
  76. data/app/components/solidus_admin/store_credit_reasons/index/component.rb +11 -4
  77. data/app/components/solidus_admin/store_credit_reasons/new/component.html.erb +27 -0
  78. data/app/components/solidus_admin/store_credit_reasons/new/component.rb +12 -0
  79. data/app/components/solidus_admin/store_credit_reasons/new/component.yml +8 -0
  80. data/app/components/solidus_admin/stores/index/component.rb +1 -1
  81. data/app/components/solidus_admin/tax_categories/edit/component.html.erb +28 -0
  82. data/app/components/solidus_admin/tax_categories/edit/component.rb +12 -0
  83. data/app/components/solidus_admin/tax_categories/edit/component.yml +8 -0
  84. data/app/components/solidus_admin/tax_categories/index/component.rb +11 -4
  85. data/app/components/solidus_admin/tax_categories/new/component.html.erb +28 -0
  86. data/app/components/solidus_admin/tax_categories/new/component.rb +12 -0
  87. data/app/components/solidus_admin/tax_categories/new/component.yml +8 -0
  88. data/app/components/solidus_admin/tax_rates/index/component.rb +3 -3
  89. data/app/components/solidus_admin/taxonomies/index/component.rb +1 -1
  90. data/app/components/solidus_admin/ui/button/component.rb +1 -1
  91. data/app/components/solidus_admin/ui/checkbox_row/component.html.erb +29 -0
  92. data/app/components/solidus_admin/ui/checkbox_row/component.rb +11 -0
  93. data/app/components/solidus_admin/ui/forms/address/component.html.erb +27 -9
  94. data/app/components/solidus_admin/ui/forms/address/component.js +38 -13
  95. data/app/components/solidus_admin/ui/forms/search/component.html.erb +2 -3
  96. data/app/components/solidus_admin/ui/forms/search/component.js +3 -3
  97. data/app/components/solidus_admin/ui/modal/component.html.erb +7 -7
  98. data/app/components/solidus_admin/ui/modal/component.js +7 -0
  99. data/app/components/solidus_admin/ui/modal/component.rb +1 -1
  100. data/app/components/solidus_admin/ui/pages/index/component.html.erb +17 -3
  101. data/app/components/solidus_admin/ui/pages/index/component.rb +29 -43
  102. data/app/components/solidus_admin/ui/panel/component.html.erb +5 -16
  103. data/app/components/solidus_admin/ui/panel/component.rb +11 -7
  104. data/app/components/solidus_admin/ui/table/component.js +31 -2
  105. data/app/components/solidus_admin/ui/table/component.rb +23 -7
  106. data/app/components/solidus_admin/ui/table/component.yml +1 -0
  107. data/app/components/solidus_admin/ui/thumbnail/component.rb +1 -1
  108. data/app/components/solidus_admin/ui/thumbnail_with_caption/component.html.erb +17 -0
  109. data/app/components/solidus_admin/ui/thumbnail_with_caption/component.rb +15 -0
  110. data/app/components/solidus_admin/users/addresses/component.html.erb +46 -0
  111. data/app/components/solidus_admin/users/addresses/component.rb +61 -0
  112. data/app/components/solidus_admin/users/addresses/component.yml +14 -0
  113. data/app/components/solidus_admin/users/edit/api_access/component.html.erb +49 -0
  114. data/app/components/solidus_admin/users/edit/api_access/component.js +9 -0
  115. data/app/components/solidus_admin/users/edit/api_access/component.rb +7 -0
  116. data/app/components/solidus_admin/users/edit/api_access/component.yml +10 -0
  117. data/app/components/solidus_admin/users/edit/component.html.erb +52 -0
  118. data/app/components/solidus_admin/users/edit/component.rb +51 -0
  119. data/app/components/solidus_admin/users/edit/component.yml +12 -0
  120. data/app/components/solidus_admin/users/index/component.rb +10 -8
  121. data/app/components/solidus_admin/users/items/component.html.erb +41 -0
  122. data/app/components/solidus_admin/users/items/component.rb +170 -0
  123. data/app/components/solidus_admin/users/items/component.yml +16 -0
  124. data/app/components/solidus_admin/users/orders/component.html.erb +42 -0
  125. data/app/components/solidus_admin/users/orders/component.rb +131 -0
  126. data/app/components/solidus_admin/users/orders/component.yml +12 -0
  127. data/app/components/solidus_admin/users/stats/component.html.erb +11 -0
  128. data/app/components/solidus_admin/users/stats/component.rb +9 -0
  129. data/app/components/solidus_admin/users/stats/component.yml +2 -0
  130. data/app/components/solidus_admin/users_and_roles/component.rb +24 -0
  131. data/app/components/solidus_admin/users_and_roles/component.yml +2 -0
  132. data/app/components/solidus_admin/zones/index/component.rb +1 -1
  133. data/app/controllers/solidus_admin/addresses_controller.rb +6 -1
  134. data/app/controllers/solidus_admin/adjustment_reasons_controller.rb +85 -10
  135. data/app/controllers/solidus_admin/adjustments_controller.rb +57 -0
  136. data/app/controllers/solidus_admin/customers_controller.rb +5 -1
  137. data/app/controllers/solidus_admin/orders_controller.rb +5 -1
  138. data/app/controllers/solidus_admin/products_controller.rb +11 -0
  139. data/app/controllers/solidus_admin/refund_reasons_controller.rb +85 -10
  140. data/app/controllers/solidus_admin/reimbursement_types_controller.rb +0 -5
  141. data/app/controllers/solidus_admin/return_reasons_controller.rb +85 -10
  142. data/app/controllers/solidus_admin/roles_controller.rb +118 -0
  143. data/app/controllers/solidus_admin/shipping_categories_controller.rb +87 -10
  144. data/app/controllers/solidus_admin/shipping_methods_controller.rb +0 -5
  145. data/app/controllers/solidus_admin/stock_items_controller.rb +6 -6
  146. data/app/controllers/solidus_admin/stock_locations_controller.rb +0 -5
  147. data/app/controllers/solidus_admin/store_credit_reasons_controller.rb +85 -10
  148. data/app/controllers/solidus_admin/stores_controller.rb +0 -5
  149. data/app/controllers/solidus_admin/tax_categories_controller.rb +89 -10
  150. data/app/controllers/solidus_admin/tax_rates_controller.rb +0 -5
  151. data/app/controllers/solidus_admin/users_controller.rb +85 -6
  152. data/app/controllers/solidus_admin/zones_controller.rb +0 -5
  153. data/app/helpers/solidus_admin/last_login_helper.rb +16 -0
  154. data/app/helpers/solidus_admin/permission_sets_helper.rb +32 -0
  155. data/app/views/layouts/solidus_admin/application.html.erb +2 -1
  156. data/config/locales/adjustment_reasons.en.yml +5 -1
  157. data/config/locales/adjustments.en.yml +10 -0
  158. data/config/locales/refund_reasons.en.yml +10 -0
  159. data/config/locales/return_reasons.en.yml +5 -1
  160. data/config/locales/roles.en.yml +10 -0
  161. data/config/locales/shipping_categories.en.yml +4 -0
  162. data/config/locales/store_credit_reasons.en.yml +5 -1
  163. data/config/locales/tax_categories.en.yml +4 -0
  164. data/config/locales/users.en.yml +10 -0
  165. data/config/routes.rb +24 -7
  166. data/docs/components.md +109 -0
  167. data/docs/{customizing_view_components.md → customizing_components.md} +2 -7
  168. data/docs/index_pages.md +146 -0
  169. data/docs/{customizing_menu_items.md → menu_items.md} +1 -1
  170. data/docs/stimulusjs.md +85 -0
  171. data/docs/{customizing_tailwindcss.md → tailwindcss.md} +27 -8
  172. data/lib/solidus_admin/component_registry.rb +40 -0
  173. data/lib/solidus_admin/configuration.rb +2 -26
  174. data/lib/solidus_admin/install_tailwindcss.rb +4 -2
  175. data/lib/solidus_admin/testing_support/admin_assets.rb +10 -0
  176. data/lib/solidus_admin/testing_support/component_helpers.rb +27 -0
  177. data/lib/solidus_admin/testing_support/dummy_app/rake_tasks.rb +60 -0
  178. data/lib/solidus_admin/testing_support/feature_helpers.rb +34 -0
  179. data/lib/solidus_admin/version.rb +1 -1
  180. data/solidus_admin.gemspec +7 -3
  181. metadata +108 -19
  182. data/app/components/solidus_admin/promotion_categories/index/component.rb +0 -56
  183. data/app/components/solidus_admin/promotions/index/component.rb +0 -104
  184. data/app/components/solidus_admin/promotions/index/component.yml +0 -10
  185. data/app/controllers/solidus_admin/promotion_categories_controller.rb +0 -29
  186. data/app/controllers/solidus_admin/promotions_controller.rb +0 -46
  187. data/config/locales/promotion_categories.en.yml +0 -6
  188. data/config/locales/promotions.en.yml +0 -6
  189. data/config/locales/refund_reasons_.en.yml +0 -6
@@ -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
- # Customizing TailwindCSS
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. If you
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
- ## Setting up a local TailwindCSS build for Solidus Admin
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
- ## Caveats
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.
@@ -111,13 +111,6 @@ module SolidusAdmin
111
111
  ]
112
112
  },
113
113
 
114
- {
115
- key: "promotions",
116
- route: -> { spree.admin_promotions_path },
117
- icon: "megaphone-line",
118
- position: 30,
119
- },
120
-
121
114
  {
122
115
  key: "stock",
123
116
  route: -> { spree.admin_stock_items_path },
@@ -187,24 +180,7 @@ module SolidusAdmin
187
180
  end
188
181
 
189
182
  def components
190
- @components ||= Hash.new do |_h, k|
191
- const_name = "solidus_admin/#{k}/component".classify
192
-
193
- unless Object.const_defined?(const_name)
194
- prefix = "#{ENGINE_ROOT}/app/components/solidus_admin/"
195
- suffix = "/component.rb"
196
- dictionary = Dir["#{prefix}**#{suffix}"].map { _1.delete_prefix(prefix).delete_suffix(suffix) }
197
- corrections = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(k.to_s)
198
-
199
- raise ComponentNotFoundError.new(
200
- "Unknown component #{k}#{DidYouMean.formatter.message_for(corrections)}",
201
- k.classify,
202
- receiver: ::SolidusAdmin
203
- )
204
- end
205
-
206
- const_name.constantize
207
- end
183
+ @components ||= ComponentRegistry.new
208
184
  end
209
185
 
210
186
  # The method used to authenticate the user in the admin interface, it's expected to redirect the user to the login method
@@ -39,7 +39,7 @@ create_file "lib/tasks/solidus_admin/tailwind.rake", <<~RUBY
39
39
  namespace :solidus_admin do
40
40
  namespace :tailwindcss do
41
41
  root = Rails.root
42
- tailwindcss = Tailwindcss::Commands.executable
42
+ tailwindcss = Tailwindcss::Ruby.executable
43
43
 
44
44
  tailwindcss_command = [
45
45
  tailwindcss,
@@ -73,7 +73,9 @@ create_file "lib/tasks/solidus_admin/tailwind.rake", <<~RUBY
73
73
  end
74
74
  RUBY
75
75
 
76
- append_file ".gitignore", "app/assets/builds/solidus_admin/"
76
+ if Rails.root.join(".gitignore").exist?
77
+ append_file ".gitignore", "app/assets/builds/solidus_admin/"
78
+ end
77
79
 
78
80
  unless Rails.root.join("Procfile.dev").exist?
79
81
  create_file "Procfile.dev", <<~YAML
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.when_first_matching_example_defined(solidus_admin: true) do
5
+ config.before(:suite) do
6
+ system('bin/rails solidus_admin:tailwindcss:build') or abort 'Failed to build Tailwind CSS'
7
+ Rails.application.precompiled_assets
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusAdmin
4
+ module TestingSupport
5
+ module ComponentHelpers
6
+ # Mocks a component class with the given definition.
7
+ #
8
+ # @param definition [Proc] the component definition
9
+ # @example
10
+ # mock_component do
11
+ # def call
12
+ # "Rendered"
13
+ # end
14
+ # end
15
+ def mock_component(&definition)
16
+ location = caller(1, 1).first
17
+ component_class = Class.new(SolidusAdmin::BaseComponent)
18
+ # ViewComponent will complain if we don't fake a class name:
19
+ # @see https://github.com/ViewComponent/view_component/blob/5decd07842c48cbad82527daefa3fe9c65a4226a/lib/view_component/base.rb#L371
20
+ component_class.define_singleton_method(:name) { "Foo" }
21
+ component_class.define_singleton_method(:to_s) { "#{name} (#{location})" }
22
+ component_class.class_eval(&definition) if definition
23
+ component_class
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :solidus_admin do
4
+ namespace :tailwindcss do
5
+ desc "Build Tailwind CSS"
6
+ task build: :dummy_environment do
7
+ require "solidus_admin"
8
+ require "tailwindcss/commands"
9
+
10
+ config_file = <<~JS
11
+ const adminRoot = "#{SolidusAdmin::Engine.root}"
12
+ const solidusAdmin = require(`${adminRoot}/config/tailwind.config.js`)
13
+
14
+ module.exports = {
15
+ // Read how to use TailwindCSS presets: https://tailwindcss.com/docs/presets.
16
+ presets: [solidusAdmin],
17
+
18
+ content: [
19
+ // Include paths coming from SolidusAdmin.
20
+ ...solidusAdmin.content,
21
+
22
+ // Include paths to your own components.
23
+ `${__dirname}/../../../../app/components/admin/**/*`,
24
+ `${__dirname}/../../../../lib/components/admin/**/*`,
25
+ ],
26
+ }
27
+ JS
28
+ FileUtils.mkdir_p(DummyApp::Application.root.join("config"))
29
+ File.write(DummyApp::Application.root.join("config/tailwind.config.js"), config_file)
30
+ FileUtils.mkdir_p(DummyApp::Application.root.join("app/assets/stylesheets/solidus_admin"))
31
+ FileUtils.cp(
32
+ SolidusAdmin::Engine.root.join("app/assets/stylesheets/solidus_admin/application.tailwind.css"),
33
+ DummyApp::Application.root.join("app/assets/stylesheets/solidus_admin/application.tailwind.css")
34
+ )
35
+
36
+ tailwindcss = Tailwindcss::Ruby.executable
37
+
38
+ tailwindcss_command = [
39
+ tailwindcss,
40
+ "--config", DummyApp::Application.root.join("config/tailwind.config.js"),
41
+ "--input", DummyApp::Application.root.join("app/assets/stylesheets/solidus_admin/application.tailwind.css"),
42
+ "--output", DummyApp::Application.root.join("assets/builds/solidus_admin/tailwind.css")
43
+ ]
44
+
45
+ sh tailwindcss_command.shelljoin
46
+ end
47
+ end
48
+ end
49
+
50
+ # Attach Tailwind CSS build to other tasks.
51
+ %w[
52
+ assets:precompile
53
+ test:prepare
54
+ spec:prepare
55
+ db:test:prepare
56
+ ].each do |task_name|
57
+ next unless Rake::Task.task_defined?(task_name)
58
+
59
+ Rake::Task[task_name].enhance(["solidus_admin:tailwindcss:build"])
60
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusAdmin
4
+ module TestingSupport
5
+ module FeatureHelpers
6
+ def sign_in(user)
7
+ allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(user)
8
+ end
9
+
10
+ def stub_authorization!(user)
11
+ ability = Spree::Ability.new(user)
12
+ if block_given?
13
+ yield ability
14
+ else
15
+ ability.can :manage, :all
16
+ end
17
+ allow_any_instance_of(SolidusAdmin::BaseController).to receive(:current_ability).and_return(ability)
18
+ allow_any_instance_of(Spree::Admin::BaseController).to receive(:current_ability).and_return(ability)
19
+ end
20
+
21
+ def find_row(text)
22
+ find('table tbody tr', text: text)
23
+ end
24
+
25
+ def find_row_checkbox(text)
26
+ find_row(text).find('td:first-child input[type="checkbox"]')
27
+ end
28
+
29
+ def select_row(text)
30
+ find_row_checkbox(text).check
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusAdmin
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -12,11 +12,15 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.author = 'Solidus Team'
14
14
  s.email = 'contact@solidus.io'
15
- s.homepage = 'http://solidus.io'
15
+ s.homepage = 'https://github.com/solidusio/solidus/blob/main/admin/README.md'
16
16
  s.license = 'BSD-3-Clause'
17
17
 
18
18
  s.metadata['rubygems_mfa_required'] = 'true'
19
19
 
20
+ s.metadata["homepage_uri"] = s.homepage
21
+ s.metadata["source_code_uri"] = "https://github.com/solidusio/solidus/tree/main/api"
22
+ s.metadata["changelog_uri"] = "https://github.com/solidusio/solidus/releases?q=%22solidus_admin%2Fv0%22&expanded=true"
23
+
20
24
  s.files = `git ls-files -z`.split("\x0").reject do |f|
21
25
  f.match(%r{^(spec|script)/})
22
26
  end + ["app/assets/builds/solidus_admin/tailwind.css"]
@@ -29,6 +33,6 @@ Gem::Specification.new do |s|
29
33
  s.add_dependency 'solidus_backend'
30
34
  s.add_dependency 'solidus_core', '> 4.2'
31
35
  s.add_dependency 'stimulus-rails', '~> 1.2'
32
- s.add_dependency 'turbo-rails', '~> 1.4'
33
- s.add_dependency 'view_component', '~> 3.3'
36
+ s.add_dependency 'turbo-rails', '~> 2.0'
37
+ s.add_dependency 'view_component', '~> 3.9'
34
38
  end