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

feat: add drag n drop functionality to section cards #17

Merged
merged 16 commits into from
Dec 13, 2023

Conversation

steff456
Copy link

@steff456 steff456 commented Dec 4, 2023

Resolves private ref: BB-8219

This PR,

  • Adds an endpoint for reordering the list of sections
  • Adds the functionality for drag and drop the sections cards
  • Adds new tests for the functionality

Demo

Grabacion.de.pantalla.desde.05-12-23.22.51.02.mp4

Depends on

Testing instructions

Questions

  • I'm unsure if there's any preference on the style of the draggable objects, in the other front end they are using three dots so the users can understand they are able to drag and drop the cards.
  • The same question goes for the drag animation, right now it is using the default

@steff456 steff456 self-assigned this Dec 4, 2023
Copy link
Member

@navinkarkera navinkarkera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steff456 Even though I like that the custom drag-n-drop implementation, we should probably use something like react-DnD as the current implementation is bit confusing as their is no indication about the drop position and implementing it by hand will require a lot more effort and time. See this example, we want something similar. Also, after dropping an item it should not go back to its original position and wait for the API to complete, instead it should update the UI first and then update the backend via API and if for some reason the API call fails, we display an error message (which is already handled in exception handling).

I'm unsure if there's any preference on the style of the draggable objects, in the other front end they are using three dots so the users can understand they are able to drag and drop the cards.

We don't need to add the three dots as per the new design. The curson already updates as expected so we don't need any changes in UI.

The same question goes for the drag animation, right now it is using the default

We can keep the default animation for now from the example

@navinkarkera navinkarkera force-pushed the navin/course-outline/section branch 3 times, most recently from 98fdf30 to 8734daa Compare December 5, 2023 11:12
@steff456
Copy link
Author

steff456 commented Dec 5, 2023

@navinkarkera I'll modify the implementation to use react-dnd and ping you once it is ready :)

@steff456
Copy link
Author

steff456 commented Dec 6, 2023

@navinkarkera I just updated to use dnd-react library, I also updated the demo video in the description. With this changes now the UI updates first and then it sends the new order to the backend and now the animation is the same as the example you provided.

Tomorrow I'll work on adding some tests :)

Copy link
Member

@navinkarkera navinkarkera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steff456 Thanks, I just pushed a commit to fix multiple requests on hover issue.

I see ~43 new commits as you seem to have use merge commit instead of rebasing with the base branch. Can you try to create a new branch from the base and cherry pick your and my last commit to cleanup the commit history?

src/course-outline/CourseOutline.jsx Outdated Show resolved Hide resolved
@navinkarkera navinkarkera force-pushed the navin/course-outline/section branch from 8734daa to 61ff8f4 Compare December 7, 2023 07:32
Copy link
Member

@navinkarkera navinkarkera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steff456 Almost there. We have one more issue where if you try to select text via dragging the mouse in title while editing it, it drags the whole section. Maybe this issue can help fixing it: react-dnd/react-dnd#335

src/course-outline/CourseOutline.jsx Show resolved Hide resolved
@steff456
Copy link
Author

steff456 commented Dec 8, 2023

@navinkarkera the last commit fixes the text editing issue. Please let me know if there's anything else this PR needs.

Copy link

codecov bot commented Dec 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (navin/course-outline/section@f181ca1). Click here to learn what that means.

❗ Current head 6760328 differs from pull request most recent head 8371ce1. Consider uploading reports for the commit 8371ce1 to get more accurate results

Additional details and impacted files
@@                       Coverage Diff                       @@
##             navin/course-outline/section      #17   +/-   ##
===============================================================
  Coverage                                ?   87.94%           
===============================================================
  Files                                   ?      482           
  Lines                                   ?     7542           
  Branches                                ?     1603           
===============================================================
  Hits                                    ?     6633           
  Misses                                  ?      880           
  Partials                                ?       29           

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

Copy link
Member

@navinkarkera navinkarkera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steff456 The functionality now works as expected. We have an issue in firefox where the text inside the form cannot be selected. We can address this in a separate ticket as HTML5 drag n drop has some issues with firefox. For now it looks good.

We should add some tests (probably in CourseOutline.test.jsx) to test ordering when it runs successfully as well as when something goes wrong (restoreCallback).

src/course-outline/section-card/SectionCard.jsx Outdated Show resolved Hide resolved
@navinkarkera navinkarkera force-pushed the navin/course-outline/section branch from 61ff8f4 to 6567ed9 Compare December 11, 2023 14:35
@steff456
Copy link
Author

@navinkarkera now we have tests for the endpoints, as well I rebased this PR with the changes you made recently in your base branch.

Please let me know what else is needed for this PR to be ready!

@steff456
Copy link
Author

@navinkarkera I just updated this branch with the latest changes of the base branch. I had to do some modifications for the scroll to work with the drag and drop given that both were using refs and useEffect simultaneously, but everything is working as expected now. The CI failed because of coverage, which I suspect is because of the fork and base branch PR.

Please let me know if there's anything else needed in this PR for merging!

@navinkarkera
Copy link
Member

@steff456 The scrolling was not working properly after deleting a section. Also it broke scrolling for subsections.

I pushed a fix such that the page will only scroll if the element is not visible and it will align based on the position of the element in the screen. Now it works for both sections and subsections.

I'll merge this now. Thanks for you work!

@steff456
Copy link
Author

Thanks for all the review @navinkarkera! 🎉

@navinkarkera navinkarkera merged commit a68964a into navin/course-outline/section Dec 13, 2023
3 checks passed
@xitij2000 xitij2000 deleted the steff456/dragndrop branch January 15, 2024 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants