Skip to content

Commit

Permalink
Merge pull request #43814 from abzokhattab/fix-app-crash
Browse files Browse the repository at this point in the history
Fix app crash on loading null reportActions
  • Loading branch information
Hayata Suenaga authored Jun 17, 2024
2 parents df9689f + 7ed4689 commit 1e0831e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
34 changes: 18 additions & 16 deletions src/hooks/useReportIDs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,24 @@ const chatReportSelector = (report: OnyxEntry<OnyxTypes.Report>): ChatReportSele

const reportActionsSelector = (reportActions: OnyxEntry<OnyxTypes.ReportActions>): ReportActionsSelector =>
(reportActions &&
Object.values(reportActions).map((reportAction) => {
const {reportActionID, actionName, errors = [], originalMessage} = reportAction;
const decision = reportAction.message?.[0]?.moderationDecision?.decision;

return {
reportActionID,
actionName,
errors,
message: [
{
moderationDecision: {decision},
},
] as Message[],
originalMessage,
};
})) as ReportActionsSelector;
Object.values(reportActions)
.filter(Boolean)
.map((reportAction) => {
const {reportActionID, actionName, errors = [], originalMessage} = reportAction;
const decision = reportAction.message?.[0]?.moderationDecision?.decision;

return {
reportActionID,
actionName,
errors,
message: [
{
moderationDecision: {decision},
},
] as Message[],
originalMessage,
};
})) as ReportActionsSelector;

const policySelector = (policy: OnyxEntry<OnyxTypes.Policy>): PolicySelector =>
(policy && {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ function getSortedReportActionsForDisplay(reportActions: OnyxEntry<ReportActions
}

if (shouldIncludeInvisibleActions) {
filteredReportActions = Object.values(reportActions);
filteredReportActions = Object.values(reportActions).filter(Boolean);
} else {
filteredReportActions = Object.entries(reportActions)
.filter(([key, reportAction]) => shouldReportActionBeVisible(reportAction, key))
Expand Down
12 changes: 9 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6756,7 +6756,9 @@ function getIndicatedMissingPaymentMethod(userWallet: OnyxEntry<UserWallet>, rep
*/
function hasMissingPaymentMethod(userWallet: OnyxEntry<UserWallet>, iouReportID: string): boolean {
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`] ?? {};
return Object.values(reportActions).some((action) => getIndicatedMissingPaymentMethod(userWallet, iouReportID, action) !== undefined);
return Object.values(reportActions)
.filter(Boolean)
.some((action) => getIndicatedMissingPaymentMethod(userWallet, iouReportID, action) !== undefined);
}

/**
Expand All @@ -6782,7 +6784,9 @@ function getTripTransactions(tripRoomReportID: string | undefined): Transaction[
*/
function hasActionsWithErrors(reportID: string): boolean {
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {};
return Object.values(reportActions).some((action) => !isEmptyObject(action.errors));
return Object.values(reportActions)
.filter(Boolean)
.some((action) => !isEmptyObject(action.errors));
}

function isNonAdminOrOwnerOfPolicyExpenseChat(report: OnyxInputOrEntry<Report>, policy: OnyxInputOrEntry<Policy>): boolean {
Expand Down Expand Up @@ -6884,7 +6888,9 @@ function createDraftTransactionAndNavigateToParticipantSelector(transactionID: s
return;
}

const linkedTrackedExpenseReportAction = Object.values(reportActions).find((action) => (action.originalMessage as IOUMessage)?.IOUTransactionID === transactionID);
const linkedTrackedExpenseReportAction = Object.values(reportActions)
.filter(Boolean)
.find((action) => (action.originalMessage as IOUMessage)?.IOUTransactionID === transactionID);

const {created, amount, currency, merchant, mccGroup} = getTransactionDetails(transaction) ?? {};
const comment = getTransactionCommentObject(transaction);
Expand Down

0 comments on commit 1e0831e

Please sign in to comment.