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.
- checksums.yaml +4 -4
- data/README.md +60 -6
- data/Rakefile +1 -0
- data/app/assets/builds/solidus_admin/tailwind.css +198 -163
- 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 +19 -2
- 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 +0 -25
- data/app/components/solidus_admin/option_types/index/component.rb +1 -1
- data/app/components/solidus_admin/orders/index/component.rb +8 -8
- data/app/components/solidus_admin/orders/index/component.yml +1 -0
- 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 +1 -1
- data/app/components/solidus_admin/products/index/component.rb +8 -5
- 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 +1 -1
- 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 +11 -4
- 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/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 +20 -2
- 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_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 +20 -3
- 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 +2 -2
- 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 +5 -6
- data/app/components/solidus_admin/stock_locations/index/component.rb +1 -1
- 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 +11 -4
- 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 +1 -1
- 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 +11 -4
- 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 +3 -3
- data/app/components/solidus_admin/taxonomies/index/component.rb +1 -1
- 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 +17 -3
- data/app/components/solidus_admin/ui/pages/index/component.rb +29 -43
- 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.js +31 -2
- data/app/components/solidus_admin/ui/table/component.rb +23 -7
- 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 +10 -8
- 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 +1 -1
- 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/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/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 +2 -26
- data/lib/solidus_admin/install_tailwindcss.rb +4 -2
- 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 +108 -19
- data/app/components/solidus_admin/promotion_categories/index/component.rb +0 -56
- data/app/components/solidus_admin/promotions/index/component.rb +0 -104
- data/app/components/solidus_admin/promotions/index/component.yml +0 -10
- data/app/controllers/solidus_admin/promotion_categories_controller.rb +0 -29
- 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/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.
|
@@ -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 ||=
|
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::
|
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
|
-
|
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
|
data/solidus_admin.gemspec
CHANGED
@@ -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 = '
|
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', '~>
|
33
|
-
s.add_dependency 'view_component', '~> 3.
|
36
|
+
s.add_dependency 'turbo-rails', '~> 2.0'
|
37
|
+
s.add_dependency 'view_component', '~> 3.9'
|
34
38
|
end
|