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
7 changes: 2 additions & 5 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
}

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 92 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -101,7 +101,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 104 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -110,13 +110,13 @@
});

let deprecatedIsNetworkOffline = false;
Onyx.connect({

Check warning on line 113 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NETWORK,
callback: (val) => (deprecatedIsNetworkOffline = val?.isOffline ?? false),
});

let deprecatedCurrentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 119 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, value is undefined
Expand Down Expand Up @@ -2062,6 +2062,7 @@
CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_QUICK_BOOKS,
CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_REQUESTED,
CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_SETUP,
CONST.REPORT.ACTIONS.TYPE.REIMBURSED,
Comment thread
shubham1206agra marked this conversation as resolved.
].some((oldDotActionName) => oldDotActionName === action?.actionName);
}

Expand Down Expand Up @@ -2092,6 +2093,7 @@
CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_QUICK_BOOKS,
CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_REQUESTED,
CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_SETUP,
CONST.REPORT.ACTIONS.TYPE.REIMBURSED,
].some((oldDotActionName) => oldDotActionName === action.actionName);
}

Expand Down Expand Up @@ -2360,11 +2362,6 @@
return [{text: message, html: `<muted-text>${message}</muted-text>`, type: 'COMMENT'}];
}

if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REIMBURSED)) {
const message = getReportActionMessageText(action);
return [{text: message, html: `<muted-text>${message}</muted-text>`, type: 'COMMENT'}];
}

if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.RETRACTED)) {
const message = translate('iou.retracted');
return [{text: message, html: `<muted-text>${message}</muted-text>`, type: 'COMMENT'}];
Expand Down
77 changes: 59 additions & 18 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
getDismissedViolationMessageText,
getDynamicExternalWorkflowApproveFailedActionMessage,
getDynamicExternalWorkflowSubmitFailedActionMessage,
getExportIntegrationLastMessageText,
getForeignCurrencyDefaultTaxUpdateMessage,
getForwardsToUpdateMessage,
getIntegrationSyncFailedMessage,
Expand Down Expand Up @@ -105,6 +106,8 @@ import {
isMovedAction,
isOldDotReportAction,
isOriginalReportDeleted,
isReimbursementDeQueuedOrCanceledAction,
isReimbursementQueuedAction,
isRejectedAction,
isRenamedAction,
isReportActionAttachment,
Expand All @@ -122,6 +125,8 @@ import {
getParentReport,
getPolicyChangeMessage,
getPolicyName,
getReimbursementDeQueuedOrCanceledActionMessage,
getReimbursementQueuedActionMessage,
getReportMetadata,
getReportOrDraftReport,
getTransactionReportName,
Expand Down Expand Up @@ -411,10 +416,12 @@ function getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}: {rep

function computeReportNameBasedOnReportAction(
translate: LocalizedTranslate,
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
parentReportAction: ReportAction | undefined,
report: Report | undefined,
reportPolicy: Policy | undefined,
parentReport: Report | undefined,
personalDetailsList: OnyxEntry<PersonalDetailsList>,
// TODO: Make this required when https://github.com/Expensify/App/issues/66411 is done
conciergeReportID?: string,
): string | undefined {
Expand Down Expand Up @@ -443,9 +450,35 @@ function computeReportNameBasedOnReportAction(
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {
return translate('iou.heldExpense');
}
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION) {
return getExportIntegrationLastMessageText(translate, parentReportAction);
}
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.UNHOLD) {
return translate('iou.unheldExpense');
}
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTEDTRANSACTION_THREAD) {
return translate('iou.reject.reportActions.rejectedExpense');
}
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED_TRANSACTION_MARKASRESOLVED) {
return translate('iou.reject.reportActions.markedAsResolved');
}
if (isReimbursementQueuedAction(parentReportAction)) {
return getReimbursementQueuedActionMessage({
reportAction: parentReportAction,
report: parentReport,
translate,
formatPhoneNumber,
shouldUseShortDisplayName: false,
personalDetails: personalDetailsList,
});
}
if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.RECEIPT_SCAN_FAILED) {
return translate('iou.receiptScanningFailed');
}

if (isReimbursementDeQueuedOrCanceledAction(parentReportAction)) {
return getReimbursementDeQueuedOrCanceledActionMessage(translate, parentReportAction, parentReport);
}
if (isRejectedAction(parentReportAction)) {
return translate('iou.rejectedThisReport');
}
Expand Down Expand Up @@ -699,6 +732,21 @@ function computeReportNameBasedOnReportAction(
return Parser.htmlToText(getSettlementAccountLockedMessage(translate, parentReportAction));
}

if (isOldDotReportAction(parentReportAction)) {
return getMessageOfOldDotReportAction(translate, parentReportAction);
}

if (isRenamedAction(parentReportAction)) {
return getRenamedAction(translate, parentReportAction, isExpenseReport(parentReport));
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.RESOLVED_DUPLICATES)) {
return translate('violations.resolvedDuplicates');
}

