activeadmin-hotwire_combobox_filters 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8c32e895fd56e03fe690a40ce2261595fc004c308247802b96a5b0f32adf429
4
- data.tar.gz: cabf8b82dc496d6c5fd46be328955d596a5e45761eafde64cde5201a9a912896
3
+ metadata.gz: f19b82e2a06c1606fe1877596cce758e2702b7ec3ed8be6d88dd4ec4e28d9ab9
4
+ data.tar.gz: a43b4bff032a831febe82396d9d656ff7906c89d1d266b1c14d218f131d71981
5
5
  SHA512:
6
- metadata.gz: e13a13adf946921c55194a13c03e57b591ccee72984d0da1073405a66796a30f8cdafd733e073112eed35b52741c45cd201984aa77b361d2e8c53a2c8f7449fb
7
- data.tar.gz: 93d15f3643f166f78014a24c0081afc096faa76fb54fdecf3905a700fd9ecd2f474143b2e002cfe3f3d4fdc4aef7206ebc1c847d6bb017c2f6a3b09d5aa4163e
6
+ metadata.gz: 2d5453aa79004a4f7a148a17ff636063cc2e816bce602a7870f9e4e046ec0ec6c71a98aab4928dc32d48abbebab89fde88fe5cc9ccc80039e9ab2d2b8a0c8eff
7
+ data.tar.gz: 38fab523fe954a2aafa83a291e63b7cc9fd1dc7df08ef133a0aa4786b9e2f5f0b7b63e3aa44e4030ab69b9d97e9154c081cef2d814a9ae84910e56e2add59adf
data/README.md CHANGED
@@ -4,15 +4,101 @@ This gem adds a hotwire combobox to ActiveAdmin sidebar filters for related reso
4
4
 
5
5
  # Installation
6
6
 
7
- ```
7
+ ```ruby
8
8
  gem "activeadmin-hotwire_combobox_filters"
