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

SortableList - Pass from and to indexes of changed item #3153

Merged
merged 7 commits into from
Jul 10, 2024

Conversation

nitzanyiz
Copy link
Contributor

Description

Adding option for onChange to send the indexes the item moved from and to.

Changelog

SortableList - onOrderChange now sends the old and new index of the changed item.

Additional info

MADS-4312

@nitzanyiz nitzanyiz changed the title on change sents from and to index of the change item SortableList - Pass from and to indexes of changed item Jun 27, 2024
@nitzanyiz nitzanyiz requested a review from ethanshar July 3, 2024 10:37
@nitzanyiz nitzanyiz marked this pull request as ready for review July 3, 2024 10:38
Copy link
Collaborator

@ethanshar ethanshar left a comment

Choose a reason for hiding this comment

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

Looks good, added a small comment

@@ -16,8 +16,8 @@
},
{
"name": "onOrderChange",
"type": "(data: ItemT[]) => void",
"description": "A callback to get the new order (or swapped items).",
"type": "(data: ItemT[], from: number, to: number) => void",
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider wrapping from and to in an object, just in case we'll have to pass more info in the future, we don't want to have lots of arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would have wanted to combine all the arguments to one object (like they do in RN draggable) but that would create a migration. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes it would require a migration and also combining all not necessarily the right solution
I personally like to have a main argument (the data) separated from the extra arguments that do grouped as an object
anyway there's no right or wrong, but we don't want to go into a migration just for that, so I think we can settle an adding the new info/data as an object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. I've added an info object to the callback that contains the from to values.

@@ -21,7 +21,7 @@ export interface SortableListProps<ItemT extends SortableListItemProps>
/**
* A callback to get the new order (or swapped items).
*/
onOrderChange: (data: ItemT[] /* TODO: add more data? */) => void;
onOrderChange: (data: ItemT[], from: number, to: number /* TODO: add more data? */) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

see my comment on the API

@nitzanyiz nitzanyiz requested a review from ethanshar July 7, 2024 09:16
@ethanshar ethanshar merged commit 34186d0 into master Jul 10, 2024
1 check passed
@ethanshar ethanshar deleted the feat/SortableListFromToIndexes branch July 10, 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