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

Create a belongs_to record from the associated record screen #1556

Closed
adrianthedev opened this issue Jan 28, 2023 · 11 comments · Fixed by #1876
Closed

Create a belongs_to record from the associated record screen #1556

adrianthedev opened this issue Jan 28, 2023 · 11 comments · Fixed by #1876

Comments

@adrianthedev
Copy link
Collaborator

adrianthedev commented Jan 28, 2023

Feature

In a Post has_many Comments example, when on a Comment new page, next to the posts dropdown you'd have a plus icon which when clicked it will open a modal with the post form ready to create a new post.

From here

Aproach

The way I would go about it is like this:

  1. update the belongs_to edit field to add that, plus link
  2. it links to the create screen with a special via_ attribute
  3. that lets the controller know to use a different view from the base/new.html.erb. it will use a new view that is wrapped inside a modal. it will also be wrapped in a turbo-frame element similar to how actions work
  4. that new modal new view would actually load up the Avo::Views::ResourceEditComponent in a large modal window.
  5. The modal window will have the submit button that will save the form's record.
  6. after the update action goes through, we need a way to reload the belongs_to dropdown field. we can't do a full page reload because the user might have pre-filled other fields and they won't appreciate loosing those values

Other considerations

  1. a nice to have would be to have that new record selected on the field reload
  2. this should work nicely with the searchable belongs_to field
  3. the modal should ensure that it displays validation errors if they may incur
  4. ideally it will not use any custom JS and work on native Turbo methods
  5. it should not worsen the experience for the create action and belongs_to field

Screenshots

A rough sketch of how envision it to look

CleanShot 2023-01-28 at 12 39 30

@github-actions
Copy link
Contributor

This issue has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Feb 13, 2023
@github-actions
Copy link
Contributor

Closing this because there was no activity for the past 15 days. Feel free to reopen if new information pops up ✌️

@sdcoffey
Copy link
Contributor

Hey @adrianthedev, did a way to do this ever make it into a release of Avo? Would love to use this feature. Thanks!

@adrianthedev
Copy link
Collaborator Author

Nope. Not yet.

I' love to get some time to work on it. We'd also merge a PR if we had one. Shouldn't be suuuuper dificult.

@adrianthedev adrianthedev reopened this Jul 25, 2023
@sdcoffey
Copy link
Contributor

Challenge accepted!

@adrianthedev
Copy link
Collaborator Author

🔥🔥🔥

My approach would be:

  • add a plus button net to the select
  • that will load up a modal with a turbo_frame pointing to a new view with the parent in the URL (ex: https://main.avodemo.com/avo/resources/users/new?via_record_id=4&via_relation=teams&via_relation_class=Team)
  • (this is something that I don't know by heart how to solve), but the controller should create the new record already associated with the parent
  • the controller would respond with aturbo_stream response that would close the modal and update the select field with the new option (probably regenerate it somehow)

Feel free to build it otherwise if you want that, and let me know if you need help navigating the codebase.

... and thank you!

@sdcoffey
Copy link
Contributor

@adrianthedev took a stab at this here. I went about this in mostly the way you recommended with some minor variations. Let me know your feedback!

@adrianthedev
Copy link
Collaborator Author

I have this on the radar @sdcoffey. We're a bit busy with the public beta launch, so we're probably going to have a look later next week.

Thank you for doing the grind like this ❤️

@sdcoffey
Copy link
Contributor

sdcoffey commented Aug 2, 2023

Sounds great! Thanks @adrianthedev

@github-actions
Copy link
Contributor

This issue has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Aug 18, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2023

Closing this because there was no activity for the past 15 days. Feel free to reopen if new information pops up ✌️

@github-actions github-actions bot closed this as completed Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants