From 937b63889f574c03dd5b0991815465df67d9c2d7 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 6 Jun 2024 10:15:43 -0600 Subject: [PATCH 1/2] fix crash if report doesnt have transactions --- src/components/SelectionList/Search/ReportListItem.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index 10e25f3d871c..f35880e6077f 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -95,14 +95,18 @@ function ReportListItem({ return null; } - const participantFrom = reportItem.transactions[0].from; - const participantTo = reportItem.transactions[0].to; + const participantFrom = reportItem.transactions[0]?.from; + const participantTo = reportItem.transactions[0]?.to; // These values should come as part of the item via SearchUtils.getSections() but ReportListItem is not yet 100% handled // This will be simplified in future once sorting of ReportListItem is done const participantFromDisplayName = participantFrom?.name ?? participantFrom?.displayName ?? participantFrom?.login ?? ''; const participantToDisplayName = participantTo?.name ?? participantTo?.displayName ?? participantTo?.login ?? ''; + if (reportItem.transactions.length === 0) { + return; + } + if (reportItem.transactions.length === 1) { const transactionItem = reportItem.transactions[0]; From a45dab2025deb844e55d5187b4c9cb01bd97161c Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 6 Jun 2024 10:24:40 -0600 Subject: [PATCH 2/2] return early --- .../SelectionList/Search/ReportListItem.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index f35880e6077f..b463cabbe960 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -79,6 +79,10 @@ function ReportListItem({ const {isLargeScreenWidth} = useWindowDimensions(); const StyleUtils = useStyleUtils(); + if (reportItem.transactions.length === 0) { + return; + } + const listItemPressableStyle = [styles.selectionListPressableItemWrapper, styles.pv3, item.isSelected && styles.activeComponentBG, isFocused && styles.sidebarLinkActive]; const handleOnButtonPress = () => { @@ -95,18 +99,14 @@ function ReportListItem({ return null; } - const participantFrom = reportItem.transactions[0]?.from; - const participantTo = reportItem.transactions[0]?.to; + const participantFrom = reportItem.transactions[0].from; + const participantTo = reportItem.transactions[0].to; // These values should come as part of the item via SearchUtils.getSections() but ReportListItem is not yet 100% handled // This will be simplified in future once sorting of ReportListItem is done const participantFromDisplayName = participantFrom?.name ?? participantFrom?.displayName ?? participantFrom?.login ?? ''; const participantToDisplayName = participantTo?.name ?? participantTo?.displayName ?? participantTo?.login ?? ''; - if (reportItem.transactions.length === 0) { - return; - } - if (reportItem.transactions.length === 1) { const transactionItem = reportItem.transactions[0];