Skip to content

Commit

Permalink
Merge pull request #52948 from wildan-m/wildan/fix/51296-pure-report-…
Browse files Browse the repository at this point in the history
…action-item

(1/2) Add support for all reportAction types in ChatListItem - create PureReportActionItem
  • Loading branch information
luacmartins authored Dec 13, 2024
2 parents d3eb3ca + a5323be commit 2c3c9ac
Show file tree
Hide file tree
Showing 6 changed files with 1,296 additions and 1,066 deletions.
6 changes: 4 additions & 2 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyTagLists, Report, ReportAction} from '@src/types/onyx';
import type {SearchReport} from '@src/types/onyx/SearchResults';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import * as Localize from './Localize';
Expand Down Expand Up @@ -138,12 +139,13 @@ function getForDistanceRequest(newMerchant: string, oldMerchant: string, newAmou
* ModifiedExpense::getNewDotComment in Web-Expensify should match this.
* If we change this function be sure to update the backend as well.
*/
function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry<ReportAction>): string {
function getForReportAction(reportOrID: string | SearchReport | undefined, reportAction: OnyxEntry<ReportAction>): string {
if (!ReportActionsUtils.isModifiedExpenseAction(reportAction)) {
return '';
}
const reportActionOriginalMessage = ReportActionsUtils.getOriginalMessage(reportAction);
const policyID = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.policyID ?? '-1';
const report = typeof reportOrID === 'string' ? allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] : reportOrID;
const policyID = report?.policyID ?? '-1';

const removalFragments: string[] = [];
const setFragments: string[] = [];
Expand Down
26 changes: 15 additions & 11 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,12 +1509,14 @@ function isArchivedRoom(report: OnyxInputOrEntry<Report> | SearchReport, reportN
/**
* Whether the report with the provided reportID is an archived room
*/
function isArchivedRoomWithID(reportID?: string) {
if (!reportID) {
function isArchivedRoomWithID(reportOrID?: string | SearchReport) {
if (!reportOrID) {
return false;
}

return isArchivedRoom(getReport(reportID), getReportNameValuePairs(reportID));
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const report = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
return isArchivedRoom(report);
}

/**
Expand Down Expand Up @@ -2599,7 +2601,7 @@ function getDeletedParentActionMessageForChatReport(reportAction: OnyxEntry<Repo
*/
function getReimbursementQueuedActionMessage(
reportAction: OnyxEntry<ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_QUEUED>>,
reportOrID: OnyxEntry<Report> | string,
reportOrID: OnyxEntry<Report> | string | SearchReport,
shouldUseShortDisplayName = true,
): string {
const report = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
Expand All @@ -2620,7 +2622,7 @@ function getReimbursementQueuedActionMessage(
*/
function getReimbursementDeQueuedActionMessage(
reportAction: OnyxEntry<ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_DEQUEUED>>,
reportOrID: OnyxEntry<Report> | string,
reportOrID: OnyxEntry<Report> | string | SearchReport,
isLHNPreview = false,
): string {
const report = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
Expand Down Expand Up @@ -4820,7 +4822,7 @@ function getIOUApprovedMessage(reportAction: ReportAction<typeof CONST.REPORT.AC
* We pass the reportID as older FORWARDED actions do not have the amount & currency stored in the message
* so we retrieve the amount from the report instead
*/
function getReportAutomaticallyForwardedMessage(reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.FORWARDED>, reportOrID: OnyxInputOrEntry<Report> | string) {
function getReportAutomaticallyForwardedMessage(reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.FORWARDED>, reportOrID: OnyxInputOrEntry<Report> | string | SearchReport) {
const expenseReport = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction) as OriginalMessageIOU;
let formattedAmount;
Expand All @@ -4839,7 +4841,7 @@ function getReportAutomaticallyForwardedMessage(reportAction: ReportAction<typeo
* We pass the reportID as older FORWARDED actions do not have the amount & currency stored in the message
* so we retrieve the amount from the report instead
*/
function getIOUForwardedMessage(reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.FORWARDED>, reportOrID: OnyxInputOrEntry<Report> | string) {
function getIOUForwardedMessage(reportAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.FORWARDED>, reportOrID: OnyxInputOrEntry<Report> | string | SearchReport) {
const expenseReport = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction) as OriginalMessageIOU;
let formattedAmount;
Expand Down Expand Up @@ -6780,17 +6782,18 @@ function getAllPolicyReports(policyID: string): Array<OnyxEntry<Report>> {
/**
* Returns true if Chronos is one of the chat participants (1:1)
*/
function chatIncludesChronos(report: OnyxInputOrEntry<Report>): boolean {
function chatIncludesChronos(report: OnyxInputOrEntry<Report> | SearchReport): boolean {
const participantAccountIDs = Object.keys(report?.participants ?? {}).map(Number);
return participantAccountIDs.includes(CONST.ACCOUNT_ID.CHRONOS);
}

function chatIncludesChronosWithID(reportID?: string): boolean {
if (!reportID) {
function chatIncludesChronosWithID(reportOrID?: string | SearchReport): boolean {
if (!reportOrID) {
return false;
}

return chatIncludesChronos(getReport(reportID));
const report = typeof reportOrID === 'string' ? getReport(reportOrID) : reportOrID;
return chatIncludesChronos(report);
}

/**
Expand Down Expand Up @@ -8854,4 +8857,5 @@ export type {
TransactionDetails,
PartialReportAction,
ParsingDetails,
MissingPaymentMethod,
};
1 change: 1 addition & 0 deletions src/libs/actions/ReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function clearAllRelatedReportActionErrors(reportID: string, reportAction: Repor
}
}

export type {IgnoreDirection};
export {
// eslint-disable-next-line import/prefer-default-export
clearAllRelatedReportActionErrors,
Expand Down
Loading

0 comments on commit 2c3c9ac

Please sign in to comment.