Skip to content

Add drag and drop prioritization to K2 #252

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

Merged
merged 34 commits into from
Apr 24, 2025
Merged

Conversation

neil-marcellini
Copy link
Contributor

@neil-marcellini neil-marcellini commented Apr 8, 2025

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/480259

Tests

  1. Adjust priorities via drag and drop in each bucket
  2. Verify they persist after a page refresh
  3. Toggle filters to show more issues
  4. Verify unprioritized issues display below prioritized issues
  5. Change the priority label of an issue (daily to weekly). Do it manually because there's an existing bug on main with the K2 buttons
  6. Verify it moves to the new list below the prioritized items
2025-04-18_13-01-17.mp4

@neil-marcellini neil-marcellini self-assigned this Apr 8, 2025
@neil-marcellini neil-marcellini marked this pull request as ready for review April 9, 2025 15:03
@neil-marcellini neil-marcellini requested a review from a team April 9, 2025 15:03
@melvin-bot melvin-bot bot requested review from inimaga and removed request for a team April 9, 2025 15:04
@inimaga
Copy link

inimaga commented Apr 10, 2025

@neil-marcellini Noob question. How do I package and install this in my browser for testing? I have tried downloading the source code as zip from your branch, and uploading this as unpacked but get a manifest error.

image

@neil-marcellini
Copy link
Contributor Author

neil-marcellini commented Apr 10, 2025

@neil-marcellini Noob question. How do I package and install this in my browser for testing? I have tried downloading the source code as zip from your branch, and uploading this as unpacked but get a manifest error.

Please git clone the repo and follow the instructions in the README. Let me know if you have other questions.

@neil-marcellini neil-marcellini requested a review from tgolen April 10, 2025 13:35
@neil-marcellini
Copy link
Contributor Author

Also requesting a review from Tim because I think he's done a lot of work on K2

@inimaga
Copy link

inimaga commented Apr 10, 2025

Able to replicate testing without issues. Including positions after page refresh.

K2.testing.mp4

inimaga
inimaga previously approved these changes Apr 10, 2025
@neil-marcellini
Copy link
Contributor Author

Oh, Tim is OOO for a week so I'll ask someone else.

@neil-marcellini neil-marcellini requested review from a team and removed request for tgolen April 10, 2025 16:46
@melvin-bot melvin-bot bot requested review from dangrous and removed request for a team April 10, 2025 16:46
Copy link
Contributor

@dangrous dangrous left a comment

Choose a reason for hiding this comment

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

Neat! code looks good - only issue - react-beautiful-dnd is dying at the end of April. We're replacing it with dnd-kit in App, we might want to do this here as well? Expensify/App#59231

Let me know what you think, it might not be worth the extra work but would be more future proof.

@neil-marcellini
Copy link
Contributor Author

Oh wow great to know, I'm glad Pullerbear chose you to review. Yeah sure I can try switching it to dnd-kit.

@neil-marcellini
Copy link
Contributor Author

Wow updating to that new library was kind of a pain, since it seems to be a bit more complex, but it's working well now! Please review again.

@neil-marcellini neil-marcellini marked this pull request as ready for review April 18, 2025 20:13
@neil-marcellini neil-marcellini requested a review from tgolen April 21, 2025 21:31
@neil-marcellini
Copy link
Contributor Author

Thanks for the review @tgolen. Updated.

Comment on lines +202 to +204
// Update local order immediately for UI feedback
const newOrder = arrayMove(_.pluck(filteredData, 'id'), oldIndex, newIndex);
setLocalOrder(newOrder);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me understand why the local order is being used, rather than keeping everything in Onyx and having this component subscribe to the Onyx priorities? That would still give the user immediate feedback, wouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Everything is kept in Onyx and the component subscribes through useOnyx to the priorities. Originally I did not use the local order state and used Onyx only. It worked fine with the react-beautiful-dnd library. Later, I switched to dnd-kit, since the other library is going to be deprecated soon. After that there was an issue with the UI where the dragged item would briefly jump back to it's original position, then jump to where it was dropped. I believe that's because Onyx.set is not synchronous, and that's further confirmed by the fact that using and setting this localOrder state fixes the problem.

I definitely don't love it since it's pretty complicated to keep the state in sync. However, it seems necessary to make this work properly. I can record a video of the bug if you like or you can checkout a commit before I added the local order and view it yourself.

Are you ok with leaving this in now? Should I clarify any comments in the code? Is there something else you would recommend?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, thanks for explaining that a little. Did you happen to look into https://github.com/react-dnd/react-dnd/ at all? Maybe it's worth giving it a quick look to see if we don't need to do this local state thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I guess I can try that out

Copy link
Contributor Author

@neil-marcellini neil-marcellini Apr 23, 2025

Choose a reason for hiding this comment

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

I tried out react-dnd briefly, using Onyx only, and it had similar and even worse issues. I believe this flashing is due to repeated updates to the component when the hovering and the async nature of them.

If you're cool with it I think we should keep the current library and keep using local state for synchronous updates.

2025-04-22_20-09-53.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, sounds good. Thanks for looking into it.

@neil-marcellini neil-marcellini requested a review from tgolen April 23, 2025 03:16
Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

It would be great to extend this so that items could be dragged between columns in order to change the daily/weekly/monthly labels. Maybe something you could work on next!

@neil-marcellini
Copy link
Contributor Author

It would be great to extend this so that items could be dragged between columns in order to change the daily/weekly/monthly labels. Maybe something you could work on next!

Yeah I was thinking that too! I wanted to keep the initial version focused but that would certainly make it feel more complete. It would also be nice to be able to view other people's priorities when viewing their dashboards, but I'm not sure where we would store the information tied to a user's account.

@tgolen
Copy link
Contributor

tgolen commented Apr 24, 2025

but I'm not sure where we would store the information tied to a user's account.

Yeah, there is no central place to store this. There used to be some code in here which kept a shared "database" in a GH Gist. I put database in quotes because it was just a Gist with a JSON file that could be written to and read from.

The file was here but removed at some point because we stopped using it.

Copy link
Contributor

@dangrous dangrous left a comment

Choose a reason for hiding this comment

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

Very neat!

@neil-marcellini neil-marcellini merged commit 052b06c into main Apr 24, 2025
3 checks passed
@neil-marcellini neil-marcellini deleted the neil-priority-ordering branch April 24, 2025 17:40
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.

4 participants