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

[Admin] Open edit and new forms in dialog with turbo frame #6046

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Dec 20, 2024

Depends on #6048

Summary

Opens new and edit forms of Admin resources in dialogs with Turbo Frames.
Removing the need of rendering the index table again on the form components.

Also handles the layout toggle for all turbo frame requests.

Includes the ground work from #6045

  • Shipping Categories
  • Adjustment reasons
  • Return reasons
  • Store credit reasons
  • Refund reasons
  • Tax categories
  • User roles
  • Add user store credit
  • Edit Stock items

Closes #5944

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch 2 times, most recently from 22f5345 to 5e2c4da Compare December 20, 2024 10:57
3.21.0 introduced a bug with testing view components.
@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch from 5e2c4da to 909607d Compare December 20, 2024 20:02
@tvdeyen tvdeyen changed the title [Admin] Open Shipping Categories edit and new forms in dialog with turbo frame [Admin] Open edit and new forms in dialog with turbo frame Dec 20, 2024
@tvdeyen tvdeyen marked this pull request as ready for review December 20, 2024 20:05
@tvdeyen tvdeyen requested a review from a team as a code owner December 20, 2024 20:05
@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch 2 times, most recently from 354c7c2 to a1e9278 Compare December 20, 2024 20:28
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 94.87179% with 6 lines in your changes missing coverage. Please review.

Project coverage is 89.59%. Comparing base (9234436) to head (0e5c4dc).

Files with missing lines Patch % Lines
...ontrollers/solidus_admin/stock_items_controller.rb 50.00% 2 Missing ⚠️
...rollers/solidus_admin/tax_categories_controller.rb 50.00% 2 Missing ⚠️
...nts/solidus_admin/tax_categories/edit/component.rb 0.00% 1 Missing ⚠️
...rollers/solidus_admin/return_reasons_controller.rb 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6046      +/-   ##
==========================================
+ Coverage   87.82%   89.59%   +1.77%     
==========================================
  Files         477      791     +314     
  Lines       11670    18254    +6584     
==========================================
+ Hits        10249    16355    +6106     
- Misses       1421     1899     +478     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch 2 times, most recently from 162d93c to ca8ae78 Compare December 20, 2024 21:07
@chaimann
Copy link

@tvdeyen i've checked out your branch and here's the screen recording of the "issues" i mentioned. You can see when I open the edit page in the new tab and click outside, it makes a request to edit url. Also when I click update the modal stays open.

However, I guess I understood it incorrectly what you meant about being able to visit the edit page. In my PR I have done it in a way that the underlying table is still rendered on edit page which I thought was your goal.
So in case we want to have just a modal on the edit page and nothing else, not closing it on all occasions specified above may still be a desired behaviour since we are not rendering anything else other than a modal, so basically there's no need to close it 😄

Screen.Recording.2024-12-20.at.23.38.25.mov

Though there's one more thing I discovered, not related to visiting edit page, but opening a modal with "turbo-framed" link and clicking outside:

Screen.Recording.2024-12-20.at.23.50.35.mov

as you can see it makes a request to index which I'm sure is unnecessary in this circumstance. Probably has something to do with how the clicking outside is implemented, but I have not yet checked how it works so can't tell for sure

@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch 2 times, most recently from 3776427 to 6b476d4 Compare December 20, 2024 23:47
If a table has no rowUrl defined we currently redirect to
root path. Which is not preferable. We should do nothing instead.
We do not want to render the whole layout if the request
is a turbo frame request. We just want to render the
component's html.
@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch from f566aa1 to fd5cbe3 Compare December 23, 2024 08:48
@tvdeyen
Copy link
Member Author

tvdeyen commented Dec 23, 2024

@chaimann Now, I understand what you meant. Thanks for the screen recording. This helps to understand the issue.

@tvdeyen i've checked out your branch and here's the screen recording of the "issues" i mentioned. You can see when I open the edit page in the new tab and click outside, it makes a request to edit url. Also when I click update the modal stays open.

However, I guess I understood it incorrectly what you meant about being able to visit the edit page. In my PR I have done it in a way that the underlying table is still rendered on edit page which I thought was your goal. So in case we want to have just a modal on the edit page and nothing else, not closing it on all occasions specified above may still be a desired behaviour since we are not rendering anything else other than a modal, so basically there's no need to close it 😄

Yeah, I think that we do not display the index table on the /new routes is preferable. But we should adopt the layout. Maybe simply remove the dialog when the request is not a turbo-frame request?

The same is true for the redirect after successful form submission.
I will add something that makes the redirect dependent from the kind of request.

Though there's one more thing I discovered, not related to visiting edit page, but opening a modal with "turbo-framed" link and clicking outside:

as you can see it makes a request to index which I'm sure is unnecessary in this circumstance. Probably has something to do with how the clicking outside is implemented, but I have not yet checked how it works so can't tell for sure

This is how @close_path is implemented. I can see if we can change that, but in the end it's something I can live with in this case.

tvdeyen and others added 8 commits December 23, 2024 09:56
We don't want to deal with Turbo caching issues in the new admin.
The content a customer agent or product administrator should always be
the latest and most accurate version.

Prefetching is a performance nightmare for an admin interface like ours.

Co-authored-by: Eugene Chaikin <[email protected]>
This is actual links to open the new and edit forms in the modal dialog
remotely.
@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch from fd5cbe3 to 0e5c4dc Compare December 23, 2024 14:56
That way we can disdplay the modal on an edit/new route but prevent
the modal from being closed by the user.
@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch 3 times, most recently from 6770fa3 to 3995aa3 Compare December 23, 2024 15:46
In order to make redirects to the index route from an edit or new
form and being able to re-display the form with errors in case of
failed validation, we need to explicitely set the request format to html, otherwise turbo will refresh the edit/new page.
@tvdeyen tvdeyen force-pushed the open-modal-content-remotely branch from 3995aa3 to 05dabbd Compare December 23, 2024 15:49
@tvdeyen tvdeyen marked this pull request as draft December 23, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Admin] Table component rows do not contain links
2 participants