-
Notifications
You must be signed in to change notification settings - Fork 993
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
Fixes #37575 - Foreman Table columns sort is inconsistent #10213
Conversation
What if both weights are undefined? Should it sort on a secondary parameter like name or id? |
then it sorts it in the order the columns are in the object provided to the table |
Shouldn't it still return |
It will return 0 if both undefined since then the first if would be true |
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.
What I meant was that it needs to be:
if (columnAWeight === undefined && columnBWeight === undefined) {
return 0;
}
if (columnBWeight === undefined) {
return -1;
}
if (columnAWeight === undefined) {
return 1;
}
return columnAWeight - columnBWeight;
Because the sort interface says that when it's 0
they should be considered equal. Your current change implies that if columnBWeight
they're always equal, even if columnAWeight
isn't undefined.
Another way to look at it is that the function should be its inverse with a swapped order, or sort(a, b) == -sort(b, a)
.
Yeah changed to this logic instead, the weights are sorted in this way, from the doc:
|
@jeremylenz since I proposed the current version, would you mind reviewing? |
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.
Tested and LGTM 👍
To test you can open the models table in firefox and chrome and see that the order is different before the pr.
Firefox and Chrome implement the sort function differently