Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ import {
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
getAddExpenseDropdownOptions,
getDisplayNameForParticipant,
getMoneyReportPreviewName,
getMoneyRequestSpendBreakdown,
getNonHeldAndFullAmount,
getPolicyName,
getReportName,
getReportStatusColorStyle,
getReportStatusTranslation,
getTransactionsWithReceipts,
Expand Down Expand Up @@ -118,7 +118,6 @@ function MoneyRequestReportPreviewContent({
currentWidth,
reportPreviewStyles,
shouldDisplayContextMenu = true,
isInvoice,
shouldShowBorder = false,
onPress,
forwardedFSClass,
Expand Down Expand Up @@ -218,12 +217,6 @@ function MoneyRequestReportPreviewContent({

const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportAttributesSelector});

const currentReportName = iouReport?.reportID ? reportAttributes?.[iouReport.reportID]?.reportName : undefined;
const reportPreviewName = useMemo(() => {
return getMoneyReportPreviewName(action, iouReport, isInvoice, reportAttributes);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [action, iouReport, isInvoice, currentReportName]);

const hasReceipts = transactionsWithReceipts.length > 0;
const isScanning = hasReceipts && areAllRequestsBeingSmartScanned;
const existingB2BInvoiceReport = useParticipantsInvoiceReport(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport?.policyID);
Expand Down Expand Up @@ -737,7 +730,9 @@ function MoneyRequestReportPreviewContent({
style={[styles.headerText]}
testID="MoneyRequestReportPreview-reportName"
>
{reportPreviewName}
{/* This will be fixed as follow up https://github.com/Expensify/App/pull/75357 */}
{/* eslint-disable-next-line @typescript-eslint/no-deprecated */}
{getReportName(iouReport, undefined, undefined, undefined, undefined, reportAttributes)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
// eslint-disable-next-line @typescript-eslint/no-deprecated

Add this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

</Text>
</Animated.View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function MoneyRequestReportPreview({
onPaymentOptionsShow,
onPaymentOptionsHide,
shouldDisplayContextMenu = true,
isInvoice = false,
shouldShowBorder,
}: MoneyRequestReportPreviewProps) {
const styles = useThemeStyles();
Expand Down Expand Up @@ -168,7 +167,6 @@ function MoneyRequestReportPreview({
currentWidth={widths.currentWidth}
reportPreviewStyles={reportPreviewStyles}
shouldDisplayContextMenu={shouldDisplayContextMenu}
isInvoice={isInvoice}
onPress={openReportFromPreview}
shouldShowBorder={shouldShowBorder}
forwardedFSClass={CONST.FULLSTORY.CLASS.UNMASK}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ type MoneyRequestReportPreviewProps = {
/** Whether context menu should be shown on press */
shouldDisplayContextMenu?: boolean;

/** Whether the report is an invoice preview */
isInvoice?: boolean;

/** Whether to show a border to separate Reports Chat Item and Money Request Report Preview */
shouldShowBorder?: boolean;
};
Expand Down
12 changes: 0 additions & 12 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12646,17 +12646,6 @@ function hasReportBeenRetracted(report: OnyxEntry<Report>, reportActions?: OnyxE
return reportActionList.some((action) => isRetractedAction(action));
}

function getMoneyReportPreviewName(action: ReportAction, iouReport: OnyxEntry<Report>, isInvoice?: boolean, reportAttributes?: ReportAttributesDerivedValue['reports']) {
if (isInvoice && isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW)) {
const originalMessage = getOriginalMessage(action);
// eslint-disable-next-line @typescript-eslint/no-deprecated
return originalMessage && translateLocal('iou.invoiceReportName', originalMessage);
}
// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
// eslint-disable-next-line @typescript-eslint/no-deprecated
return getReportName(iouReport, undefined, undefined, undefined, undefined, reportAttributes) || action.childReportName;
}

function selectFilteredReportActions(
reportActions: Record<string, Record<string, OnyxInputOrEntry<ReportAction>> | undefined> | null | undefined,
): Record<string, ReportAction[]> | undefined {
Expand Down Expand Up @@ -13299,7 +13288,6 @@ export {
canRejectReportAction,
hasReportBeenReopened,
hasReportBeenRetracted,
getMoneyReportPreviewName,
getNextApproverAccountID,
isWorkspaceTaskReport,
isWorkspaceThread,
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,6 @@ function PureReportActionItem({
contextMenuAnchor={popoverAnchorRef.current}
isHovered={hovered}
isWhisper={isWhisper}
isInvoice={action.childType === CONST.REPORT.CHAT_TYPE.INVOICE}
checkIfContextMenuActive={toggleContextMenuFromActiveReportAction}
onPaymentOptionsShow={() => setIsPaymentMethodPopoverActive(true)}
onPaymentOptionsHide={() => setIsPaymentMethodPopoverActive(false)}
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/MoneyRequestReportPreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jest.mock('@rnmapbox/maps', () => {

jest.mock('@src/hooks/useReportWithTransactionsAndViolations', () =>
jest.fn((): [OnyxEntry<Report>, Transaction[], OnyxCollection<TransactionViolation[]>] => {
return [mockChatReport, [mockTransaction, {...mockTransaction, transactionID: mockSecondTransactionID}], {violations: mockViolations}];
return [mockIOUReport, [mockTransaction, {...mockTransaction, transactionID: mockSecondTransactionID}], {violations: mockViolations}];
}),
);

Expand Down Expand Up @@ -155,11 +155,14 @@ describe('MoneyRequestReportPreview', () => {
await waitForBatchedUpdatesWithAct();
});
await waitForBatchedUpdatesWithAct();
const {reportName: moneyRequestReportPreviewName = ''} = mockChatReport;

// This will be fixed as follow up https://github.com/Expensify/App/pull/75357
// eslint-disable-next-line @typescript-eslint/no-deprecated
expect(screen.getByText(ReportUtils.getReportName(mockIOUReport, undefined, undefined, undefined, undefined, undefined))).toBeOnTheScreen();

for (const transaction of arrayOfTransactions) {
const {transactionDisplayAmount, transactionHeaderText} = getTransactionDisplayAmountAndHeaderText(transaction);

expect(screen.getByText(moneyRequestReportPreviewName)).toBeOnTheScreen();
expect(screen.getByText(transactionDisplayAmount)).toBeOnTheScreen();
expect(screen.getAllByText(transactionHeaderText)).toHaveLength(arrayOfTransactions.length);
expect(screen.getAllByText(transaction.merchant)).toHaveLength(arrayOfTransactions.length);
Expand Down
141 changes: 0 additions & 141 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import {
getIconsForParticipants,
getIndicatedMissingPaymentMethod,
getIOUReportActionDisplayMessage,
getMoneyReportPreviewName,
getMostRecentlyVisitedReport,
getOutstandingChildRequest,
getParentNavigationSubtitle,
Expand Down Expand Up @@ -6056,146 +6055,6 @@ describe('ReportUtils', () => {
});
});

describe('getMoneyReportPreviewName', () => {
beforeAll(async () => {
await Onyx.clear();
await Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: participantsPersonalDetails,
[ONYXKEYS.SESSION]: {email: currentUserEmail, accountID: currentUserAccountID},
});
});

afterAll(async () => {
await Onyx.clear();
});

it('should return the report name when the chat type is policy room', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_ROOM);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return the report name when the chat type is domain all', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.DOMAIN_ALL);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return the report name when the chat type is group', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.GROUP);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return policy name when the chat type is invoice', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.INVOICE);
const result = getMoneyReportPreviewName(action, report);
// Policies are empty, so the policy name is "Unavailable workspace"
expect(result).toBe('Unavailable workspace');
});

it('should return the report name when the chat type is policy admins', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_ADMINS);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return the report name when the chat type is policy announce', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_ANNOUNCE);
const result = getMoneyReportPreviewName(action, report);
expect(result).toBe(report.reportName);
});

it('should return the owner name expenses when the chat type is policy expense chat', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);
const result = getMoneyReportPreviewName(action, report);
// Report with ownerAccountID: 1 corresponds to "Ragnar Lothbrok"
expect(result).toBe("Ragnar Lothbrok's expenses");
});

it('should return the display name of the current user when the chat type is self dm', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM);
const result = getMoneyReportPreviewName(action, report);
// currentUserAccountID: 5 corresponds to "Lagertha Lothbrok"
expect(result).toBe('Lagertha Lothbrok (you)');
});

it('should return the participant name when the chat type is system', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SYSTEM),
participants: {
1: {notificationPreference: 'hidden'},
},
};
const result = getMoneyReportPreviewName(action, report);
// participant accountID: 1 corresponds to "Ragnar Lothbrok"
expect(result).toBe('Ragnar Lothbrok');
});

it('should return the participant names when the chat type is trip room', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
};
const report: Report = {
...createRandomReport(1, CONST.REPORT.CHAT_TYPE.TRIP_ROOM),
participants: {
1: {notificationPreference: 'hidden'},
2: {notificationPreference: 'always'},
},
};
const result = getMoneyReportPreviewName(action, report);
// participant accountID: 1, 2 corresponds to "Ragnar", "floki@vikings.net"
expect(result).toBe('Ragnar, floki@vikings.net');
});

it('should return the child report name when the report name is not present', () => {
const action: ReportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
childReportName: 'Child Report',
};
const result = getMoneyReportPreviewName(action, undefined);
expect(result).toBe('Child Report');
});
});

describe('canAddTransaction', () => {
it('should return true for a non-archived report', async () => {
// Given a non-archived expense report
Expand Down
Loading