From ca83e0df73647350e4564187086372bb7e634593 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 30 Nov 2023 19:41:19 +0100 Subject: [PATCH 1/3] fix: fix type and remove parameter for canAccessReport --- src/libs/ReportActionsUtils.ts | 4 ++-- src/libs/ReportUtils.ts | 16 ++++------------ src/libs/SidebarUtils.ts | 6 ++---- src/pages/home/report/withReportOrNotFound.tsx | 2 +- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index bd475a57954e6..e4bbd2b02f18e 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -122,11 +122,11 @@ function isThreadParentMessage(reportAction: OnyxEntry, reportID: * * @deprecated Use Onyx.connect() or withOnyx() instead */ -function getParentReportAction(report: OnyxEntry, allReportActionsParam?: OnyxCollection): ReportAction | Record { +function getParentReportAction(report: OnyxEntry): ReportAction | Record { if (!report?.parentReportID || !report.parentReportActionID) { return {}; } - return (allReportActionsParam ?? allReportActions)?.[report.parentReportID]?.[report.parentReportActionID] ?? {}; + return allReportActions?.[report.parentReportID]?.[report.parentReportActionID] ?? {}; } /** diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 50a39f837fae3..f347ed5cec02f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3360,8 +3360,8 @@ function canSeeDefaultRoom(report: OnyxEntry, policies: OnyxCollection

, policies: OnyxCollection, betas: OnyxEntry, allReportActions?: OnyxCollection): boolean { - if (isThread(report) && ReportActionsUtils.isPendingRemove(ReportActionsUtils.getParentReportAction(report, allReportActions))) { +function canAccessReport(report: OnyxEntry, policies: OnyxCollection, betas: OnyxEntry): boolean { + if (isThread(report) && ReportActionsUtils.isPendingRemove(ReportActionsUtils.getParentReportAction(report))) { return false; } @@ -3390,15 +3390,7 @@ function shouldHideReport(report: OnyxEntry, currentReportId: string): b * This logic is very specific and the order of the logic is very important. It should fail quickly in most cases and also * filter out the majority of reports before filtering out very specific minority of reports. */ -function shouldReportBeInOptionList( - report: OnyxEntry, - currentReportId: string, - isInGSDMode: boolean, - betas: Beta[], - policies: OnyxCollection, - allReportActions?: OnyxCollection, - excludeEmptyChats = false, -) { +function shouldReportBeInOptionList(report: OnyxEntry, currentReportId: string, isInGSDMode: boolean, betas: Beta[], policies: OnyxCollection, excludeEmptyChats = false) { const isInDefaultMode = !isInGSDMode; // Exclude reports that have no data because there wouldn't be anything to show in the option item. // This can happen if data is currently loading from the server or a report is in various stages of being created. @@ -3419,7 +3411,7 @@ function shouldReportBeInOptionList( ) { return false; } - if (!canAccessReport(report, policies, betas, allReportActions)) { + if (!canAccessReport(report, policies, betas)) { return false; } diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index ff94861599470..c7024589e1a43 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -117,7 +117,7 @@ function getOrderedReportIDs( betas: Beta[], policies: Record, priorityMode: ValueOf, - allReportActions: OnyxCollection, + allReportActions: OnyxCollection, ): string[] { // Generate a unique cache key based on the function arguments const cachedReportsKey = JSON.stringify( @@ -149,9 +149,7 @@ function getOrderedReportIDs( const isInDefaultMode = !isInGSDMode; const allReportsDictValues = Object.values(allReports); // Filter out all the reports that shouldn't be displayed - const reportsToDisplay = allReportsDictValues.filter((report) => - ReportUtils.shouldReportBeInOptionList(report, currentReportId ?? '', isInGSDMode, betas, policies, allReportActions, true), - ); + const reportsToDisplay = allReportsDictValues.filter((report) => ReportUtils.shouldReportBeInOptionList(report, currentReportId ?? '', isInGSDMode, betas, policies, true)); if (reportsToDisplay.length === 0) { // Display Concierge chat report when there is no report to be displayed diff --git a/src/pages/home/report/withReportOrNotFound.tsx b/src/pages/home/report/withReportOrNotFound.tsx index 93d42ef6fd2b6..cf2c0d5aca4b7 100644 --- a/src/pages/home/report/withReportOrNotFound.tsx +++ b/src/pages/home/report/withReportOrNotFound.tsx @@ -39,7 +39,7 @@ export default function ( const shouldShowFullScreenLoadingIndicator = props.isLoadingReportData !== false && (!Object.entries(props.report ?? {}).length || !props.report?.reportID); const shouldShowNotFoundPage = - !Object.entries(props.report ?? {}).length || !props.report?.reportID || !ReportUtils.canAccessReport(props.report, props.policies, props.betas, {}); + !Object.entries(props.report ?? {}).length || !props.report?.reportID || !ReportUtils.canAccessReport(props.report, props.policies, props.betas); // If the content was shown but it's not anymore that means the report was deleted and we are probably navigating out of this screen. // Return null for this case to avoid rendering FullScreenLoadingIndicator or NotFoundPage when animating transition. From f64ef0fe4aa56846efc499bcc32ddeca1b73f3c9 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 30 Nov 2023 20:16:50 +0100 Subject: [PATCH 2/3] fix: type error in perf tests --- tests/perf-test/SidebarUtils.perf-test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 7f9957232cfbb..b81d6c433023d 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -1,4 +1,4 @@ -import Onyx, {OnyxCollection} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; import {measureFunction} from 'reassure'; import SidebarUtils from '@libs/SidebarUtils'; import CONST from '@src/CONST'; @@ -6,7 +6,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import {PersonalDetails} from '@src/types/onyx'; import Policy from '@src/types/onyx/Policy'; import Report from '@src/types/onyx/Report'; -import ReportAction, {ReportActions} from '@src/types/onyx/ReportAction'; +import ReportAction from '@src/types/onyx/ReportAction'; import createCollection from '../utils/collections/createCollection'; import createPersonalDetails from '../utils/collections/personalDetails'; import createRandomPolicy from '../utils/collections/policies'; @@ -86,7 +86,7 @@ test('getOrderedReportIDs on 5k reports', async () => { }, ], ]), - ) as unknown as OnyxCollection; + ) as unknown as Record; Onyx.multiSet({ ...mockedResponseMap, From 441935abcc01bc8a2d21d3283ea2789bf1417b7c Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Mon, 4 Dec 2023 09:44:40 +0100 Subject: [PATCH 3/3] fix: type --- tests/perf-test/SidebarUtils.perf-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index b81d6c433023d..78f385cde90b4 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -1,4 +1,4 @@ -import Onyx from 'react-native-onyx'; +import Onyx, {OnyxCollection} from 'react-native-onyx'; import {measureFunction} from 'reassure'; import SidebarUtils from '@libs/SidebarUtils'; import CONST from '@src/CONST'; @@ -86,7 +86,7 @@ test('getOrderedReportIDs on 5k reports', async () => { }, ], ]), - ) as unknown as Record; + ) as unknown as OnyxCollection; Onyx.multiSet({ ...mockedResponseMap,