Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: wrap index table on a turbo_frame #3347

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/components/avo/resource_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions app/components/avo/turbo_frame_wrapper_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
<% if @name.present? %><turbo-frame id="<%= @name %>"><% 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? %></turbo-frame><% end %>
<%= render_content %>
16 changes: 15 additions & 1 deletion app/components/avo/turbo_frame_wrapper_component.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# 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
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
# 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
1 change: 1 addition & 0 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions app/views/avo/base/index.html.erb
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/app/avo/actions/toggle_inactive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ def handle(**args)
end

silent
close_modal
append_to_response -> {
turbo_stream.turbo_frame_set_src(@resource.model_key, src: avo.resources_users_path)
}
end
end
Loading