-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
Create a belongs_to
record from the associated record screen
#1876
Create a belongs_to
record from the associated record screen
#1876
Conversation
app/javascript/js/controllers/fields/reload_belongs_to_field_controller.js
Show resolved
Hide resolved
Code Climate has analyzed commit 528432c and detected 0 issues on this pull request. View more on Code Climate. |
belongs_to
record from the associated record screenbelongs_to
record from the associated record screen
This PR has been marked as stale because there was no activity for the past 15 days. |
@Paul-Bob can you please also have a look over this when you get a chance? Thank you. |
Hi @sdcoffey, first of all thank you for the amazing PR. I've been testing it and came across a few issues. The modal that opens for the belongs_to creation seems a little unpolished, for example, when creating an user or some record that have a big resource it expands to full height, maybe we should assure some margins. It's no biggie. My main concern revolves around the form errors. They no longer seem to show up when submitting a form and some validation fails. It happens due turbo-stream I think. We should focus on solving this error rendering issue first. Otherwise, the functionality seems to be there, good job! |
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 assure that errors render on the form when validations fails
<%= turbo_stream.append "alerts" do %> | ||
<%= render Avo::FlashAlertsComponent.new flashes: flash %> | ||
<% 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.
Maybe we should rename this stream to .../_flash_alerts.turbo_stream.erb
I think it fits better to the file porpoise.
Thanks for the review @Paul-Bob! Will take another look at the issue with large resources and fix the missing validation errors (totally missed that). Will ping you again when I've finished updating |
Hey all! Been a couple weeks since the last activity, wanted to bump this to see about getting it across the finish line |
Yes @sdcoffey. You're right! It's on me to review it. I'll give it a go tomorrow. |
No worries, just wanted to make sure it didn't get lost–I'm sure y'all are busy! Thank you! 🙏 |
@sdcoffey it works great but I need to check the code a bit and the styling. It's on my plate for the weekend. |
Sounds good! Thank for the update |
Thanks @sdcoffey for the contribution. |
🙏 No worries! Thanks for the cleanup. Excited to see this make it into the next release! |
Yes. It will be out on Tuesday 🙌 |
</div> | ||
<% end %> | ||
|
||
<% if content? %> |
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 think this content?
call is causing a NoMethodError
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.
@segiddins can you describe the scenario? I wasn't able to reproduce it
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.
rubygems/rubygems.org#4154 yeah, tests started failing on the version bump
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.
👀
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 think you might need to update view_component
on your end.
I can't put my finger on it exactly, but at some point they changed the way they figure out if the slot has any content inside.
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 see that view_component v3 added this helper. Are you able to update to VC 3 @segiddins?
I see that you are already on 2.8+ which should not bring breaking changes AFAIK.
I'm getting a error trying to use new resource links introduced by this PR. e.g. this URL
but this works just fine Trace example:
|
@sdcoffey could you please take a look? ^^ It doesn't open a modal for me, it just goes to the link and shows a "No route" error. |
@xeron was this fixed for you? I can't replicate it on my end. |
No, I tried to remove all my avo customizations:
also tried downgrading rails from 7.1 to 7.0. And it still didn't work. Clicking I'll try to create a minimal app which reproduces the issue. |
Can you check if you have a JS error somewhere. To me that sounds like the JS is not working. Or Turbo doesn't execute it as a Turbo request. |
This was the 1st thing I did when I faced the issue :) Anyway I think I found the problem. Enabling the following in config.buttons_on_form_footers = true |
I've reported it as an issue for tracking purposes: #2008 |
Pfff. What a weird bug! |
Back button without valid path was rendering on the form footer, this PR fixes it. Thanks for pointing to the right point and for building a detailed issue! |
It would indeed be important to be able to disconnect this option, if possible at field level. For example I have "Task belongs_to User", I can pick a User (searchable). This certainly does not mean that I can create a User. Maybe there's another way to disable it? Thx. |
I was thinking about the same. This feature should be opt-in or opt-out in In fact I even had this in my code before: field :driver, as: :belongs_to,
help: 'You can add new drivers <a href="/admin/resources/drivers/new" target="_blank">here</a>', So this feature automatically added duplicate functionality to some of my fields. |
Yup. That makes sense. |
Description
Allows creation of a
belongs_to
record from the new or edit pages of a resource.Accomplished this by:
Create new x
below the belongs_to field. This link points to the associated resource'snew
view with a special url param:via_belongs_to_resource_class
.BaseController#new
to render a turbo stream adding a modal to the page containing the associated resource'snew
view, when the above param is present.BaseController#create_success_action
to, when the above param is present, render two turbo streams, one removing the modal, and the other containing a custom event with the details of the new record.Fixes #1556
Checklist:
Manual review steps
Course
fromedit
/new
ofCourse::Link
- searchable belongs_to associationUser
fromedit
/new
ofFish
- belongs_to with normal HTML selectPost
orProject
fromnew
/edit
ofComment
- polymorphic belongs_toFish
fromnew
/edit
ofReview
- searchable, polymorphic belongs_toManual reviewer: please leave a comment with output from the test if that's the case.
Open Questions
CompactUser
)?