avo 2.43.0 → 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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e46a221f03c28ba77e3a9ab32d841176eb9ecf7125161742ad0e1c222063d1b0
4
- data.tar.gz: 53a6aced2acfe8347472915e2d1c757ab7125b4189c333b1a849b23e51e306f5
3
+ metadata.gz: 6b2cdd36d7332c119809608975ea38e68d2bfe09987e9203b9f39149292885a7
4
+ data.tar.gz: 9e00cbe1f725979bf1c61164ae0912e20eff340ff727b4eb27c7212ed1500897
5
5
  SHA512:
6
- metadata.gz: 6c911463f13e7556ac9a9340ab45d67e18ee9130a542d5d12db3d728dbf62e4abe74f09ffc6cf9bfb4fa5b578396461715ba47ffc2a006680a6460ec25e748bd
7
- data.tar.gz: 7399602dd68b5442f19ed38a483373c95cde447a43fba2108e6e3e76905888f547841fd81675700c7467d0f035aab5a5563cc2a870ced29faf74581818266396
6
+ metadata.gz: 6fd7ac16fac942d14da9c82317a0f8c322cdd0b1af785319c4cc273badd5e528a73c0f87e8b12bf8673fe35e8c6cfe61ac3f578b044797e64cb1c7c3158de677
7
+ data.tar.gz: 87a8e856ca13470d32119b71685300dc1759f6455fc86742284e1e41f573500bb016bf0105e6e3fce48f0362a50d06f0905660d681a7345987afd5827a4ed7ff
data/Gemfile CHANGED
@@ -167,3 +167,5 @@ gem "image_processing", "~> 1.12"
167
167
  gem "prefixed_ids"
168
168
 
169
169
  gem "mapkick-rb", "~> 0.1.4"
170
+
171
+ gem "turbo_power", "~> 0.5.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.43.0)
4
+ avo (2.44.0)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
@@ -13,6 +13,7 @@ PATH
13
13
  meta-tags
14
14
  pagy
15
15
  turbo-rails
16
+ turbo_power (~> 0.5.0)
16
17
  view_component (>= 2.54.0)
17
18
  zeitwerk (>= 2.6.2)
18
19
 
@@ -419,6 +420,8 @@ GEM
419
420
  actionpack (>= 6.0.0)
420
421
  activejob (>= 6.0.0)
421
422
  railties (>= 6.0.0)
423
+ turbo_power (0.5.0)
424
+ turbo-rails (~> 1.3)
422
425
  tzinfo (2.0.6)
423
426
  concurrent-ruby (~> 1.0)
424
427
  unicode-display_width (2.4.0)
@@ -518,6 +521,7 @@ DEPENDENCIES
518
521
  sprockets-rails
519
522
  standard
520
523
  test-prof
524
+ turbo_power (~> 0.5.0)
521
525
  tzinfo-data
522
526
  web-console (>= 3.3.0)
523
527
  webdrivers (>= 5.3.0)
@@ -16,7 +16,6 @@ module Avo
16
16
  @view = :new
17
17
 
18
18
  @resource.hydrate(model: @model, view: @view, user: _current_user, params: params)
19
- @model = ActionModel.new @action.get_attributes_for_action
20
19
  end
21
20
 
22
21
  def handle
@@ -79,19 +78,18 @@ module Avo
79
78
  end
80
79
 
81
80
  respond_to do |format|
82
- format.html do
81
+ format.turbo_stream do
83
82
  # Flash the messages collected from the action
84
83
  flash_messages messages
85
84
 
86
85
  if response[:type] == :redirect
87
- path = response[:path]
88
-
89
- if path.respond_to? :call
90
- path = instance_eval(&path)
91
- end
92
-
93
- redirect_to path, **{allow_other_host: response[:allow_other_host], status: response[:status]}.compact
94
- elsif response[:type] == :reload
86
+ render turbo_stream: turbo_stream.redirect_to(
87
+ Avo::ExecutionContext.new(target: response[:path]).handle,
88
+ nil,
89
+ response[:redirect_args][:turbo_frame],
90
+ **response[:redirect_args].except(:turbo_frame)
91
+ )
92
+ else
95
93
  redirect_back fallback_location: resources_path(resource: @resource)
96
94
  end
97
95
  end
@@ -2,6 +2,9 @@ import 'mapkick/bundle'
2
2
 
3
3
  import { Alert, Popover } from 'tailwindcss-stimulus-components'
4
4
  import { Application } from '@hotwired/stimulus'
5
+ import TurboPower from 'turbo_power'
6
+
7
+ TurboPower.initialize(Turbo.StreamActions)
5
8
 
6
9
  const application = Application.start()
7
10
 
@@ -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|
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
 
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.43.0" unless const_defined?(:VERSION)
2
+ VERSION = "2.44.0" unless const_defined?(:VERSION)
3
3
  end