fix: use localeCompare to sort in mention list#45324
Conversation
Signed-off-by: dominictb <tb-dominic@outlook.com>
situchan
left a comment
There was a problem hiding this comment.
Please make utils and add unit test
|
on it now! |
|
@situchan done! |
Reviewer Checklist
Screenshots/VideosAndroid: Nativeandroid.mp4Android: mWeb Chromemchrome.mp4iOS: Nativeios.moviOS: mWeb Safarimsafari.movMacOS: Desktopdesktop.mov |
|
waiting for @situchan's review. |
|
@dominictb please merge main |
|
done! |
|
@dominictb @situchan please add screenshots/video for all platforms |
|
@dominictb also, QA Step is a bit confusing.
As a result, you should add:
|
|
@cead22 done! |
| function getDisplayName(p: PersonalDetails) { | ||
| const displayNameFromAccountID = ReportUtils.getDisplayNameForParticipant(p.accountID); | ||
| if (!displayNameFromAccountID) { | ||
| return p.login?.length ? p.login : ''; | ||
| } | ||
| return displayNameFromAccountID; | ||
| } |
There was a problem hiding this comment.
| function getDisplayName(p: PersonalDetails) { | |
| const displayNameFromAccountID = ReportUtils.getDisplayNameForParticipant(p.accountID); | |
| if (!displayNameFromAccountID) { | |
| return p.login?.length ? p.login : ''; | |
| } | |
| return displayNameFromAccountID; | |
| } | |
| function getDisplayName(details: PersonalDetails) { | |
| const displayNameFromAccountID = ReportUtils.getDisplayNameForParticipant(details.accountID); | |
| if (!displayNameFromAccountID) { | |
| return details.login?.length ? details.login : ''; | |
| } | |
| return displayNameFromAccountID; | |
| } |
| * the comparison function used to determine which user will come first in the sorted list | ||
| * generally, smaller weight means will come first, and if the weight is the same, we'll sort based on displayName/login and accountID |
There was a problem hiding this comment.
| * the comparison function used to determine which user will come first in the sorted list | |
| * generally, smaller weight means will come first, and if the weight is the same, we'll sort based on displayName/login and accountID | |
| * Comparison function to sort users. It compares weights, display names, and accountIDs in that order |
| // first, we should sort by weight | ||
| if (first.weight !== second.weight) { | ||
| return first.weight - second.weight; | ||
| } | ||
|
|
||
| // next we sort by display name | ||
| const displayNameLoginOrder = localeCompare(getDisplayName(first), getDisplayName(second)); | ||
| if (displayNameLoginOrder !== 0) { | ||
| return displayNameLoginOrder; | ||
| } | ||
| // then fallback on accountID as the final sorting criteria. |
There was a problem hiding this comment.
The jsdoc already explains this, and this says what the code is doing, which is obvious from reading the code. Since these comments don't follow our style guide (should use capital letters on the first word), I suggest removing them
| // first, we should sort by weight | |
| if (first.weight !== second.weight) { | |
| return first.weight - second.weight; | |
| } | |
| // next we sort by display name | |
| const displayNameLoginOrder = localeCompare(getDisplayName(first), getDisplayName(second)); | |
| if (displayNameLoginOrder !== 0) { | |
| return displayNameLoginOrder; | |
| } | |
| // then fallback on accountID as the final sorting criteria. | |
| if (first.weight !== second.weight) { | |
| return first.weight - second.weight; | |
| } | |
| const displayNameLoginOrder = localeCompare(getDisplayName(first), getDisplayName(second)); | |
| if (displayNameLoginOrder !== 0) { | |
| return displayNameLoginOrder; | |
| } |
| }); | ||
| }) as Array<PersonalDetails & {weight: number}>; | ||
|
|
||
| // at this point we are sure that the details are not null, since empty user details have been filtered in the previous step |
There was a problem hiding this comment.
| // at this point we are sure that the details are not null, since empty user details have been filtered in the previous step | |
| // At this point we are sure that the details are not null, since empty user details have been filtered in the previous step |
|
@cead22 updated. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/cead22 in version: 9.0.15-0 🚀
|
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.0.15-9 🚀
|



Details
Fixed Issues
$ #43845
PROPOSAL: #43845 (comment)
Tests
Pre-requisite: Create 4 account with name
águero,Bronn,Carol,Daniel.@Verify that the order in the mention list is
here,águero,Bronn,Carol,Daniel(or if you invite the above 4 accounts, should beaName,B,Bname,Workspace member)Offline tests
QA Steps
Pre-requisite: Create 4 account with name
águero,Bronn,Carol,Daniel(or any other equivalent names which highlight the alphabetical order). Or can invite the following account:natnael.expensify+idf6yd@gmail.com,
natnael.expensify+lajf088b@gmail.com,
natnael.expensify+ldjf66vd@gmail.com,
natnael.expensify+3@gmail.com
@Verify that the order in the mention list is
here,águero,Bronn,Carol,Daniel(or if you invite the above 4 accounts, should beaName,B,Bname,Workspace member)PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop