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 %>