diff --git a/app/components/avo/actions_component.rb b/app/components/avo/actions_component.rb index e5e5df698d..c2da208043 100644 --- a/app/components/avo/actions_component.rb +++ b/app/components/avo/actions_component.rb @@ -111,7 +111,7 @@ def render_action_link(action, icon: nil) def action_data_attributes(action) { action_name: action.action_name, - "turbo-frame": Avo::ACTIONS_TURBO_FRAME_ID, + "turbo-frame": Avo::MODAL_FRAME_ID, action: "click->actions-picker#visitAction", "actions-picker-target": action.standalone ? "standaloneAction" : "resourceAction", disabled: is_disabled?(action), diff --git a/app/components/avo/fields/has_one_field/show_component.html.erb b/app/components/avo/fields/has_one_field/show_component.html.erb index a6b936a852..d9a3705a57 100644 --- a/app/components/avo/fields/has_one_field/show_component.html.erb +++ b/app/components/avo/fields/has_one_field/show_component.html.erb @@ -10,7 +10,10 @@ icon: 'heroicons/outline/link', color: :primary, style: :text, - 'data-turbo-frame': 'attach_modal' do %> + data: { + turbo_frame: Avo::MODAL_FRAME_ID, + target: :attach + } do %> <%= t('avo.attach_item', item: @field.name.humanize(capitalize: false)) %> <% end %> <% end %> diff --git a/app/components/avo/resource_component.rb b/app/components/avo/resource_component.rb index ee7668a300..540e1c14b9 100644 --- a/app/components/avo/resource_component.rb +++ b/app/components/avo/resource_component.rb @@ -246,7 +246,7 @@ def render_attach_button(control) color: :primary, style: :text, data: { - turbo_frame: :attach_modal, + turbo_frame: Avo::MODAL_FRAME_ID, target: :attach } do control.label @@ -282,7 +282,7 @@ def render_action(action) title: action.title, size: action.size, data: { - turbo_frame: Avo::ACTIONS_TURBO_FRAME_ID, + turbo_frame: Avo::MODAL_FRAME_ID, action_name: action.action.action_name, tippy: action.title ? :tooltip : nil, action: "click->actions-picker#visitAction", diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index a0b9a1aba9..1b192c1be3 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -101,14 +101,13 @@ def respond # Trigger download, removes modal and flash the messages [ turbo_stream.download(content: Base64.encode64(@response[:path]), filename: @response[:filename]), - turbo_stream.close_action_modal, + turbo_stream.close_modal, turbo_stream.flash_alerts ] when :navigate_to_action - frame_id = Avo::ACTIONS_TURBO_FRAME_ID src, _ = @response[:action].link_arguments(resource: @action.resource, **@response[:navigate_to_action_args]) - turbo_stream.turbo_frame_set_src(frame_id, src) + turbo_stream.turbo_frame_set_src(Avo::MODAL_FRAME_ID, src) when :redirect turbo_stream.redirect_to( Avo::ExecutionContext.new(target: @response[:path]).handle, @@ -118,7 +117,7 @@ def respond when :close_modal # Close the modal and flash the messages [ - turbo_stream.close_action_modal, + turbo_stream.close_modal, turbo_stream.flash_alerts ] else diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index 5b18007818..fad9c69965 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -64,6 +64,16 @@ def new [@attachment_resource.new(record: record).record_title, record.to_param] end end + + @url = Avo::Services::URIService.parse(avo.root_url.to_s) + .append_paths("resources", params[:resource_name], params[:id], params[:related_name]) + .append_query( + { + view: @resource&.view&.to_s, + for_attribute: @field&.try(:for_attribute) + }.compact + ) + .to_s end def create diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 796ebbf463..90dc73f911 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -109,7 +109,7 @@ def new # Handle special cases when creating a new record via a belongs_to relationship if params[:via_belongs_to_resource_class].present? - return render turbo_stream: turbo_stream.append("attach_modal", partial: "avo/base/new_via_belongs_to") + return render turbo_stream: turbo_stream.append(Avo::MODAL_FRAME_ID, partial: "avo/base/new_via_belongs_to") end set_actions diff --git a/app/helpers/avo/turbo_stream_actions_helper.rb b/app/helpers/avo/turbo_stream_actions_helper.rb index e255d3a087..7dcd337909 100644 --- a/app/helpers/avo/turbo_stream_actions_helper.rb +++ b/app/helpers/avo/turbo_stream_actions_helper.rb @@ -10,10 +10,10 @@ def flash_alerts template: @view_context.render(Avo::FlashAlertsComponent.new(flashes: @view_context.flash.discard)) end - def close_action_modal + def close_modal turbo_stream_action_tag :replace, - target: Avo::ACTIONS_TURBO_FRAME_ID, - template: @view_context.turbo_frame_tag(Avo::ACTIONS_TURBO_FRAME_ID, data: {turbo_temporary: 1}) + target: Avo::MODAL_FRAME_ID, + template: @view_context.turbo_frame_tag(Avo::MODAL_FRAME_ID, data: {turbo_temporary: 1}) end end end diff --git a/app/javascript/js/controllers/actions_picker_controller.js b/app/javascript/js/controllers/actions_picker_controller.js index d1fe201897..f478ebc39d 100644 --- a/app/javascript/js/controllers/actions_picker_controller.js +++ b/app/javascript/js/controllers/actions_picker_controller.js @@ -12,7 +12,7 @@ export default class extends Controller { } get actionsShowTurboFrame() { - return document.querySelector('turbo-frame#actions_show') + return document.querySelector(`turbo-frame#${window.Avo.configuration.modal_frame_id}`) } enableTarget() { diff --git a/app/views/avo/actions/show.html.erb b/app/views/avo/actions/show.html.erb index ad4834aa5b..6e37ab3c4a 100644 --- a/app/views/avo/actions/show.html.erb +++ b/app/views/avo/actions/show.html.erb @@ -2,7 +2,7 @@ <%= render Avo::LoadingComponent.new(title: "...") %> <% end %> -<%= turbo_frame_tag Avo::ACTIONS_TURBO_FRAME_ID do %> +<%= turbo_frame_tag Avo::MODAL_FRAME_ID do %>
" data-action-no-confirmation-value="<%= @action.no_confirmation %>" diff --git a/app/views/avo/associations/new.html.erb b/app/views/avo/associations/new.html.erb index d14abe6284..bffa165a75 100644 --- a/app/views/avo/associations/new.html.erb +++ b/app/views/avo/associations/new.html.erb @@ -1,20 +1,9 @@ -<%= turbo_frame_tag 'attach_modal' do %> - <% - url = Avo::Services::URIService.parse(avo.root_url.to_s) - .append_paths('resources', params[:resource_name], params[:id], params[:related_name]) - .append_query( - { - view: @resource&.view&.to_s, - for_attribute: @field&.try(:for_attribute) - }.compact - ) - .to_s - %> +<%= turbo_frame_tag Avo::MODAL_FRAME_ID do %> <%= form_with scope: 'fields', - url: url, + url: @url, local: true, data: { - 'turbo-frame': '_top' + turbo_frame: :_top } do |form| %> <%= render Avo::ModalComponent.new do |c| %> <% c.with_heading do %> diff --git a/app/views/avo/partials/_attach_modal.html.erb b/app/views/avo/partials/_attach_modal.html.erb deleted file mode 100644 index df192cbdce..0000000000 --- a/app/views/avo/partials/_attach_modal.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= turbo_frame_tag 'attach_modal' %> diff --git a/app/views/avo/partials/_javascript.html.erb b/app/views/avo/partials/_javascript.html.erb index b6c19cfc34..006bc03db1 100644 --- a/app/views/avo/partials/_javascript.html.erb +++ b/app/views/avo/partials/_javascript.html.erb @@ -11,4 +11,5 @@ param_key: '<%= Avo::DynamicFilters.configuration.param_key %>' } <% end %> + Avo.configuration.modal_frame_id = '<%= ::Avo::MODAL_FRAME_ID %>' <% end %> diff --git a/app/views/layouts/avo/application.html.erb b/app/views/layouts/avo/application.html.erb index 92ffbd1135..5bc8a06c95 100644 --- a/app/views/layouts/avo/application.html.erb +++ b/app/views/layouts/avo/application.html.erb @@ -49,8 +49,7 @@
- <%= turbo_frame_tag Avo::ACTIONS_TURBO_FRAME_ID, data: {turbo_temporary: 1} %> - <%= render partial: "avo/partials/attach_modal" %> + <%= turbo_frame_tag Avo::MODAL_FRAME_ID, data: {turbo_temporary: 1} %> <%= render partial: "avo/partials/alerts" %> <%= render partial: "avo/partials/scripts" %> <%= render partial: "avo/partials/confirm_dialog" %> diff --git a/lib/avo.rb b/lib/avo.rb index b1753ac5bb..83ce55ccaa 100644 --- a/lib/avo.rb +++ b/lib/avo.rb @@ -20,7 +20,7 @@ module Avo IN_DEVELOPMENT = ENV["AVO_IN_DEVELOPMENT"] == "1" PACKED = !IN_DEVELOPMENT COOKIES_KEY = "avo" - ACTIONS_TURBO_FRAME_ID = :actions_show + MODAL_FRAME_ID = :modal_frame ACTIONS_BACKGROUND_FRAME = :actions_background class LicenseVerificationTemperedError < StandardError; end diff --git a/lib/avo/base_action.rb b/lib/avo/base_action.rb index 7a00ae05ab..d8df280f0b 100644 --- a/lib/avo/base_action.rb +++ b/lib/avo/base_action.rb @@ -61,11 +61,7 @@ def link_arguments(resource:, arguments: {}, **args) ) .to_s - data = { - turbo_frame: Avo::ACTIONS_TURBO_FRAME_ID, - } - - [path, data] + [path, {turbo_frame: Avo::MODAL_FRAME_ID}] end # Encrypt the arguments so we can pass sensible data as a query param. diff --git a/spec/system/avo/actions_spec.rb b/spec/system/avo/actions_spec.rb index f90e52e7e0..4bcff86f5a 100644 --- a/spec/system/avo/actions_spec.rb +++ b/spec/system/avo/actions_spec.rb @@ -192,7 +192,7 @@ click_on "Actions" click_on "Do Nothing" - expect(page).to have_css('turbo-frame#actions_show') + expect(page).to have_css("turbo-frame#modal_frame") expect(page).to have_selector(modal = "[role='dialog']") click_on "Run" expect(page).not_to have_selector(modal) @@ -214,7 +214,7 @@ click_on "Actions" click_on "Close modal" - expect(page).to have_css('turbo-frame#actions_show') + expect(page).to have_css("turbo-frame#modal_frame") expect(page).to have_selector(modal = "[role='dialog']") click_on "Run" expect(page).not_to have_selector(modal)