avo 2.42.2 → 2.44.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +5 -1
  4. data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +118 -96
  5. data/app/components/avo/fields/belongs_to_field/edit_component.rb +11 -0
  6. data/app/components/avo/fields/tags_field/edit_component.html.erb +1 -0
  7. data/app/components/avo/modal_component.html.erb +17 -10
  8. data/app/components/avo/modal_component.rb +21 -0
  9. data/app/components/avo/panel_component.html.erb +2 -2
  10. data/app/components/avo/referrer_params_component.html.erb +1 -0
  11. data/app/components/avo/views/resource_edit_component.html.erb +11 -6
  12. data/app/components/avo/views/resource_edit_component.rb +11 -1
  13. data/app/controllers/avo/actions_controller.rb +9 -11
  14. data/app/controllers/avo/base_controller.rb +11 -2
  15. data/app/helpers/avo/application_helper.rb +4 -0
  16. data/app/javascript/js/application.js +3 -0
  17. data/app/javascript/js/controllers/fields/reload_belongs_to_field_controller.js +51 -0
  18. data/app/javascript/js/controllers/fields/tags_field_controller.js +2 -1
  19. data/app/javascript/js/controllers.js +2 -0
  20. data/app/views/avo/actions/show.html.erb +3 -2
  21. data/app/views/avo/base/_new_via_belongs_to.html.erb +12 -0
  22. data/app/views/avo/base/close_modal_and_reload_field.turbo_stream.erb +8 -0
  23. data/app/views/avo/base/create_fail_action.turbo_stream.erb +13 -0
  24. data/app/views/avo/partials/_flash_alerts.turbo_stream.erb +3 -0
  25. data/avo.gemspec +1 -0
  26. data/lib/avo/base_action.rb +10 -26
  27. data/lib/avo/fields/base_field.rb +13 -7
  28. data/lib/avo/fields/tags_field.rb +2 -0
  29. data/lib/avo/licensing/h_q.rb +4 -2
  30. data/lib/avo/version.rb +1 -1
  31. data/public/avo-assets/avo.base.css +20 -8
  32. data/public/avo-assets/avo.base.js +176 -176
  33. data/public/avo-assets/avo.base.js.map +3 -3
  34. metadata +21 -5
  35. data/app/controllers/avo/team_users_controller.rb +0 -4
  36. data/app/views/avo/actions/keep_modal_open.turbo_stream.erb +0 -5
  37. data/lib/avo/action_model.rb +0 -20
@@ -21,6 +21,7 @@ import ModalController from './controllers/modal_controller'
21
21
  import MultipleSelectFilterController from './controllers/multiple_select_filter_controller'
22
22
  import PerPageController from './controllers/per_page_controller'
23
23
  import ProgressBarFieldController from './controllers/fields/progress_bar_field_controller'
24
+ import ReloadBelongsToFieldController from './controllers/fields/reload_belongs_to_field_controller'
24
25
  import ResourceEditController from './controllers/resource_edit_controller'
25
26
  import ResourceIndexController from './controllers/resource_index_controller'
26
27
  import ResourceShowController from './controllers/resource_show_controller'
@@ -70,6 +71,7 @@ application.register('date-field', DateFieldController)
70
71
  application.register('easy-mde', EasyMdeController)
71
72
  application.register('key-value', KeyValueController)
72
73
  application.register('progress-bar-field', ProgressBarFieldController)
74
+ application.register("reload-belongs-to-field", ReloadBelongsToFieldController)
73
75
  application.register('trix-field', TrixFieldController)
74
76
 
75
77
  // Custom controllers
@@ -7,8 +7,7 @@
7
7
  data-resource-id="<%= params[:id] %>"
8
8
  class="hidden text-slate-800"
9
9
  >
10
- <%= form_with model: @model,
11
- scope: 'fields',
10
+ <%= form_with scope: 'fields',
12
11
  url: Avo::Services::URIService.parse(@resource.records_path).append_paths("actions").to_s,
13
12
  local: true,
14
13
  data: @action.class.form_data_attributes do |form|
@@ -17,6 +16,7 @@
17
16
  <% c.with_heading do %>
18
17
  <%= @action.action_name %>
19
18
  <% end %>
19
+
20
20
  <div class="flex-1 flex">
21
21
  <%= @action.get_message %>
22
22
  </div>
@@ -34,6 +34,7 @@
34
34
  <% end %>
35
35
  </div>
36
36
  <% end %>
37
+
37
38
  <% c.with_controls do %>
38
39
  <%= a_button type: :button,
39
40
  data: { action: 'click->modal#close' },