if (isCardIssuedAction(parentReportAction)) {
return getCardIssuedMessage({reportAction: parentReportAction, translate});
}
if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_CARD_FEED)) {
return getAddedCardFeedMessage(translate, parentReportAction);
}
Expand Down Expand Up @@ -759,23 +807,10 @@ function computeChatThreadReportName(
return formatReportLastMessageText(formattedName);
}

if (!isEmptyObject(parentReportAction) && isOldDotReportAction(parentReportAction)) {
return getMessageOfOldDotReportAction(translate, parentReportAction);
}

if (isRenamedAction(parentReportAction)) {
const parent = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
return getRenamedAction(translate, parentReportAction, isExpenseReport(parent));
}

if (parentReportActionMessage?.isDeletedParentAction) {
return translate('parentReportAction.deletedMessage');
}

if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.RESOLVED_DUPLICATES) {
return translate('violations.resolvedDuplicates');
}

const isAttachment = isReportActionAttachment(!isEmptyObject(parentReportAction) ? parentReportAction : undefined);
const reportActionMessage = getReportActionText(parentReportAction).replaceAll(/(\n+|\r\n|\n|\r)/gm, ' ');
if (isAttachment && reportActionMessage) {
Expand Down Expand Up @@ -814,9 +849,6 @@ function computeChatThreadReportName(
if (isTripRoom(report) && report?.reportName !== CONST.REPORT.DEFAULT_REPORT_NAME) {
return report?.reportName ?? '';
}
if (isCardIssuedAction(parentReportAction)) {
return getCardIssuedMessage({reportAction: parentReportAction, translate});
}
return reportActionMessage;
}

Expand Down Expand Up @@ -845,8 +877,17 @@ function computeReportName({
const parentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
const parentReportAction = isThread(report) ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report.parentReportActionID] : undefined;

// eslint-disable-next-line @typescript-eslint/no-deprecated
const parentReportActionBasedName = computeReportNameBasedOnReportAction(translateLocal, parentReportAction, report, reportPolicy, parentReport, conciergeReportID);
const parentReportActionBasedName = computeReportNameBasedOnReportAction(
// eslint-disable-next-line @typescript-eslint/no-deprecated
Comment thread
shubham1206agra marked this conversation as resolved.
translateLocal,
formatPhoneNumberPhoneUtils,
parentReportAction,
report,
reportPolicy,
parentReport,
personalDetailsList,
conciergeReportID,
);

if (parentReportActionBasedName) {
return parentReportActionBasedName;
Expand Down
123 changes: 12 additions & 111 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,37 +182,30 @@
formatLastMessageText,
getActionableJoinRequestPendingReportAction,
getAllReportActions,
getCardIssuedMessage,
getCreatedReportForUnapprovedTransactionsMessage,
getExportIntegrationLastMessageText,
getIOUActionForTransactionID,
getIOUReportIDFromReportActionPreview,
getLastVisibleAction,
getLastVisibleAction as getLastVisibleActionReportActionsUtils,
getLastVisibleMessage as getLastVisibleMessageActionUtils,
getLastVisibleMessage as getLastVisibleMessageReportActionsUtils,
getMessageOfOldDotReportAction,
getMostRecentActiveDEWApproveFailedAction,
getMostRecentActiveDEWSubmitFailedAction,
getNumberOfMoneyRequests,
getOneTransactionThreadReportAction,
getOneTransactionThreadReportID,
getOriginalMessage,
getRenamedAction,
getReportAction,
getReportActionActorAccountID,
getReportActionHtml,
getReportActionMessage as getReportActionMessageReportUtils,
getReportActionMessageText,
getReportActionText,
getSortedReportActions,
isActionableCardFraudAlert,
isActionableJoinRequestPending,
isActionableTrackExpense,
isActionOfType,
isApprovedAction,
isApprovedOrSubmittedReportAction,
isCardIssuedAction,
isCreatedTaskReportAction,
isCurrentActionUnread,
isDeletedAction,
Expand All @@ -224,12 +217,9 @@
isModifiedExpenseAction,
isMoneyRequestAction,
isMovedAction,
isOldDotReportAction,
isPendingRemove,
isPolicyChangeLogAction,
isReimbursementDeQueuedOrCanceledAction,
isReimbursementQueuedAction,
isRenamedAction,
isReopenedAction,
isReportActionAttachment,
isReportActionVisible,
Expand Down Expand Up @@ -1055,7 +1045,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1048 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1063,7 +1053,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1056 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1081,7 +1071,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1074 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1093,7 +1083,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1086 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1101,7 +1091,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1094 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1111,7 +1101,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1104 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand Down Expand Up @@ -5784,75 +5774,6 @@
return textMessage;
}

/**
* Get the report action message for a report action.
*/
function getReportActionMessage({
reportAction,
translate,
formatPhoneNumber,
reportID,
childReportID,
reports,
personalDetails,
conciergeReportID,
}: {
reportAction: OnyxEntry<ReportAction>;
translate: LocalizedTranslate;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
reportID?: string;
childReportID?: string;
reports?: Report[];
personalDetails?: Partial<PersonalDetailsList>;
conciergeReportID: string | undefined;
}) {
if (isEmptyObject(reportAction)) {
return '';
}
if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {
return translate('iou.heldExpense');
}

if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION) {
return getExportIntegrationLastMessageText(translate, reportAction);
}

if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.UNHOLD) {
return translate('iou.unheldExpense');
}

if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTEDTRANSACTION_THREAD) {
return translate('iou.reject.reportActions.rejectedExpense');
}

