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

[Audit][Implementation] Replace localeCompare with static Collator implementation #36941

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libs/GroupChatUtils.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -11,7 +12,7 @@ function getGroupChatName(report: OnyxEntry<Report>): 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(', ');
}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/KeyboardShortcut/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -32,7 +33,7 @@ type Shortcut = {
const documentedShortcuts: Record<string, Shortcut> = {};

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';
Expand Down
5 changes: 3 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -871,9 +872,9 @@ function sortTags(tags: Record<string, Tag> | 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;
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1443,7 +1444,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;
}
Expand Down Expand Up @@ -1701,7 +1702,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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/ReportParticipantsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/pages/RoomMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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';
Expand Down Expand Up @@ -201,7 +202,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;
};
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as ErrorUtils from '@libs/ErrorUtils';
import localeCompare from '@libs/LocaleCompare';
import Navigation from '@libs/Navigation/Navigation';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -77,7 +78,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli
label: policy.name,
value: policy.id,
}))
.sort((a, b) => a.label.toLowerCase().localeCompare(b.label.toLowerCase())) ?? [],
.sort((a, b) => localeCompare(a.label, b.label)) ?? [],
[policies],
);
const [policyID, setPolicyID] = useState<string>(() => {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)) {
Expand Down
Loading