-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Refactored localeCompare in ReportUtils (part 3) #68101
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
Changes from all commits
b98a1c5
f7c5068
e3fbe0b
b0f512b
42ace3b
5b5fb58
def0523
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,8 +279,6 @@ | |
| totalDisplaySpend: number; | ||
| }; | ||
|
|
||
| type ParticipantDetails = [number, string, AvatarSource, AvatarSource]; | ||
|
|
||
| type OptimisticAddCommentReportAction = Pick< | ||
| ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT>, | ||
| | 'reportActionID' | ||
|
|
@@ -914,7 +912,7 @@ | |
| const parsedReportActionMessageCache: Record<string, string> = {}; | ||
|
|
||
| let conciergeReportID: OnyxEntry<string>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.CONCIERGE_REPORT_ID, | ||
| callback: (value) => { | ||
| conciergeReportID = value; | ||
|
|
@@ -922,7 +920,7 @@ | |
| }); | ||
|
|
||
| const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon'; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.SESSION, | ||
| callback: (value) => { | ||
| // When signed out, val is undefined | ||
|
|
@@ -940,7 +938,7 @@ | |
| let allPersonalDetails: OnyxEntry<PersonalDetailsList>; | ||
| let allPersonalDetailLogins: string[]; | ||
| let currentUserPersonalDetails: OnyxEntry<PersonalDetails>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
| callback: (value) => { | ||
| if (currentUserAccountID) { | ||
|
|
@@ -952,14 +950,14 @@ | |
| }); | ||
|
|
||
| let allReportsDraft: OnyxCollection<Report>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT_DRAFT, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => (allReportsDraft = value), | ||
| }); | ||
|
|
||
| let allPolicies: OnyxCollection<Policy>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.POLICY, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => (allPolicies = value), | ||
|
|
@@ -967,7 +965,7 @@ | |
|
|
||
| let allReports: OnyxCollection<Report>; | ||
| let reportsByPolicyID: ReportByPolicyMap; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -1008,14 +1006,14 @@ | |
| }); | ||
|
|
||
| let allBetas: OnyxEntry<Beta[]>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.BETAS, | ||
| callback: (value) => (allBetas = value), | ||
| }); | ||
|
|
||
| let allTransactions: OnyxCollection<Transaction> = {}; | ||
| let reportsTransactions: Record<string, Transaction[]> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -1041,7 +1039,7 @@ | |
| }); | ||
|
|
||
| let allReportActions: OnyxCollection<ReportActions>; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, | ||
| waitForCollectionCallback: true, | ||
| callback: (actions) => { | ||
|
|
@@ -1054,7 +1052,7 @@ | |
|
|
||
| let allReportMetadata: OnyxCollection<ReportMetadata>; | ||
| const allReportMetadataKeyValue: Record<string, ReportMetadata> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT_METADATA, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -2739,38 +2737,18 @@ | |
| * The Avatar sources can be URLs or Icon components according to the chat type. | ||
| */ | ||
| function getIconsForParticipants(participants: number[], personalDetails: OnyxInputOrEntry<PersonalDetailsList>): Icon[] { | ||
| const participantDetails: ParticipantDetails[] = []; | ||
| const participantsList = participants || []; | ||
| const avatars: Icon[] = []; | ||
|
|
||
| for (const accountID of participantsList) { | ||
| const avatarSource = personalDetails?.[accountID]?.avatar ?? FallbackAvatar; | ||
| const displayNameLogin = personalDetails?.[accountID]?.displayName ? personalDetails?.[accountID]?.displayName : personalDetails?.[accountID]?.login; | ||
| participantDetails.push([accountID, displayNameLogin ?? '', avatarSource, personalDetails?.[accountID]?.fallbackIcon ?? '']); | ||
| } | ||
|
|
||
| const sortedParticipantDetails = participantDetails.sort((first, second) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Context: Removed the sorting from here as major refactor revolving this happened where we are sorting later for multiple icons anyway.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1206agra Could you please give more details to explain why we remove the sort function here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to sort because sorting is happening for icons case-by-case basis now in different place.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1206agra Sorry, where is the sorting happening? Could you please provide an example?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1206agra Since we removed the sorting logic from getIconsForParticipants, we now need to ensure that sorting is applied wherever this function is used. Could you please confirm that all such places have been covered?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DylanDylann I have discussed about this here https://expensify.slack.com/archives/C08CZDJFJ77/p1754547372604689. So you can proceed as usual here |
||
| // First sort by displayName/login | ||
| const displayNameLoginOrder = localeCompareLibs(first[1], second[1]); | ||
| if (displayNameLoginOrder !== 0) { | ||
| return displayNameLoginOrder; | ||
| } | ||
|
|
||
| // Then fallback on accountID as the final sorting criteria. | ||
| // This will ensure that the order of avatars with same login/displayName | ||
| // stay consistent across all users and devices | ||
| return first[0] - second[0]; | ||
| }); | ||
|
|
||
| // Now that things are sorted, gather only the avatars (second element in the array) and return those | ||
| const avatars: Icon[] = []; | ||
|
|
||
| for (const sortedParticipantDetail of sortedParticipantDetails) { | ||
| const userIcon = { | ||
| id: sortedParticipantDetail[0], | ||
| source: sortedParticipantDetail[2], | ||
| id: accountID, | ||
| source: avatarSource, | ||
| type: CONST.ICON_TYPE_AVATAR, | ||
| name: sortedParticipantDetail[1], | ||
| fallbackIcon: sortedParticipantDetail[3], | ||
| name: displayNameLogin ?? '', | ||
| fallbackIcon: personalDetails?.[accountID]?.fallbackIcon ?? '', | ||
| }; | ||
| avatars.push(userIcon); | ||
| } | ||
|
|
@@ -3373,6 +3351,24 @@ | |
| return getIconsForParticipants(participantAccountIDs, personalDetails); | ||
| } | ||
|
|
||
| const getIconDisplayName = (icon: Icon, personalDetails: OnyxInputOrEntry<PersonalDetailsList>) => | ||
| icon.id ? (personalDetails?.[icon.id]?.displayName ?? personalDetails?.[icon.id]?.login ?? '') : ''; | ||
|
|
||
| function sortIconsByName(icons: Icon[], personalDetails: OnyxInputOrEntry<PersonalDetailsList>, localeCompare: LocaleContextProps['localeCompare']) { | ||
| return icons.sort((first, second) => { | ||
| // First sort by displayName/login | ||
| const displayNameLoginOrder = localeCompare(getIconDisplayName(first, personalDetails), getIconDisplayName(second, personalDetails)); | ||
| if (displayNameLoginOrder !== 0) { | ||
| return displayNameLoginOrder; | ||
| } | ||
|
|
||
| // Then fallback on accountID as the final sorting criteria. | ||
| // This will ensure that the order of avatars with same login/displayName | ||
| // stay consistent across all users and devices | ||
| return Number(first?.id) - Number(second?.id); | ||
| }); | ||
| } | ||
|
|
||
| function getDisplayNamesWithTooltips( | ||
| personalDetailsList: PersonalDetails[] | PersonalDetailsList | OptionData[], | ||
| shouldUseShortForm: boolean, | ||
|
|
@@ -11605,6 +11601,7 @@ | |
| getUpgradeWorkspaceMessage, | ||
| getDowngradeWorkspaceMessage, | ||
| getIcons, | ||
| sortIconsByName, | ||
| getIconsForParticipants, | ||
| getIndicatedMissingPaymentMethod, | ||
| getLastVisibleMessage, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.