Skip to content

Commit 410c7a2

Browse files
committed
fix: Remove call to getReportNameValuePairs() in method canSeeDefaultRoom
1 parent 44d8ae5 commit 410c7a2

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7864,11 +7864,11 @@ function isIOUOwnedByCurrentUser(report: OnyxEntry<Report>, allReportsDict?: Ony
78647864
* Assuming the passed in report is a default room, lets us know whether we can see it or not, based on permissions and
78657865
* the various subsets of users we've allowed to use default rooms.
78667866
*/
7867-
function canSeeDefaultRoom(report: OnyxEntry<Report>, betas: OnyxEntry<Beta[]>): boolean {
7867+
function canSeeDefaultRoom(report: OnyxEntry<Report>, betas: OnyxEntry<Beta[]>, isReportArchived = false): boolean {
78687868
// Include archived rooms
78697869
// This will get removed as part of https://github.com/Expensify/App/issues/59961
78707870
// eslint-disable-next-line deprecation/deprecation
7871-
if (isArchivedNonExpenseReport(report, !!getReportNameValuePairs(report?.reportID)?.private_isArchived)) {
7871+
if (isArchivedNonExpenseReport(report, isReportArchived)) {
78727872
return true;
78737873
}
78747874

@@ -7886,9 +7886,9 @@ function canSeeDefaultRoom(report: OnyxEntry<Report>, betas: OnyxEntry<Beta[]>):
78867886
return Permissions.isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS, betas ?? []);
78877887
}
78887888

7889-
function canAccessReport(report: OnyxEntry<Report>, betas: OnyxEntry<Beta[]>): boolean {
7889+
function canAccessReport(report: OnyxEntry<Report>, betas: OnyxEntry<Beta[]>, isReportArchived = false): boolean {
78907890
// We hide default rooms (it's basically just domain rooms now) from people who aren't on the defaultRooms beta.
7891-
if (isDefaultRoom(report) && !canSeeDefaultRoom(report, betas)) {
7891+
if (isDefaultRoom(report) && !canSeeDefaultRoom(report, betas, isReportArchived)) {
78927892
return false;
78937893
}
78947894

@@ -8199,7 +8199,7 @@ function reasonForReportToBeInOptionList({
81998199
return null;
82008200
}
82018201

8202-
if (!canAccessReport(report, betas)) {
8202+
if (!canAccessReport(report, betas, isReportArchived)) {
82038203
return null;
82048204
}
82058205

@@ -9291,8 +9291,8 @@ function isReportParticipant(accountID: number | undefined, report: OnyxEntry<Re
92919291
/**
92929292
* Check to see if the current user has access to view the report.
92939293
*/
9294-
function canCurrentUserOpenReport(report: OnyxEntry<Report>): boolean {
9295-
return (isReportParticipant(currentUserAccountID, report) || isPublicRoom(report)) && canAccessReport(report, allBetas);
9294+
function canCurrentUserOpenReport(report: OnyxEntry<Report>, isReportArchived = false): boolean {
9295+
return (isReportParticipant(currentUserAccountID, report) || isPublicRoom(report)) && canAccessReport(report, allBetas, isReportArchived);
92969296
}
92979297

92989298
function shouldUseFullTitleToDisplay(report: OnyxEntry<Report>): boolean {

src/pages/home/report/ReportActionItemParentAction.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {View} from 'react-native';
33
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
44
import OfflineWithFeedback from '@components/OfflineWithFeedback';
55
import useNetwork from '@hooks/useNetwork';
6+
import useReportIsArchived from '@hooks/useReportIsArchived';
67
import useResponsiveLayout from '@hooks/useResponsiveLayout';
78
import useThemeStyles from '@hooks/useThemeStyles';
89
import onyxSubscribe from '@libs/onyxSubscribe';
@@ -81,6 +82,7 @@ function ReportActionItemParentAction({
8182
const [allAncestors, setAllAncestors] = useState<Ancestor[]>([]);
8283
const {isOffline} = useNetwork();
8384
const {isInNarrowPaneModal} = useResponsiveLayout();
85+
const isReportArchived = useReportIsArchived(report?.reportID);
8486

8587
useEffect(() => {
8688
const unsubscribeReports: Array<() => void> = [];
@@ -137,14 +139,14 @@ function ReportActionItemParentAction({
137139
{shouldDisplayThreadDivider && (
138140
<ThreadDivider
139141
ancestor={ancestor}
140-
isLinkDisabled={!canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.reportID])}
142+
isLinkDisabled={!canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.reportID], isReportArchived)}
141143
/>
142144
)}
143145
<ReportActionItem
144146
allReports={allReports}
145147
policies={policies}
146148
onPress={
147-
canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.reportID])
149+
canCurrentUserOpenReport(ancestorReports.current?.[ancestor?.report?.reportID], isReportArchived)
148150
? () => navigateToLinkedReportAction(ancestor, isInNarrowPaneModal, canUserPerformWriteAction, isOffline)
149151
: undefined
150152
}

src/pages/home/report/withReportAndReportActionOrNotFound.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, {useEffect, useMemo} from 'react';
44
import type {OnyxEntry} from 'react-native-onyx';
55
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
66
import useOnyx from '@hooks/useOnyx';
7+
import useReportIsArchived from '@hooks/useReportIsArchived';
78
import useResponsiveLayout from '@hooks/useResponsiveLayout';
89
import {openReport} from '@libs/actions/Report';
910
import getComponentDisplayName from '@libs/getComponentDisplayName';
@@ -83,7 +84,8 @@ export default function <TProps extends WithReportAndReportActionOrNotFoundProps
8384
// Perform all the loading checks
8485
const isLoadingReport = isLoadingReportData && !report?.reportID;
8586
const isLoadingReportAction = isEmptyObject(reportActions) || (reportMetadata?.isLoadingInitialReportActions && isEmptyObject(linkedReportAction));
86-
const shouldHideReport = !isLoadingReport && (!report?.reportID || !canAccessReport(report, betas));
87+
const isReportArchived = useReportIsArchived(report?.reportID);
88+
const shouldHideReport = !isLoadingReport && (!report?.reportID || !canAccessReport(report, betas, isReportArchived));
8789

8890
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
8991
if ((isLoadingReport || isLoadingReportAction) && !shouldHideReport) {

src/pages/home/report/withReportOrNotFound.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, {useEffect} from 'react';
55
import type {OnyxEntry} from 'react-native-onyx';
66
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
77
import useOnyx from '@hooks/useOnyx';
8+
import useReportIsArchived from '@hooks/useReportIsArchived';
89
import {openReport} from '@libs/actions/Report';
910
import getComponentDisplayName from '@libs/getComponentDisplayName';
1011
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
@@ -72,7 +73,7 @@ export default function (
7273
const contentShown = React.useRef(false);
7374
const isReportIdInRoute = !!props.route.params.reportID?.length;
7475
const isReportLoaded = !isEmptyObject(report) && !!report?.reportID;
75-
76+
const isReportArchived = useReportIsArchived(report?.reportID);
7677
// The `isLoadingInitialReportActions` value will become `false` only after the first OpenReport API call is finished (either succeeded or failed)
7778
const shouldFetchReport = isReportIdInRoute && reportMetadata?.isLoadingInitialReportActions !== false;
7879

@@ -90,7 +91,7 @@ export default function (
9091

9192
if (shouldRequireReportID || isReportIdInRoute) {
9293
const shouldShowFullScreenLoadingIndicator = !isReportLoaded && (isLoadingReportData !== false || shouldFetchReport);
93-
const shouldShowNotFoundPage = !isReportLoaded || !canAccessReport(report, betas);
94+
const shouldShowNotFoundPage = !isReportLoaded || !canAccessReport(report, betas, isReportArchived);
9495

9596
// 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.
9697
// Return null for this case to avoid rendering FullScreenLoadingIndicator or NotFoundPage when animating transition.

0 commit comments

Comments
 (0)