Skip to content

Commit

Permalink
fix: Rename Turbo Stream helpers to avoid clashes in user apps (#3462)
Browse files Browse the repository at this point in the history
  • Loading branch information
dark-panda committed Nov 27, 2024
1 parent c60e854 commit 5c89f7d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions app/controllers/avo/actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ def respond
turbo_response = case @response[:type]
when :keep_modal_open
# Only render the flash messages if the action keeps the modal open
turbo_stream.flash_alerts
turbo_stream.avo_flash_alerts
when :download
# Trigger download, removes modal and flash the messages
[
turbo_stream.download(content: Base64.encode64(@response[:path]), filename: @response[:filename]),
turbo_stream.close_modal,
turbo_stream.flash_alerts
turbo_stream.avo_download(content: Base64.encode64(@response[:path]), filename: @response[:filename]),
turbo_stream.avo_close_modal,
turbo_stream.avo_flash_alerts
]
when :navigate_to_action
src, _ = @response[:action].link_arguments(resource: @action.resource, **@response[:navigate_to_action_args])
Expand All @@ -125,8 +125,8 @@ def respond
when :close_modal
# Close the modal and flash the messages
[
turbo_stream.close_modal,
turbo_stream.flash_alerts
turbo_stream.avo_close_modal,
turbo_stream.avo_flash_alerts
]
else
# Reload the page
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def reload_frame_turbo_streams
turbo_streams = super

# We want to close the modal if the user wants to add just one record
turbo_streams << turbo_stream.close_modal if params[:button] != "attach_another"
turbo_streams << turbo_stream.avo_close_modal if params[:button] != "attach_another"

turbo_streams
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def destroy_fail_action
flash[:error] = destroy_fail_message

respond_to do |format|
format.turbo_stream { render turbo_stream: turbo_stream.flash_alerts }
format.turbo_stream { render turbo_stream: turbo_stream.avo_flash_alerts }
end
end

Expand Down Expand Up @@ -660,7 +660,7 @@ def sanitized_sort_direction
def reload_frame_turbo_streams
[
turbo_stream.turbo_frame_reload(params[:turbo_frame]),
turbo_stream.flash_alerts
turbo_stream.avo_flash_alerts
]
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/avo/turbo_stream_actions_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module Avo
module TurboStreamActionsHelper
def download(content:, filename:)
def avo_download(content:, filename:)
turbo_stream_action_tag :download, content: content, filename: filename
end

def flash_alerts
def avo_flash_alerts
turbo_stream_action_tag :append,
target: "alerts",
template: @view_context.render(Avo::FlashAlertsComponent.new(flashes: @view_context.flash.discard))
end

def close_modal
def avo_close_modal
turbo_stream_action_tag :replace,
target: Avo::MODAL_FRAME_ID,
template: @view_context.turbo_frame_tag(Avo::MODAL_FRAME_ID, data: {turbo_temporary: 1})
Expand Down

0 comments on commit 5c89f7d

Please sign in to comment.