-
-
Notifications
You must be signed in to change notification settings - Fork 213
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 assigning Stimulus controllers to actions #2039
feature: allow assigning Stimulus controllers to actions #2039
Conversation
Code Climate has analyzed commit 4211289 and detected 0 issues on this pull request. View more on Code Climate. |
f910f34
to
f61bbac
Compare
…ontrollers concern
@Paul-Bob I have a problem with failing
|
It's not related @bryszard, don't worry. We're missing some translation on a new feature |
…ead of array In the implementation for resources we're using string. I'm not convinced that this is a right approach, but I'm applying same convention here.
@Paul-Bob Ok, in that case I think it's ready for review :). |
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.
Thanks for the PR @bryszard ! It looks great and complete with docs and tests!
Thank you, Paul :). So, it will be merged only to version 2.0? Or also copied to 3.0? |
Everything that is merged into |
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.
Look good! Thanks @bryszard! This is going to improve actions so much!
Description
Fixes # 1938
Context
As explained in the linked issue, we want to be able to assign Stimulus controllers to actions, similarly as we do to the resources.
I was considering reusing the controller assigned to the resource, but I've decided that would make the feature less flexible and less understandable. Why should we be binding the JS logic on action to a given resource? What if we'd like to reuse an action for different resources?
Changes
In order to enable the feature I had to do the following:
stimulus_controllers
class attribute andget_stimulus_controllers
instance method toBaseAction
.I've considered reusing the concern
HasStimulusControllers
, but it would be an overfit in here because as far as I understand we don't need to add view type specific attributes.action
to theBaseField
in order to later use it while rendering.controller
to the top-level action element andtarget
to all fields in the action form.As an example I've reused existing Stimulus controller
course_resource_controller
.I've renamed to
city_in_country_controller
, because it is not specific to course resource.Out of scope
What are differences from the Stimulus controllers added for resources:
resource-edit
,resource-show
, andresource-index
.view
attribute to the DOM. The main reason is that currently standalone action is getting theview
value from here and it will be always:new
. To get the "real" value I believe some refactoring would be required.Let me know if you think we should do it differently.
Checklist:
Visual QA
2023-11-19.00-39-04.mp4
Manual review steps
Manual reviewer: please leave a comment with output from the test if that's the case.