diff --git a/app/components/avo/paginator_component.html.erb b/app/components/avo/paginator_component.html.erb index c5c8b649b7..bf39e296aa 100644 --- a/app/components/avo/paginator_component.html.erb +++ b/app/components/avo/paginator_component.html.erb @@ -31,7 +31,7 @@ <% if @pagy.pages > 1 %> <%# @todo: add first & last page. make the first and last buttons rounded %> - <%== helpers.pagy_nav @pagy, anchor_string: "data-turbo-frame=\"#{@turbo_frame}\"" %> + <%== helpers.pagy_nav @pagy, anchor_string: anchor_string %> <% end %> diff --git a/app/components/avo/paginator_component.rb b/app/components/avo/paginator_component.rb index 318197b7fa..e85e8221db 100644 --- a/app/components/avo/paginator_component.rb +++ b/app/components/avo/paginator_component.rb @@ -48,4 +48,12 @@ def pagy_major_version version end + + def anchor_string + if @parent_record.present? + "data-turbo-frame=\"#{@turbo_frame}\"" + else + "data-turbo-frame=\"#{@turbo_frame}\", data-turbo-action=\"advance\"" + end + end end diff --git a/app/components/avo/resource_component.rb b/app/components/avo/resource_component.rb index 0cf8b59272..cc94a61ab2 100644 --- a/app/components/avo/resource_component.rb +++ b/app/components/avo/resource_component.rb @@ -232,7 +232,8 @@ def render_create_button(control) style: :primary, icon: "heroicons/outline/plus", data: { - target: :create + target: :create, + turbo_frame: :_top } do control.label end diff --git a/app/components/avo/turbo_frame_wrapper_component.html.erb b/app/components/avo/turbo_frame_wrapper_component.html.erb index d3b2ad3cc0..dbcf7adeaf 100644 --- a/app/components/avo/turbo_frame_wrapper_component.html.erb +++ b/app/components/avo/turbo_frame_wrapper_component.html.erb @@ -1,10 +1 @@ -<% if @name.present? %><% end %> -<% - # When rendering the frames the flashed content gets lost. - # We're appending it back if it's a turbo_frame_request. -%> -<% if helpers.turbo_frame_request? %> - <%= helpers.turbo_stream_action_tag :append, target: "alerts", template: render(Avo::FlashAlertsComponent.new(flashes: helpers.flash)) %> -<% end %> -<%= content %> -<% if @name.present? %><% end %> +<%= render_content %> diff --git a/app/components/avo/turbo_frame_wrapper_component.rb b/app/components/avo/turbo_frame_wrapper_component.rb index d21e0197f1..6a27c0fe46 100644 --- a/app/components/avo/turbo_frame_wrapper_component.rb +++ b/app/components/avo/turbo_frame_wrapper_component.rb @@ -1,5 +1,21 @@ # frozen_string_literal: true class Avo::TurboFrameWrapperComponent < Avo::BaseComponent - prop :name, kind: :positional + prop :frame_id, kind: :positional + + def render_content + return content if @frame_id.blank? + + turbo_frame_tag @frame_id do + # When rendering the frames the flashed content gets lost. + # We're appending it back if it's a turbo_frame_request. + if helpers.turbo_frame_request? + helpers.turbo_stream_action_tag :append, + target: "alerts", + template: render(Avo::FlashAlertsComponent.new(flashes: helpers.flash)) + end + + content + end + end end diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index a19bdece03..c372b0f6ea 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -17,6 +17,7 @@ class BaseController < ApplicationController before_action :set_pagy_locale, only: :index def index + @turbo_frame = params[:turbo_frame] || @resource.route_key @page_title = @resource.plural_name.humanize if @reflection.present? && !turbo_frame_request? diff --git a/app/javascript/js/controllers/filter_controller.js b/app/javascript/js/controllers/filter_controller.js index 6ac35cdbd3..fc272cecc5 100644 --- a/app/javascript/js/controllers/filter_controller.js +++ b/app/javascript/js/controllers/filter_controller.js @@ -1,4 +1,5 @@ import { Controller } from '@hotwired/stimulus' +import { Turbo } from '@hotwired/turbo-rails' import URI from 'urijs' export default class extends Controller { @@ -109,7 +110,6 @@ export default class extends Controller { url.query(query) - this.urlRedirectTarget.href = url.readable().toString() - this.urlRedirectTarget.click() + Turbo.visit(url.readable().toString()) } } diff --git a/app/views/avo/base/index.html.erb b/app/views/avo/base/index.html.erb index 396798883e..d144acef2a 100644 --- a/app/views/avo/base/index.html.erb +++ b/app/views/avo/base/index.html.erb @@ -1,4 +1,4 @@ -<%= render Avo::TurboFrameWrapperComponent.new(params[:turbo_frame]) do %> +<%= render Avo::TurboFrameWrapperComponent.new(@turbo_frame) do %> <%= render @component.new( resource: @resource, resources: @resources, @@ -8,7 +8,7 @@ filters: @filters, actions: @actions, reflection: @reflection, - turbo_frame: params[:turbo_frame], + turbo_frame: @turbo_frame, parent_record: @parent_record, parent_resource: @parent_resource, applied_filters: @applied_filters, diff --git a/app/views/avo/partials/_view_toggle_button.html.erb b/app/views/avo/partials/_view_toggle_button.html.erb index 3171c5ceec..fd1bb532a7 100644 --- a/app/views/avo/partials/_view_toggle_button.html.erb +++ b/app/views/avo/partials/_view_toggle_button.html.erb @@ -26,6 +26,15 @@
<% available_view_types.each do |type| %> <% is_active_view = view_type.to_s == type.to_s %> + <% + data = { + tippy: 'tooltip', + 'turbo-frame': turbo_frame, + control: "view-type-toggle-#{type}" + } + + data.merge(turbo_action: :advance) if @parent_record.blank? + %> <%= a_link url_for(params.permit!.merge(view_type: type)).to_s, icon: info[type][:new_icon], @@ -34,11 +43,7 @@ size: :sm, class: is_active_view ? "z-20" : "bg-gray-100 border-gray-300", title: t('avo.switch_to_view', view_type: type), - data: { - tippy: 'tooltip', - 'turbo-frame': turbo_frame, - control: "view-type-toggle-#{type}" - } + data: data %> <% end %>
diff --git a/spec/dummy/app/avo/actions/toggle_inactive.rb b/spec/dummy/app/avo/actions/toggle_inactive.rb index 84760248bf..dea909ee90 100644 --- a/spec/dummy/app/avo/actions/toggle_inactive.rb +++ b/spec/dummy/app/avo/actions/toggle_inactive.rb @@ -34,5 +34,9 @@ def handle(**args) end silent + close_modal + append_to_response -> { + turbo_stream.turbo_frame_set_src(@resource.model_key, src: @resource.records_path) + } end end