if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED_TRANSACTION_MARKASRESOLVED) {
return translate('iou.reject.reportActions.markedAsResolved');
}

if (isApprovedOrSubmittedReportAction(reportAction) || isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REIMBURSED)) {
return getReportActionMessageText(reportAction);
}
if (isReimbursementQueuedAction(reportAction)) {
return getReimbursementQueuedActionMessage({
reportAction,
report: getReportOrDraftReport(reportID, reports),
translate,
formatPhoneNumber,
shouldUseShortDisplayName: false,
personalDetails,
});
}
if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.RECEIPT_SCAN_FAILED) {
return translate('iou.receiptScanningFailed');
}

if (isReimbursementDeQueuedOrCanceledAction(reportAction)) {
return getReimbursementDeQueuedOrCanceledActionMessage(translate, reportAction, getReportOrDraftReport(reportID, reports));
}

return parseReportActionHtmlToText(reportAction, reportID, conciergeReportID, childReportID);
}

/**
* Get the title for a report.
* @deprecated Moved to src/libs/ReportNameUtils.ts.
Expand Down Expand Up @@ -5882,8 +5803,17 @@

const reportPolicy = policy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];

// eslint-disable-next-line @typescript-eslint/no-deprecated
const parentReportActionBasedName = computeReportNameBasedOnReportAction(translateLocal, parentReportAction, report, reportPolicy, parentReport, conciergeReportID);
const parentReportActionBasedName = computeReportNameBasedOnReportAction(
// eslint-disable-next-line @typescript-eslint/no-deprecated
Comment thread
shubham1206agra marked this conversation as resolved.
translateLocal,
formatPhoneNumberPhoneUtils,
parentReportAction,
report,
reportPolicy,
parentReport,
personalDetails as PersonalDetailsList,
conciergeReportID,
);

if (parentReportActionBasedName) {
return parentReportActionBasedName;
Expand Down Expand Up @@ -5914,38 +5844,13 @@
return formatReportLastMessageText(formattedName);
}

if (!isEmptyObject(parentReportAction) && isOldDotReportAction(parentReportAction)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return getMessageOfOldDotReportAction(translateLocal, parentReportAction);
}

if (isRenamedAction(parentReportAction)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return getRenamedAction(translateLocal, parentReportAction, isExpenseReport(getReport(report.parentReportID, allReports)));
}

if (parentReportActionMessage?.isDeletedParentAction) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('parentReportAction.deletedMessage');
}

if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.RESOLVED_DUPLICATES) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('violations.resolvedDuplicates');
}

const isAttachment = isReportActionAttachment(!isEmptyObject(parentReportAction) ? parentReportAction : undefined);
const reportActionMessage = getReportActionMessage({
reportAction: parentReportAction,
// eslint-disable-next-line @typescript-eslint/no-deprecated
translate: translateLocal,
formatPhoneNumber: formatPhoneNumberPhoneUtils,
reportID: report?.parentReportID,
childReportID: report?.reportID,
reports,
personalDetails,
conciergeReportID,
}).replaceAll(/(\n+|\r\n|\n|\r)/gm, ' ');
const reportActionMessage = parseReportActionHtmlToText(parentReportAction, report?.parentReportID, conciergeReportID, report?.reportID).replaceAll(/(\n+|\r\n|\n|\r)/gm, ' ');
if (isAttachment && reportActionMessage) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return `[${translateLocal('common.attachment')}]`;
Expand Down Expand Up @@ -5986,10 +5891,6 @@
if (isTripRoom(report) && report?.reportName !== CONST.REPORT.DEFAULT_REPORT_NAME) {
return report?.reportName ?? '';
}
if (isCardIssuedAction(parentReportAction)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return getCardIssuedMessage({reportAction: parentReportAction, translate: translateLocal});
}
return reportActionMessage;
}

Expand Down
1 change: 1 addition & 0 deletions tests/utils/collections/reportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const deprecatedReportActions: ReportActionName[] = [
CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_REQUESTED,
CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_SETUP_REQUESTED,
CONST.REPORT.ACTIONS.TYPE.DONATION,
CONST.REPORT.ACTIONS.TYPE.REIMBURSED,
] as const;

export default function createRandomReportAction(index: number): ReportAction {
Expand Down
Loading