From b7ef24eb2893b24a268145ef6692e50f713def14 Mon Sep 17 00:00:00 2001 From: aimane-chnaif Date: Thu, 21 Mar 2024 21:15:39 +1000 Subject: [PATCH 1/4] fix crash on sidebarutils --- src/libs/SidebarUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index e043d4e7f1ad..c4e8070b55a2 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -77,14 +77,18 @@ function getOrderedReportIDs( // Filter out all the reports that shouldn't be displayed let reportsToDisplay = allReportsDictValues.filter((report) => { - const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`; + if (!report) { + return false; + } + + const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`; const parentReportActions = allReportActions?.[parentReportActionsKey]; const reportActions = ReportActionsUtils.getAllReportActions(report.reportID); - const parentReportAction = parentReportActions?.find((action) => action && report && action?.reportActionID === report?.parentReportActionID); + const parentReportAction = parentReportActions?.find((action) => action && report && action?.reportActionID === report.parentReportActionID); const doesReportHaveViolations = betas.includes(CONST.BETAS.VIOLATIONS) && !!parentReportAction && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); - const isHidden = report?.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; - const isFocused = report?.reportID === currentReportId; + const isHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; + const isFocused = report.reportID === currentReportId; const hasErrors = Object.keys(OptionsListUtils.getAllReportErrors(report, reportActions) ?? {}).length !== 0; const hasBrickError = hasErrors || doesReportHaveViolations ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; const shouldOverrideHidden = hasBrickError || isFocused || report.isPinned; From b32ce2f406494f909aa45efdd220483ac23f9663 Mon Sep 17 00:00:00 2001 From: aimane-chnaif Date: Thu, 21 Mar 2024 21:20:17 +1000 Subject: [PATCH 2/4] more optimization --- src/libs/SidebarUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index c4e8070b55a2..63b907a42e25 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -84,7 +84,7 @@ function getOrderedReportIDs( const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`; const parentReportActions = allReportActions?.[parentReportActionsKey]; const reportActions = ReportActionsUtils.getAllReportActions(report.reportID); - const parentReportAction = parentReportActions?.find((action) => action && report && action?.reportActionID === report.parentReportActionID); + const parentReportAction = parentReportActions?.find((action) => action && action?.reportActionID === report.parentReportActionID); const doesReportHaveViolations = betas.includes(CONST.BETAS.VIOLATIONS) && !!parentReportAction && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); const isHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; From 0d412193df30a1af0cc1057694646303bcf8491c Mon Sep 17 00:00:00 2001 From: aimane-chnaif Date: Thu, 21 Mar 2024 21:34:24 +1000 Subject: [PATCH 3/4] optimize more --- src/libs/SidebarUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 63b907a42e25..4c869e82b10b 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -83,7 +83,8 @@ function getOrderedReportIDs( const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`; const parentReportActions = allReportActions?.[parentReportActionsKey]; - const reportActions = ReportActionsUtils.getAllReportActions(report.reportID); + const reportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`; + const reportActions = allReportActions?.[reportActionsKey]; const parentReportAction = parentReportActions?.find((action) => action && action?.reportActionID === report.parentReportActionID); const doesReportHaveViolations = betas.includes(CONST.BETAS.VIOLATIONS) && !!parentReportAction && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); From 81f4e1009e3e0d2c6173593eb327914ccce847fc Mon Sep 17 00:00:00 2001 From: aimane-chnaif Date: Thu, 21 Mar 2024 21:47:13 +1000 Subject: [PATCH 4/4] revert using allReportActions --- src/libs/SidebarUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 4c869e82b10b..63b907a42e25 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -83,8 +83,7 @@ function getOrderedReportIDs( const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`; const parentReportActions = allReportActions?.[parentReportActionsKey]; - const reportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`; - const reportActions = allReportActions?.[reportActionsKey]; + const reportActions = ReportActionsUtils.getAllReportActions(report.reportID); const parentReportAction = parentReportActions?.find((action) => action && action?.reportActionID === report.parentReportActionID); const doesReportHaveViolations = betas.includes(CONST.BETAS.VIOLATIONS) && !!parentReportAction && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction);