From cd56779d2c0102bb4e46c45e63147337a474ab1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Tue, 20 Feb 2024 20:49:53 +0100 Subject: [PATCH] replace all localeCompare occurrences with custom one --- src/libs/GroupChatUtils.ts | 3 ++- src/libs/KeyboardShortcut/index.ts | 3 ++- src/libs/OptionsListUtils.ts | 5 +++-- src/libs/ReportUtils.ts | 5 +++-- src/pages/ReportParticipantsPage.tsx | 3 ++- src/pages/RoomMembersPage.tsx | 3 ++- src/pages/workspace/WorkspaceNewRoomPage.js | 3 ++- src/pages/workspace/WorkspacesListPage.tsx | 3 ++- 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/libs/GroupChatUtils.ts b/src/libs/GroupChatUtils.ts index 5d925ae1c684..58a82de3df53 100644 --- a/src/libs/GroupChatUtils.ts +++ b/src/libs/GroupChatUtils.ts @@ -1,5 +1,6 @@ import type {OnyxEntry} from 'react-native-onyx'; import type {Report} from '@src/types/onyx'; +import localeCompare from './LocaleCompare'; import * as ReportUtils from './ReportUtils'; /** @@ -11,7 +12,7 @@ function getGroupChatName(report: OnyxEntry): string | undefined { return participants .map((participant) => ReportUtils.getDisplayNameForParticipant(participant, isMultipleParticipantReport)) - .sort((first, second) => first?.localeCompare(second ?? '') ?? 0) + .sort((first, second) => localeCompare(first ?? '', second ?? '')) .filter(Boolean) .join(', '); } diff --git a/src/libs/KeyboardShortcut/index.ts b/src/libs/KeyboardShortcut/index.ts index 44ba54953c40..0571f5e271ab 100644 --- a/src/libs/KeyboardShortcut/index.ts +++ b/src/libs/KeyboardShortcut/index.ts @@ -1,6 +1,7 @@ import Str from 'expensify-common/lib/str'; import * as KeyCommand from 'react-native-key-command'; import getOperatingSystem from '@libs/getOperatingSystem'; +import localeCompare from '@libs/LocaleCompare'; import CONST from '@src/CONST'; import bindHandlerToKeydownEvent from './bindHandlerToKeydownEvent'; @@ -32,7 +33,7 @@ type Shortcut = { const documentedShortcuts: Record = {}; function getDocumentedShortcuts(): Shortcut[] { - return Object.values(documentedShortcuts).sort((a, b) => a.displayName.localeCompare(b.displayName)); + return Object.values(documentedShortcuts).sort((a, b) => localeCompare(a.displayName, b.displayName)); } const keyInputEnter = KeyCommand?.constants?.keyInputEnter?.toString() ?? 'keyInputEnter'; diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 80081061f340..bacdf9571f55 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -34,6 +34,7 @@ import times from '@src/utils/times'; import Timing from './actions/Timing'; import * as CollectionUtils from './CollectionUtils'; import * as ErrorUtils from './ErrorUtils'; +import localeCompare from './LocaleCompare'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import * as LoginUtils from './LoginUtils'; @@ -871,9 +872,9 @@ function sortTags(tags: Record | Tag[]) { let sortedTags; if (Array.isArray(tags)) { - sortedTags = tags.sort((a, b) => a.name.localeCompare(b.name)); + sortedTags = tags.sort((a, b) => localeCompare(a.name, b.name)); } else { - sortedTags = Object.values(tags).sort((a, b) => a.name.localeCompare(b.name)); + sortedTags = Object.values(tags).sort((a, b) => localeCompare(a.name, b.name)); } return sortedTags; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6abdd4348488..1249a75e9e58 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -52,6 +52,7 @@ import * as CollectionUtils from './CollectionUtils'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; import isReportMessageAttachment from './isReportMessageAttachment'; +import localeCompare from './LocaleCompare'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import linkingConfig from './Navigation/linkingConfig'; @@ -1442,7 +1443,7 @@ function getIconsForParticipants(participants: number[], personalDetails: OnyxCo const sortedParticipantDetails = participantDetails.sort((first, second) => { // First sort by displayName/login - const displayNameLoginOrder = first[1].localeCompare(second[1]); + const displayNameLoginOrder = localeCompare(first[1], second[1]); if (displayNameLoginOrder !== 0) { return displayNameLoginOrder; } @@ -1700,7 +1701,7 @@ function getDisplayNamesWithTooltips( }) .sort((first, second) => { // First sort by displayName/login - const displayNameLoginOrder = first.displayName.localeCompare(second.displayName); + const displayNameLoginOrder = localeCompare(first.displayName, second.displayName); if (displayNameLoginOrder !== 0) { return displayNameLoginOrder; } diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index b560ce672ae4..3f24e220498d 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -8,6 +8,7 @@ import OptionsList from '@components/OptionsList'; import ScreenWrapper from '@components/ScreenWrapper'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import localeCompare from '@libs/LocaleCompare'; import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; import type * as Localize from '@libs/Localize'; import Navigation from '@libs/Navigation/Navigation'; @@ -69,7 +70,7 @@ const getAllParticipants = ( reportID: report?.reportID ?? '', }; }) - .sort((a, b) => a.displayName.localeCompare(b.displayName.toLowerCase())); + .sort((a, b) => localeCompare(a.displayName, b.displayName)); function ReportParticipantsPage({report, personalDetails}: ReportParticipantsPageProps) { const {translate} = useLocalize(); diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index 7d0833379c8d..4e990b8bfdec 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -16,6 +16,7 @@ import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalD import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; +import localeCompare from '@libs/LocaleCompare'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import type {RoomMembersNavigatorParamList} from '@libs/Navigation/types'; @@ -200,7 +201,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { }); }); - result = result.sort((value1, value2) => value1.text.localeCompare(value2.text.toLowerCase())); + result = result.sort((value1, value2) => localeCompare(value1.text, value2.text)); return result; }; diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index 36f874e8919d..e56d9d9a76fc 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -23,6 +23,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import compose from '@libs/compose'; import * as ErrorUtils from '@libs/ErrorUtils'; +import localeCompare from '@libs/LocaleCompare'; import {translatableTextPropTypes} from '@libs/Localize'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; @@ -114,7 +115,7 @@ function WorkspaceNewRoomPage(props) { label: policy.name, value: policy.id, }), - ).sort((a, b) => a.label.toLowerCase().localeCompare(b.label.toLowerCase())), + ).sort((a, b) => localeCompare(a.label, b.label)), [props.policies], ); const [policyID, setPolicyID] = useState(() => { diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 88ea1bf1ec54..d1edf7f2f783 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -23,6 +23,7 @@ import useNetwork from '@hooks/useNetwork'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; +import localeCompare from '@libs/LocaleCompare'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -308,7 +309,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r type: policy.type, }), ) - .sort((a, b) => a.title.toLowerCase().localeCompare(b.title.toLowerCase())); + .sort((a, b) => localeCompare(a.title, b.title)); }, [reimbursementAccount?.errors, policies, isOffline, theme.textLight, allPolicyMembers, policyRooms]); if (isEmptyObject(workspaces)) {