-
Notifications
You must be signed in to change notification settings - Fork 492
Sort cards before state update #337
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
Conversation
a1d56be to
ec2548d
Compare
ec2548d to
e762557
Compare
Co-Authored-By: Bruno Castro <bruno.castro@codeminer42.com>
Co-Authored-By: Bruno Castro <bruno.castro@codeminer42.com>
61f7ce8 to
494cbf1
Compare
494cbf1 to
224ad79
Compare
dapi
left a comment
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.
@belgamo hi!
Thank you very much for such detailed PR!
I pulled this branch and have played with some stories and found that basic scenario with card dragging does not work as it expected.
Here is sample - http://g.recordit.co/DjFi6MNr34.gif
|
Probably we need to disable card dragging when |
| if (lane.id === laneId) { | ||
| if (index !== undefined) { | ||
| return update(lane, {cards: {$splice: [[index, 0, ...newCards]]}}) | ||
| let cardsToUpdate = [...lane.cards, ...newCards] |
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.
@dapi Hi!
I think your comment #337 (comment) makes sense! However, the problem occurs because this line changes the original cards and this influences their order even when the laneSortFunction is not used. I suggest the code bellow:
if (laneSortFunction) {
let cardsToUpdate = [...lane.cards, ...newCards]
cardsToUpdate.sort(laneSortFunction)
return update(lane, {cards: {$set: cardsToUpdate}})
}
return update(lane, {cards: {$splice: [[index, 0, ...newCards]]}})
What do you think?
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.
Hi @belgamo!
What is you use case to sort cards? Do you save these cards to backend? Does it sort on backend also?
Pay attention to there are event bus and we need to emit MOVE_CARD event to every moved card if it is resorted.
I think the better way to give possibility to customise appendCardsToLane function using dependency injection.
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.
One more thought. Can we use event MOVE_CARD to catch this moment and resort cards as we want?
|
Hey guys. what's the status on this? I just spend like 2 hours to track this problem down until I found that somebody already did it... 😱 |
|
Guys this solution is not working. Seen the same thing. I have just merged with the v2.2.8 and is the same as before. |
dapi
left a comment
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.
either respect event bus and emit event for resorted cards or use dependency injection to customise appendCardsToLane
When I needed to use the
laneSortFunctionI notice that it's work fine in a single lane as showed in the story example. But there's a bug when I have more than one lane. The react-trello gets confused with the new indexes and consequently move wrong cards on dragging and dropping.I fixed the issue by reordering the cards before they were added on the lane.