Skip to content
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
2 changes: 2 additions & 0 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type {BlockingViewProps} from '@components/BlockingViews/BlockingView';
import BlockingView from '@components/BlockingViews/BlockingView';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';

Check warning on line 13 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used by a pattern. Direct imports from Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details

Check warning on line 13 in src/components/LHNOptionsList/LHNOptionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used. Direct imports from @components/Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details
import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider';
import TextBlock from '@components/TextBlock';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
Expand Down Expand Up @@ -286,6 +286,7 @@
isReportsSplitNavigatorLast={isReportsSplitNavigatorLast}
isScreenFocused={isScreenFocused}
localeCompare={localeCompare}
translate={translate}
testID={index}
isReportArchived={isReportArchived}
lastAction={lastAction}
Expand Down Expand Up @@ -317,6 +318,7 @@
isReportsSplitNavigatorLast,
isScreenFocused,
localeCompare,
translate,
],
);

Expand Down
3 changes: 3 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function OptionRowLHNData({
transactionViolations,
lastMessageTextFromReport,
localeCompare,
translate,
isReportArchived = false,
lastAction,
lastActionReport,
Expand Down Expand Up @@ -69,6 +70,7 @@ function OptionRowLHNData({
invoiceReceiverPolicy,
card,
lastAction,
translate,
localeCompare,
isReportArchived,
lastActionReport,
Expand Down Expand Up @@ -107,6 +109,7 @@ function OptionRowLHNData({
invoiceReceiverPolicy,
lastMessageTextFromReport,
card,
translate,
localeCompare,
isReportArchived,
movedFromReport,
Expand Down
5 changes: 4 additions & 1 deletion src/components/LHNOptionsList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {RefObject} from 'react';
import type {LayoutChangeEvent, StyleProp, TextStyle, View, ViewStyle} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';
import type CONST from '@src/CONST';
import type {OptionData} from '@src/libs/ReportUtils';
import type {Locale, OnboardingPurpose, PersonalDetailsList, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
Expand Down Expand Up @@ -128,6 +128,9 @@ type OptionRowLHNDataProps = {
/** Function to compare locale strings */
localeCompare: LocaleContextProps['localeCompare'];

/** Function to translate locale strings */
translate: LocalizedTranslate;

/** TestID of the row, indicating order */
testID: number;

Expand Down
1 change: 1 addition & 0 deletions src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) {
report,
policy,
participantPersonalDetailListExcludeCurrentUser,
translate,
localeCompare,
isReportArchived,
reportDetailsLink,
Expand Down
81 changes: 32 additions & 49 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Str} from 'expensify-common';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';
import type {PartialPolicyForSidebar, ReportsToDisplayInLHN} from '@hooks/useSidebarOrderedReports';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -14,8 +14,7 @@ import type PriorityMode from '@src/types/onyx/PriorityMode';
import type Report from '@src/types/onyx/Report';
import type ReportAction from '@src/types/onyx/ReportAction';
import {formatPhoneNumber as formatPhoneNumberPhoneUtils} from './LocalePhoneNumber';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {formatList, translateLocal} from './Localize';
import {formatList} from './Localize';
import {
getLastActorDisplayName,
getLastActorDisplayNameFromLastVisibleActions,
Expand Down Expand Up @@ -637,6 +636,7 @@ function getOptionData({
invoiceReceiverPolicy,
card,
lastAction,
translate,
localeCompare,
isReportArchived,
lastActionReport,
Expand All @@ -654,6 +654,7 @@ function getOptionData({
reportAttributes: OnyxEntry<ReportAttributes>;
card: Card | undefined;
lastAction: ReportAction | undefined;
translate: LocalizedTranslate;
localeCompare: LocaleContextProps['localeCompare'];
isReportArchived: boolean | undefined;
lastActionReport: OnyxEntry<Report> | undefined;
Expand Down Expand Up @@ -820,22 +821,17 @@ function getOptionData({
const targetAccountIDsLength = targetAccountIDs.length !== 0 ? targetAccountIDs.length : (report.lastMessageHtml?.match(/<mention-user[^>]*><\/mention-user>/g)?.length ?? 0);
const verb =
lastActionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM || lastActionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.INVITE_TO_ROOM
? // eslint-disable-next-line @typescript-eslint/no-deprecated
translateLocal('workspace.invite.invited')
: // eslint-disable-next-line @typescript-eslint/no-deprecated
translateLocal('workspace.invite.removed');
// eslint-disable-next-line @typescript-eslint/no-deprecated
const users = translateLocal(targetAccountIDsLength > 1 ? 'common.members' : 'common.member')?.toLocaleLowerCase();
? translate('workspace.invite.invited')
: translate('workspace.invite.removed');
const users = translate(targetAccountIDsLength > 1 ? 'common.members' : 'common.member')?.toLocaleLowerCase();
result.alternateText = formatReportLastMessageText(`${actorDisplayName ?? lastActorDisplayName}: ${verb} ${targetAccountIDsLength} ${users}`);
// eslint-disable-next-line @typescript-eslint/no-deprecated
const roomName = getReportName(lastActionReport) || lastActionOriginalMessage?.roomName;
if (roomName) {
const preposition =
lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.INVITE_TO_ROOM
? // eslint-disable-next-line @typescript-eslint/no-deprecated
` ${translateLocal('workspace.invite.to')}`
: // eslint-disable-next-line @typescript-eslint/no-deprecated
` ${translateLocal('workspace.invite.from')}`;
? ` ${translate('workspace.invite.to')}`
: ` ${translate('workspace.invite.from')}`;
result.alternateText += `${preposition} ${roomName}`;
}
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_NAME)) {
Expand All @@ -849,13 +845,11 @@ function getOptionData({
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_AUTO_REPORTING_FREQUENCY)) {
result.alternateText = getWorkspaceFrequencyUpdateMessage(lastAction);
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.CORPORATE_UPGRADE)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
result.alternateText = translateLocal('workspaceActions.upgradedWorkspace');
result.alternateText = translate('workspaceActions.upgradedWorkspace');
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.CORPORATE_FORCE_UPGRADE)) {
result.alternateText = Parser.htmlToText(getForcedCorporateUpgradeMessage());
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.TEAM_DOWNGRADE)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
result.alternateText = translateLocal('workspaceActions.downgradedWorkspace');
result.alternateText = translate('workspaceActions.downgradedWorkspace');
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.INTEGRATION_SYNC_FAILED)) {
result.alternateText = Parser.htmlToText(getIntegrationSyncFailedMessage(lastAction, report?.policyID));
} else if (
Expand Down Expand Up @@ -916,8 +910,7 @@ function getOptionData({
} else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.LEAVE_POLICY) {
result.alternateText = getPolicyChangeLogEmployeeLeftMessage(lastAction, true);
} else if (isCardIssuedAction(lastAction)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
result.alternateText = getCardIssuedMessage({reportAction: lastAction, expensifyCard: card, translate: translateLocal});
result.alternateText = getCardIssuedMessage({reportAction: lastAction, expensifyCard: card, translate});
} else if (lastAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && lastActorDisplayName && lastMessageTextFromReport) {
const displayName = (lastMessageTextFromReport.length > 0 && getLastActorDisplayNameFromLastVisibleActions(report, lastActorDetails)) || lastActorDisplayName;
result.alternateText = formatReportLastMessageText(`${displayName}: ${lastMessageText}`);
Expand Down Expand Up @@ -969,17 +962,18 @@ function getOptionData({

if (!result.alternateText) {
result.alternateText = formatReportLastMessageText(
// eslint-disable-next-line @typescript-eslint/no-deprecated
getWelcomeMessage(report, policy, participantPersonalDetailListExcludeCurrentUser, localeCompare, isReportArchived).messageText ?? translateLocal('report.noActivityYet'),
getWelcomeMessage(report, policy, participantPersonalDetailListExcludeCurrentUser, translate, localeCompare, isReportArchived).messageText ??
translate('report.noActivityYet'),
);
}
}
result.alternateText = prefix + result.alternateText;
} else {
if (!lastMessageText) {
lastMessageText = formatReportLastMessageText(
// eslint-disable-next-line @typescript-eslint/no-deprecated, @typescript-eslint/prefer-nullish-coalescing
getWelcomeMessage(report, policy, participantPersonalDetailListExcludeCurrentUser, localeCompare, isReportArchived).messageText || translateLocal('report.noActivityYet'),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
getWelcomeMessage(report, policy, participantPersonalDetailListExcludeCurrentUser, translate, localeCompare, isReportArchived).messageText ||
translate('report.noActivityYet'),
);
}
if (shouldShowLastActorDisplayName(report, lastActorDetails, lastAction) && !isReportArchived) {
Expand Down Expand Up @@ -1034,6 +1028,7 @@ function getWelcomeMessage(
report: OnyxEntry<Report>,
policy: OnyxEntry<Policy>,
participantPersonalDetailList: PersonalDetails[],
translate: LocalizedTranslate,
localeCompare: LocaleContextProps['localeCompare'],
isReportArchived = false,
reportDetailsLink = '',
Expand All @@ -1046,16 +1041,15 @@ function getWelcomeMessage(
}

if (isChatRoom(report)) {
return getRoomWelcomeMessage(report, isReportArchived, reportDetailsLink);
return getRoomWelcomeMessage(translate, report, isReportArchived, reportDetailsLink);
}

if (isPolicyExpenseChat(report)) {
if (policy?.description) {
welcomeMessage.messageHtml = policy.description;
welcomeMessage.messageText = Parser.htmlToText(welcomeMessage.messageHtml);
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageHtml = translateLocal(
welcomeMessage.messageHtml = translate(
'reportActionsView.beginningOfChatHistoryPolicyExpenseChat',
getPolicyName({report}),
getDisplayNameForParticipant({accountID: report?.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils}),
Expand All @@ -1066,14 +1060,12 @@ function getWelcomeMessage(
}

if (isSelfDM(report)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageText = translateLocal('reportActionsView.beginningOfChatHistorySelfDM');
welcomeMessage.messageText = translate('reportActionsView.beginningOfChatHistorySelfDM');
return welcomeMessage;
}

if (isSystemChatUtil(report)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageText = translateLocal('reportActionsView.beginningOfChatHistorySystemDM');
welcomeMessage.messageText = translate('reportActionsView.beginningOfChatHistorySystemDM');
return welcomeMessage;
}
const isMultipleParticipant = participantPersonalDetailList.length > 1;
Expand All @@ -1086,17 +1078,14 @@ function getWelcomeMessage(
const userTags = displayNamesWithTooltips.map(({displayName, accountID}) => `<user-details accountid="${accountID}">${displayName ?? ''}</user-details>`);
const usersHtml = formatList(userTags);

// eslint-disable-next-line @typescript-eslint/no-deprecated
let messageHtml = translateLocal('reportActionsView.beginningOfChatHistory', usersHtml);
let messageHtml = translate('reportActionsView.beginningOfChatHistory', usersHtml);

// Append additional text for plus button or Concierge
if (shouldShowUsePlusButtonText) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
messageHtml += translateLocal('reportActionsView.usePlusButton', {additionalText});
messageHtml += translate('reportActionsView.usePlusButton', {additionalText});
}
if (isConciergeChatReport(report)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
messageHtml += translateLocal('reportActionsView.askConcierge');
messageHtml += translate('reportActionsView.askConcierge');
}

welcomeMessage.messageHtml = messageHtml;
Expand All @@ -1107,7 +1096,7 @@ function getWelcomeMessage(
/**
* Get welcome message based on room type
*/
function getRoomWelcomeMessage(report: OnyxEntry<Report>, isReportArchived = false, reportDetailsLink = ''): WelcomeMessage {
function getRoomWelcomeMessage(translate: LocalizedTranslate, report: OnyxEntry<Report>, isReportArchived = false, reportDetailsLink = ''): WelcomeMessage {
const welcomeMessage: WelcomeMessage = {};
const workspaceName = getPolicyName({report});
// eslint-disable-next-line @typescript-eslint/no-deprecated
Expand All @@ -1120,17 +1109,13 @@ function getRoomWelcomeMessage(report: OnyxEntry<Report>, isReportArchived = fal
}

if (isReportArchived) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageHtml = translateLocal('reportActionsView.beginningOfArchivedRoom', reportName, reportDetailsLink);
welcomeMessage.messageHtml = translate('reportActionsView.beginningOfArchivedRoom', reportName, reportDetailsLink);
} else if (isDomainRoom(report)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageHtml = translateLocal('reportActionsView.beginningOfChatHistoryDomainRoom', report?.reportName ?? '');
welcomeMessage.messageHtml = translate('reportActionsView.beginningOfChatHistoryDomainRoom', report?.reportName ?? '');
} else if (isAdminRoom(report)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageHtml = translateLocal('reportActionsView.beginningOfChatHistoryAdminRoom', workspaceName);
welcomeMessage.messageHtml = translate('reportActionsView.beginningOfChatHistoryAdminRoom', workspaceName);
} else if (isAnnounceRoom(report)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageHtml = translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoom', workspaceName);
welcomeMessage.messageHtml = translate('reportActionsView.beginningOfChatHistoryAnnounceRoom', workspaceName);
} else if (isInvoiceRoom(report)) {
const payer =
report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL
Expand All @@ -1139,12 +1124,10 @@ function getRoomWelcomeMessage(report: OnyxEntry<Report>, isReportArchived = fal
// eslint-disable-next-line @typescript-eslint/no-deprecated
getPolicy(report?.invoiceReceiver?.policyID)?.name;
const receiver = getPolicyName({report});
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageHtml = translateLocal('reportActionsView.beginningOfChatHistoryInvoiceRoom', payer ?? '', receiver);
welcomeMessage.messageHtml = translate('reportActionsView.beginningOfChatHistoryInvoiceRoom', payer ?? '', receiver);
} else {
// Message for user created rooms or other room types.
// eslint-disable-next-line @typescript-eslint/no-deprecated
welcomeMessage.messageHtml = translateLocal('reportActionsView.beginningOfChatHistoryUserRoom', reportName, reportDetailsLink);
welcomeMessage.messageHtml = translate('reportActionsView.beginningOfChatHistoryUserRoom', reportName, reportDetailsLink);
}
welcomeMessage.messageText = Parser.htmlToText(welcomeMessage.messageHtml);

Expand Down
3 changes: 2 additions & 1 deletion src/pages/Debug/Report/DebugReportActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ function DebugReportActions({reportID}: DebugReportActionsProps) {

if (isCreatedAction(reportAction)) {
return formatReportLastMessageText(
SidebarUtils.getWelcomeMessage(report, policy, participantPersonalDetailList, localeCompare, isReportArchived).messageText ?? translate('report.noActivityYet'),
SidebarUtils.getWelcomeMessage(report, policy, participantPersonalDetailList, translate, localeCompare, isReportArchived).messageText ??
translate('report.noActivityYet'),
);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/perf-test/SidebarUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import createPersonalDetails from '../utils/collections/personalDetails';
import createRandomPolicy from '../utils/collections/policies';
import createRandomReportAction, {getRandomDate} from '../utils/collections/reportActions';
import {createRandomReport} from '../utils/collections/reports';
import {localeCompare} from '../utils/TestHelper';
import {localeCompare, translateLocal} from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

const REPORTS_COUNT = 15000;
Expand Down Expand Up @@ -86,6 +86,7 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
card: undefined,
lastAction: undefined,
translate: translateLocal,
localeCompare,
lastActionReport: undefined,
isReportArchived: undefined,
Expand Down
Loading
Loading