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

fix: render background context when accessing extrernal action links #2730

Merged
merged 10 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
24 changes: 24 additions & 0 deletions app/controllers/avo/actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ def show

@resource.hydrate(record: @record, view: @view, user: _current_user, params: params)
@fields = @action.get_fields

build_background_url
end

def build_background_url
uri = URI.parse(request.url)

# Remove the '/actions' segment from the path
path_without_actions = uri.path.sub(/\/actions/, '')
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved

params = URI.decode_www_form(uri.query || '').to_h
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved

params.delete('action_id')
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
params[:turbo_frame] = ACTIONS_BACKGROUND_FRAME

# Reconstruct the query string
new_query_string = URI.encode_www_form(params)

# Update the URI components
uri.path = path_without_actions
uri.query = (new_query_string == '') ? nil : new_query_string
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved

# Reconstruct the modified URL
@background_url = uri.to_s
end

def handle
Expand Down
4 changes: 4 additions & 0 deletions app/views/avo/actions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<%= turbo_frame_tag "index", src: @background_url, loading: :lazy, target: :_top, class: "block" do %>
<%= render Avo::LoadingComponent.new(title: "...") %>
<% end %>

<%= turbo_frame_tag Avo::ACTIONS_TURBO_FRAME_ID do %>
<div
data-controller="<%= ["action", @action.get_stimulus_controllers].join(" ") %>"
Expand Down
1 change: 1 addition & 0 deletions lib/avo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Avo
PACKED = !IN_DEVELOPMENT
COOKIES_KEY = "avo"
ACTIONS_TURBO_FRAME_ID = :actions_show
ACTIONS_BACKGROUND_FRAME = :actions_background

class LicenseVerificationTemperedError < StandardError; end

Expand Down
Loading