@@ -0,0 +1,12 @@
1
+ <%= turbo_frame_tag "new_via_belongs_to" do %>
2
+ <%= render(Avo::ModalComponent.new(width: :xl, body_class: "bg-application")) do |c| %>
3
+ <div class="pt-4 pb-8">
4
+ <%= render Avo::Views::ResourceEditComponent.new(
5
+ resource: @resource,
6
+ model: @model,
7
+ view: @view,
8
+ display_breadcrumbs: false
9
+ ) %>
10
+ </div>
11
+ <% end %>
12
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%= turbo_stream.remove("new_via_belongs_to") %>
2
+
3
+ <turbo-stream action="update-belongs-to"
4
+ data-relation-name="<%= params[:via_relation] %>"
5
+ data-target-resource-id="<%= @model.id %>"
6
+ data-target-resource-label="<%= @resource.label %>"
7
+ data-target-resource-class="<%= @model.class.name %>">
8
+ </turbo-stream>
@@ -0,0 +1,13 @@
1
+ <%= turbo_stream.replace(frame_id(@resource), template: "avo/base/new") %>
2
+
3
+ <%= turbo_stream.append "alerts" do %>
4
+ <%= render Avo::FlashAlertsComponent.new flashes: flash %>
5
+ <% end %>
6
+
7
+ <% if @model.errors.any? %>
8
+ <%= turbo_stream.append("alerts") do %>
9
+ <% @model.errors.full_messages.each do |message| %>
10
+ <%= render Avo::AlertComponent.new :error, message %>
11
+ <% end %>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= turbo_stream.append "alerts" do %>
2
+ <%= render Avo::FlashAlertsComponent.new flashes: flash %>
3
+ <% end %>
data/avo.gemspec CHANGED
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_dependency "active_link_to"
41
41
  spec.add_dependency "view_component", ">= 2.54.0"
42
42
  spec.add_dependency "turbo-rails"
43
+ spec.add_dependency "turbo_power", "~> 0.5.0"
43
44
  spec.add_dependency "addressable"
44
45
  spec.add_dependency "meta-tags"
45
46
  spec.add_dependency "dry-initializer"
@@ -7,22 +7,18 @@ module Avo
7
7
  class_attribute :confirm_button_label
8
8
  class_attribute :cancel_button_label
9
9
  class_attribute :no_confirmation, default: false
10
- class_attribute :model
11
- class_attribute :view
12
- class_attribute :user
13
- class_attribute :resource
14
10
  class_attribute :standalone, default: false
15
11
  class_attribute :visible
16
12
  class_attribute :may_download_file, default: false
17
13
  class_attribute :turbo
18
14
 
15
+ attr_accessor :view
19
16
  attr_accessor :response
20
17
  attr_accessor :model
21
18
  attr_accessor :resource
22
19
  attr_accessor :user
23
20
  attr_reader :arguments
24
21
 
25
- delegate :view, to: :class
26
22
  delegate :context, to: ::Avo::App
27
23
  delegate :current_user, to: ::Avo::App
28
24
  delegate :params, to: ::Avo::App
@@ -59,10 +55,10 @@ module Avo
59
55
  end
60
56
 
61
57
  def initialize(model: nil, resource: nil, user: nil, view: nil, arguments: {})
62
- self.class.model = model
63
- self.class.resource = resource
64
- self.class.user = user
65
- self.class.view = view
58
+ @model = model
59
+ @resource = resource
60
+ @user = user
61
+ @view = view
66
62
  @arguments = arguments
67
63
 
68
64
  self.class.message ||= I18n.t("avo.are_you_sure_you_want_to_run_this_option")
@@ -75,23 +71,12 @@ module Avo
75
71
 
76
72
  def get_message
77
73
  if self.class.message.respond_to? :call
78
- Avo::Hosts::ResourceRecordHost.new(block: self.class.message, record: self.class.model, resource: self.class.resource).handle
74
+ Avo::Hosts::ResourceRecordHost.new(block: self.class.message, record: @model, resource: @resource).handle
79
75
  else
80
76
  self.class.message
81
77
  end
82
78
  end
83
79
 
84
- def get_attributes_for_action
85
- get_fields.map do |field|
86
- default_value = if field.default.respond_to? :call
87
- Avo::Hosts::ResourceViewRecordHost.new(block: field.default, record: self.class.model, view: view, resource: self.class.resource).handle
88
- else
89
- field.default
90
- end
91
- [field.id, field.value || default_value]
92
- end.to_h
93
- end
94
-
95
80
  def handle_action(**args)
96
81
  models, fields, current_user, resource = args.values_at(:models, :fields, :current_user, :resource)
97
82
  # Fetching the field definitions and not the actual fields (get_fields) because they will break if the user uses a `visible` block and adds a condition using the `params` variable. The params are different in the show method and the handle method.
@@ -144,8 +129,8 @@ module Avo
144
129
  block: visible,
145
130
  params: params,
146
131
  parent_resource: parent_resource,
147
- resource: self.class.resource,
148
- view: self.class.view,
132
+ resource: @resource,
133
+ view: @view,
149
134
  arguments: arguments
150
135
  ).handle
151
136
  end
@@ -197,10 +182,9 @@ module Avo
197
182
  self
198
183
  end
199
184
 
200
- def redirect_to(path = nil, allow_other_host: nil, status: nil, &block)
185
+ def redirect_to(path = nil, **args, &block)
201
186
  response[:type] = :redirect
202
- response[:allow_other_host] = allow_other_host
203
- response[:status] = status
187
+ response[:redirect_args] = args
204
188
  response[:path] = if block.present?
205
189
  block
206
190
  else