9
9
  ```
10
10
 
11
11
  # Usage
12
12
 
13
- The gem automatically replaces the default ActiveAdmin filters with hotwire_combobox filters after being required.
13
+ The gem automatically replaces the default ActiveAdmin filters with hotwire_combobox filters after being required and configured.
14
+
15
+ The gem requires ActiveAdmin to be wired up with Hotwire.
16
+
17
+ Here's an example setup:
18
+
19
+ 1. Add hotwire_combobox styles to your app, I recommend adding them to `app/views/active_admin/_html_head.html.erb`:
20
+
21
+ ```erb
22
+ <%= render "activeadmin_hotwire_combobox_filters/combobox_styles" %>
23
+ ```
24
+
25
+ 2. Use importmaps:
26
+
27
+ In `app/views/active_admin/_html_head.html.erb`:
28
+
29
+ ```diff
30
+ -<%= javascript_importmap_tags "active_admin", importmap: ActiveAdmin.importmap %>
31
+ +<%= javascript_importmap_tags %>
32
+ ```
33
+
34
+ <details>
35
+ <summary>Here's an example `config/importmap.rb`:</summary>
36
+
37
+ ```ruby
38
+ # Pin npm packages by running ./bin/importmap
39
+
40
+ pin "application"
41
+ pin "@hotwired/turbo-rails", to: "turbo.min.js"
42
+ pin "@hotwired/stimulus", to: "@hotwired--stimulus.js" # @3.2.2
43
+ pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
44
+ pin_all_from "app/javascript/controllers", under: "controllers"
45
+
46
+ pin "flowbite", to: "https://cdn.jsdelivr.net/npm/flowbite@2.5.2/dist/flowbite.turbo.min.js" # @2.5.2
47
+ pin "@stimulus-components/auto-submit", to: "@stimulus-components--auto-submit.js" # @6.0.0
48
+ pin "@activeadmin/activeadmin", to: "@activeadmin--activeadmin.js" # @4.0.0
49
+ pin "@rails/ujs", to: "@rails--ujs.js" # @7.1.400
50
+
51
+ pin "stimulus-datepicker" # @1.0.9
52
+ pin "flowbite-datepicker" # @1.3.1
53
+ ```
54
+
55
+ Most of these files are in `vendor/javascript`, added by running `bin/importmap pin @stimulus-components/auto-submit` or similar.
56
+
57
+ `turbo.min.js`and`stimulus-loading.js`are part of`turbo-rails` gem (I believe).
58
+
59
+ Flowbite is loaded as recommened by Flowbite docs for Rails/importmaps: https://flowbite.com/docs/getting-started/rails/
60
+
61
+ </details>
62
+
63
+ 3. Add this line to your `config/application.rb`:
64
+
65
+ ```ruby
66
+ config.importmap.paths << ActiveAdmin::Engine.root.join("config", "importmap.rb")
67
+ ```
68
+
69
+ 4. Update your `app/javascript/application.js`:
70
+
71
+ ```js
72
+ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
73
+
74
+ import "active_admin";
75
+ import "@hotwired/turbo-rails";
76
+ import "controllers";
77
+ ```
78
+
79
+ 5. Some additional styling you might want to add to your app:
80
+
81
+ ```css
82
+ /* makes it look like other AA input fields */
83
+ :root:root {
84
+ --hw-component-bg-color: rgb(249 250 251);
85
+ }
86
+
87
+ /* makes it look like other AA input fields with validation errors */
88
+ .formtastic .error :where(.hw-combobox__main__wrapper) {
89
+ @apply border-red-500;
90
+ }
91
+
92
+ /* makes it wider than default hotwire_combobox styles */
93
+ :root:root {
94
+ --hw-combobox-width: 100%;
95
+ }
96
+ .hw-combobox.hw-combobox {
97
+ @apply flex;
98
+ }
99
+ ```
14
100
 
15
101
  # Thanks and credits
16
102
 
17
- Thanks to @josefarias for the awesome [hotwire_combobox](https://github.com/josefarias/hotwire_combobox) gem.
103
+ Thanks to [@josefarias](https://github.com/josefarias) for the awesome [hotwire_combobox](https://github.com/josefarias/hotwire_combobox) gem.
18
104
  Thanks to all the team at [ActiveAdmin](https://github.com/activeadmin/activeadmin) for the awesome gem.
@@ -26,8 +26,11 @@ module ActiveAdminHotwireComboboxFilters
26
26
  "No display method found for #{resource_class.name}. Methods searched: #{DISPLAY_NAME_METHODS.join(', ')}"
27
27
  end
28
28
 
29
- @records = Pundit.policy_scope!(current_user, resource_class).ransack("#{method}_cont" => params[:q]).result
30
- .page(params[:page]).per(Kaminari.config.default_per_page)
29
+ current_user = send(ActiveAdmin.application.current_user_method)
30
+ @records = Pundit.policy_scope!(current_user, resource_class)
31
+ @records = @records.ordered if resource_class.respond_to?(:ordered)
32
+ @records = @records.ransack("#{method}_cont" => params[:q]).result if params[:q].present?
33
+ @records = @records.page(params[:page]).per(Kaminari.config.default_per_page)
31
34
 
32
35
  @combobox_results = @records.pluck(method, :id)
33
36
  @next_page = @records.next_page
@@ -1,10 +1,11 @@
1
1
  ActiveAdmin::Inputs::Filters::SelectInput.class_eval do
2
- def select_html # rubocop:disable Metrics/AbcSize
2
+ def select_html # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
3
3
  current_value = object.public_send(input_name)
4
4
 
5
5
  options = []
6
6
  if current_value.present?
7
- value_record = Pundit.policy_scope!(Current.user, reflection.klass).find_by(id: current_value)
7
+ current_user = send(ActiveAdmin.application.current_user_method)
8
+ value_record = Pundit.policy_scope!(current_user, reflection.klass).find_by(id: current_value)
8
9
  options = HotwireCombobox::Listbox::Item.collection_for(
9
10
  template, [value_record], render_in: {}, include_blank: nil, display: :to_combobox_display
10
11
  )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-hotwire_combobox_filters
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Fonic