-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
feature: allow actions to render turbo streams #2796
Conversation
Code Climate has analyzed commit 5b269f4 and detected 1 issue on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
This PR has been marked as stale because there was no activity for the past 15 days. |
This PR has been marked as stale because there was no activity for the past 15 days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename it to respond_with
and left a few tweaks
enhance_response turbo_stream: -> { | ||
turbo_stream.set_title("Dummy action custom stream ;)") | ||
} | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename it to respond_with
and pass in an array or a single turbo_stream
action.
The reason why I'm thinking to not do this turbo_stream: ->
si because we only respond with turbo streams... It's a bit redundant to declare it every time, right?
Do you see any caveats?
enhance_response turbo_stream: -> { | |
turbo_stream.set_title("Dummy action custom stream ;)") | |
} | |
end | |
enhance_response turbo_stream: -> { | |
turbo_stream.set_title("Dummy action custom stream ;)") | |
} | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename it to
respond_with
...
respond_with
kinda sounds like is overriding the default responses.
enhance_response
- "Add this to response"
respond_with
- "Respond with this`
...and pass in an array or a single
turbo_stream
action.
The reason why I'm thinking to not do thisturbo_stream: ->
si because we only respond with turbo streams... It's a bit redundant to declare it every time, right?
Do you see any caveats?
You mean something like (I'll use enhance_response
until renaming):
enhance_response turbo_stream: turbo_stream.set_title("Dummy action custom stream ;)")
# OR
enhance_response turbo_stream.set_title("Dummy action custom stream ;)")
And for array:
enhance_response turbo_stream: [
turbo_stream.set_title("Dummy action custom stream ;)"),
turbo_stream...
]
# OR
enhance_response [
turbo_stream.set_title("Dummy action custom stream ;)"),
turbo_stream...
]
Do you see any caveats?
1 - not sure if turbo_stream
helper method is present.
2 - no more controller response context
end | ||
|
||
responses = if @action.enhanced_turbo_streams.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we include this if
statement in the case
statement above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scope of this feature is to add one or several turbo-stream responses to the pre-existing response
def handle(**args)
succeed "Modal closed!!"
close_modal
enhance_response turbo_stream: -> {
turbo_stream.set_title("Dummy action custom stream ;)")
}
end
For example on the code above we want the success message to be rendered, the modal to be closed then enhance that response with the turbo_stream.set_title("Dummy action custom stream ;)")
If we add the if statement on the case above the action would respond only with turbo_stream.set_title("Dummy action custom stream ;)")
ignoring succeed "Modal closed!!"
and close_modal
responses.
Naming suggestions: |
I like |
@adrianthedev changes & docs applied |
@@ -196,6 +197,7 @@ | |||
click_on "Run" | |||
expect(page).not_to have_selector(modal) | |||
expect(page).to have_text "Modal closed!!" | |||
expect(page).to have_title("Cool title") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[rubocop] reported by reviewdog 🐶
[Corrected] Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -196,6 +197,7 @@ | |||
click_on "Run" | |||
expect(page).not_to have_selector(modal) | |||
expect(page).to have_text "Modal closed!!" | |||
expect(page).to have_title("Cool title") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[rubocop] reported by reviewdog 🐶
[Corrected] Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
append_to_response -> { | ||
turbo_stream.set_title("Cool title") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't we settled on using an array notation?
I mean, why the extra block?
append_to_response -> { | |
turbo_stream.set_title("Cool title") | |
} | |
append_to_response([ | |
turbo_stream.set_title("Cool title") | |
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could do
append_to_response do
turbo_stream...
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forget about it. A block is enough. I hope users don't mistake it for the Execution Context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LEt's also discuss this possibility
# turbo_stream_response will be executed instead the default `render turbo_stream: responses` from actions controller
turbo_stream_response -> {
render turbo_stream: [
*default_responses, # can include or not the default responses
turbo_stream.set_title("Cool title"),
turbo_stream....
]
}
This PR has been merged into Please check the release guide for more information. |
Description
Fixes #2790
This PR enables enhancing action response by adding custom turbo streams.
Checklist:
Screenshots & recording
Manual review steps
Manual reviewer: please leave a comment with output from the test if that's the case.