@@ -99,14 +99,20 @@ module Avo
99
99
  except_on args[:except_on] if args[:except_on].present?
100
100
  end
101
101
 
102
- def hydrate(model: nil, resource: nil, action: nil, view: nil, panel_name: nil, user: nil)
103
- @model = model if model.present?
104
- @view = view if view.present?
105
- @resource = resource if resource.present?
106
- @action = action if action.present?
107
- @user = user if user.present?
108
- @panel_name = panel_name if panel_name.present?
102
+ def hydrate(**kwargs)
103
+ # List of permitted keyword argument keys as symbols
104
+ permited_kwargs_keys = %i[model resource action view panel_name user]
109
105
 
106
+ # Check for unrecognized keys
107
+ unrecognized_keys = kwargs.keys - permited_kwargs_keys
108
+ raise ArgumentError, "Unrecognized argument(s): #{unrecognized_keys.join(', ')}" if unrecognized_keys.any?
109
+
110
+ # Set instance variables with provided values
111
+ kwargs.each do |key, value|
112
+ instance_variable_set("@#{key}", value)
113
+ end
114
+
115
+ # Return self for method chaining, if desired
110
116
  self
111
117
  end
112
118
 
@@ -5,6 +5,7 @@ module Avo
5
5
  attr_reader :close_on_select
6
6
  attr_reader :delimiters
7
7
  attr_reader :enforce_suggestions
8
+ attr_reader :suggestions_max_items
8
9
  attr_reader :mode
9
10
 
10
11
  def initialize(id, **args, &block)
@@ -16,6 +17,7 @@ module Avo
16
17
  add_array_prop args, :disallowed
17
18
  add_array_prop args, :delimiters, [","]
18
19
  add_array_prop args, :suggestions
20
+ add_string_prop args, :suggestions_max_items
19
21
  add_string_prop args, :mode, nil
20
22
  add_string_prop args, :fetch_values_from
21
23
  add_string_prop args, :fetch_labels
@@ -109,8 +109,10 @@ module Avo
109
109
  cache_store: Avo::App.cache_store&.class&.to_s,
110
110
  **config_metadata
111
111
  }
112
- rescue
113
- {}
112
+ rescue => e
113
+ {
114
+ error: e.message
115
+ }
114
116
  end
115
117
 
116
118
  def cached_response
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.42.2" unless const_defined?(:VERSION)
2
+ VERSION = "2.44.0" unless const_defined?(:VERSION)
3
3
  end
@@ -6856,6 +6856,10 @@ trix-toolbar .trix-button-group:not(:first-child){
6856
6856
  max-height:100%
6857
6857
  }
6858
6858
 
6859
+ .max-h-11\/12{
6860
+ max-height:91.666667%
6861
+ }
6862
+
6859
6863
  .min-h-24{
6860
6864
  min-height:6rem
6861
6865
  }
@@ -7646,6 +7650,10 @@ trix-toolbar .trix-button-group:not(:first-child){
7646
7650
  background-color:rgb(246 246 247 / var(--tw-bg-opacity))
7647
7651
  }
7648
7652
 
7653
+ .bg-application{
7654
+ background-color:rgb(var(--color-application-background))
7655
+ }
7656
+
7649
7657
  .bg-orange-700{
7650
7658
  --tw-bg-opacity:1;
7651
7659
  background-color:rgb(194 65 12 / var(--tw-bg-opacity))
@@ -7661,10 +7669,6 @@ trix-toolbar .trix-button-group:not(:first-child){
7661
7669
  background-color:rgb(21 128 61 / var(--tw-bg-opacity))
7662
7670
  }
7663
7671
 
7664
- .bg-application{
7665
- background-color:rgb(var(--color-application-background))
7666
- }
7667
-
7668
7672
  .bg-red-400{
7669
7673
  --tw-bg-opacity:1;
7670
7674
  background-color:rgb(248 113 113 / var(--tw-bg-opacity))
@@ -7853,6 +7857,14 @@ trix-toolbar .trix-button-group:not(:first-child){
7853
7857
  padding-bottom:2rem
7854
7858
  }
7855
7859
 
7860
+ .pt-4{
7861
+ padding-top:1rem
7862
+ }
7863
+
7864
+ .pb-8{
7865
+ padding-bottom:2rem
7866
+ }
7867
+
7856
7868
  .pb-6{
7857
7869
  padding-bottom:1.5rem
7858
7870
  }
@@ -7881,10 +7893,6 @@ trix-toolbar .trix-button-group:not(:first-child){
7881
7893
  padding-top:0px
7882
7894
  }
7883
7895
 
7884
- .pt-4{
7885
- padding-top:1rem
7886
- }
7887
-
7888
7896
  .pb-4{
7889
7897
  padding-bottom:1rem
7890
7898
  }
@@ -9786,6 +9794,10 @@ trix-editor {
9786
9794
  width:50%
9787
9795
  }
9788
9796
 
9797
+ .lg\:w-3\/4{
9798
+ width:75%
9799
+ }
9800
+
9789
9801
  .lg\:grid-cols-3{
9790
9802
  grid-template-columns:repeat(3, minmax(0, 1fr))
9791
9803
  }