Skip to content

Commit 20f78ad

Browse files
authored
Merge pull request Expensify#68095 from DylanDylann/revert-67132-fix/67091
[CP Staging] Revert "fix: remove call to getReportNameValuePairs() in method findLastAccessedReport"
2 parents f0213a6 + 8e341c7 commit 20f78ad

17 files changed

Lines changed: 88 additions & 209 deletions

File tree

src/hooks/useLastAccessedReport.ts

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/libs/Navigation/AppNavigator/Navigators/ReportsSplitNavigator.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, {useState} from 'react';
2-
import useLastAccessedReport from '@hooks/useLastAccessedReport';
32
import usePermissions from '@hooks/usePermissions';
43
import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator';
54
import FreezeWrapper from '@libs/Navigation/AppNavigator/FreezeWrapper';
@@ -8,6 +7,7 @@ import getCurrentUrl from '@libs/Navigation/currentUrl';
87
import shouldOpenOnAdminRoom from '@libs/Navigation/helpers/shouldOpenOnAdminRoom';
98
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
109
import type {AuthScreensParamList, ReportsSplitNavigatorParamList} from '@libs/Navigation/types';
10+
import * as ReportUtils from '@libs/ReportUtils';
1111
import CONST from '@src/CONST';
1212
import type NAVIGATORS from '@src/NAVIGATORS';
1313
import SCREENS from '@src/SCREENS';
@@ -24,7 +24,6 @@ const Split = createSplitNavigator<ReportsSplitNavigatorParamList>();
2424
function ReportsSplitNavigator({route}: PlatformStackScreenProps<AuthScreensParamList, typeof NAVIGATORS.REPORTS_SPLIT_NAVIGATOR>) {
2525
const {isBetaEnabled} = usePermissions();
2626
const splitNavigatorScreenOptions = useSplitNavigatorScreenOptions();
27-
const {lastAccessReportID} = useLastAccessedReport(!isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS), shouldOpenOnAdminRoom());
2827

2928
const [initialReportID] = useState(() => {
3029
const currentURL = getCurrentUrl();
@@ -33,8 +32,9 @@ function ReportsSplitNavigator({route}: PlatformStackScreenProps<AuthScreensPara
3332
return reportIdFromPath;
3433
}
3534

35+
const initialReport = ReportUtils.findLastAccessedReport(!isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS), shouldOpenOnAdminRoom());
3636
// eslint-disable-next-line rulesdir/no-default-id-values
37-
return lastAccessReportID ?? '';
37+
return initialReport?.reportID ?? '';
3838
});
3939

4040
return (

src/libs/ReportUtils.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,25 +1967,16 @@ function getMostRecentlyVisitedReport(reports: Array<OnyxEntry<Report>>, reportM
19671967
return lodashMaxBy(filteredReports, (a) => [reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? '', a?.lastReadTime ?? '']);
19681968
}
19691969

1970-
function findLastAccessedReport(
1971-
reports: OnyxCollection<OnyxEntry<Report>>,
1972-
policies: OnyxCollection<OnyxEntry<Policy>>,
1973-
reportMetadata: OnyxCollection<ReportMetadata>,
1974-
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>,
1975-
ignoreDomainRooms: boolean,
1976-
openOnAdminRoom = false,
1977-
policyID?: string,
1978-
excludeReportID?: string,
1979-
): OnyxEntry<Report> {
1970+
function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = false, policyID?: string, excludeReportID?: string): OnyxEntry<Report> {
19801971
// If it's the user's first time using New Expensify, then they could either have:
19811972
// - just a Concierge report, if so we'll return that
19821973
// - their Concierge report, and a separate report that must have deeplinked them to the app before they created their account.
19831974
// If it's the latter, we'll use the deeplinked report over the Concierge report,
19841975
// since the Concierge report would be incorrectly selected over the deep-linked report in the logic below.
19851976

1986-
const policyMemberAccountIDs = getPolicyEmployeeListByIdWithoutCurrentUser(policies, policyID, currentUserAccountID);
1977+
const policyMemberAccountIDs = getPolicyEmployeeListByIdWithoutCurrentUser(allPolicies, policyID, currentUserAccountID);
19871978

1988-
let reportsValues = Object.values(reports ?? {});
1979+
let reportsValues = Object.values(allReports ?? {});
19891980

19901981
if (!!policyID || policyMemberAccountIDs.length > 0) {
19911982
reportsValues = filterReportsByPolicyIDAndMemberAccountIDs(reportsValues, policyMemberAccountIDs, policyID);
@@ -2025,29 +2016,24 @@ function findLastAccessedReport(
20252016
// and it prompts the user to use the Concierge chat instead.
20262017
reportsValues =
20272018
reportsValues.filter((report) => {
2028-
return !isSystemChat(report) && !isArchivedReport(reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`]);
2019+
// This will get removed as part of https://github.com/Expensify/App/issues/59961
2020+
// eslint-disable-next-line deprecation/deprecation
2021+
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);
2022+
2023+
return !isSystemChat(report) && !isArchivedReport(reportNameValuePairs);
20292024
}) ?? [];
20302025

20312026
// At least two reports remain: self DM and Concierge chat.
20322027
// Return the most recently visited report. Get the last read report from the report metadata.
20332028
// If allReportMetadata is empty we'll return most recent report owned by user
2034-
if (isEmptyObject(reportMetadata)) {
2029+
if (isEmptyObject(allReportMetadata)) {
20352030
const ownedReports = reportsValues.filter((report) => report?.ownerAccountID === currentUserAccountID);
20362031
if (ownedReports.length > 0) {
20372032
return lodashMaxBy(ownedReports, (a) => a?.lastReadTime ?? '');
20382033
}
20392034
return lodashMaxBy(reportsValues, (a) => a?.lastReadTime ?? '');
20402035
}
2041-
return getMostRecentlyVisitedReport(reportsValues, reportMetadata);
2042-
}
2043-
2044-
/**
2045-
* This function is used to retrieve the last accessed report in background
2046-
* It's used in the case we need to get the last accessed report in a listener like openReportFromDeepLink
2047-
* Please use useLastAccessedReport hook instead if we need to get the last accessed report from the UI
2048-
*/
2049-
function findLastAccessedReportWithoutView(ignoreDomainRooms: boolean, openOnAdminRoom = false, policyID?: string, excludeReportID?: string): OnyxEntry<Report> {
2050-
return findLastAccessedReport(allReports, allPolicies, allReportMetadata, allReportNameValuePair, ignoreDomainRooms, openOnAdminRoom, policyID, excludeReportID);
2036+
return getMostRecentlyVisitedReport(reportsValues, allReportMetadata);
20512037
}
20522038

20532039
/**
@@ -11669,7 +11655,6 @@ export {
1166911655
isWorkspaceTaskReport,
1167011656
isWorkspaceThread,
1167111657
getReportStatusTranslation,
11672-
findLastAccessedReportWithoutView,
1167311658
};
1167411659

1167511660
export type {

src/libs/actions/Report.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ import {
114114
buildOptimisticSelfDMReport,
115115
buildOptimisticUnreportedTransactionAction,
116116
canUserPerformWriteAction as canUserPerformWriteActionReportUtils,
117-
findLastAccessedReportWithoutView,
117+
findLastAccessedReport,
118118
findSelfDMReportID,
119119
formatReportLastMessageText,
120120
generateReportID,
@@ -3412,7 +3412,7 @@ function openReportFromDeepLink(
34123412
// Navigate to the report after sign-in/sign-up.
34133413
InteractionManager.runAfterInteractions(() => {
34143414
waitForUserSignIn().then(() => {
3415-
const connection = Onyx.connectWithoutView({
3415+
const connection = Onyx.connect({
34163416
key: ONYXKEYS.NVP_ONBOARDING,
34173417
callback: (val) => {
34183418
if (!val && !isAnonymousUser()) {
@@ -3458,7 +3458,7 @@ function openReportFromDeepLink(
34583458
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
34593459
// If the report does not exist, navigate to the last accessed report or Concierge chat
34603460
if (reportID && !report) {
3461-
const lastAccessedReportID = findLastAccessedReportWithoutView(false, shouldOpenOnAdminRoom(), undefined, reportID)?.reportID;
3461+
const lastAccessedReportID = findLastAccessedReport(false, shouldOpenOnAdminRoom(), undefined, reportID)?.reportID;
34623462
if (lastAccessedReportID) {
34633463
const lastAccessedReportRoute = ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID);
34643464
Navigation.navigate(lastAccessedReportRoute);
@@ -3504,7 +3504,9 @@ function getCurrentUserEmail(): string | undefined {
35043504
return currentUserEmail;
35053505
}
35063506

3507-
function navigateToMostRecentReport(currentReport: OnyxEntry<Report>, lastAccessedReportID: string | undefined) {
3507+
function navigateToMostRecentReport(currentReport: OnyxEntry<Report>) {
3508+
const lastAccessedReportID = findLastAccessedReport(false, false, undefined, currentReport?.reportID)?.reportID;
3509+
35083510
if (lastAccessedReportID) {
35093511
const lastAccessedReportRoute = ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID);
35103512
Navigation.goBack(lastAccessedReportRoute);
@@ -3520,7 +3522,8 @@ function navigateToMostRecentReport(currentReport: OnyxEntry<Report>, lastAccess
35203522
}
35213523
}
35223524

3523-
function getMostRecentReportID(lastAccessedReportID: string | undefined) {
3525+
function getMostRecentReportID(currentReport: OnyxEntry<Report>) {
3526+
const lastAccessedReportID = findLastAccessedReport(false, false, undefined, currentReport?.reportID)?.reportID;
35243527
return lastAccessedReportID ?? conciergeReportID;
35253528
}
35263529

@@ -3537,7 +3540,7 @@ function joinRoom(report: OnyxEntry<Report>) {
35373540
);
35383541
}
35393542

3540-
function leaveGroupChat(reportID: string, lastAccessedReportID: string | undefined) {
3543+
function leaveGroupChat(reportID: string) {
35413544
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
35423545
if (!report) {
35433546
Log.warn('Attempting to leave Group Chat that does not existing locally');
@@ -3589,12 +3592,12 @@ function leaveGroupChat(reportID: string, lastAccessedReportID: string | undefin
35893592
},
35903593
];
35913594

3592-
navigateToMostRecentReport(report, lastAccessedReportID);
3595+
navigateToMostRecentReport(report);
35933596
API.write(WRITE_COMMANDS.LEAVE_GROUP_CHAT, {reportID}, {optimisticData, successData, failureData});
35943597
}
35953598

35963599
/** Leave a report by setting the state to submitted and closed */
3597-
function leaveRoom(reportID: string, lastAccessedReportID: string | undefined, isWorkspaceMemberLeavingWorkspaceRoom = false) {
3600+
function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = false) {
35983601
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
35993602

36003603
if (!report) {
@@ -3701,7 +3704,7 @@ function leaveRoom(reportID: string, lastAccessedReportID: string | undefined, i
37013704
return;
37023705
}
37033706
// In other cases, the report is deleted and we should move the user to another report.
3704-
navigateToMostRecentReport(report, lastAccessedReportID);
3707+
navigateToMostRecentReport(report);
37053708
}
37063709

37073710
function buildInviteToRoomOnyxData(reportID: string, inviteeEmailsToAccountIDs: InvitedEmailsToAccountIDs, formatPhoneNumber: LocaleContextProps['formatPhoneNumber']) {

src/libs/actions/Task.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ function getParentReport(report: OnyxEntry<OnyxTypes.Report>): OnyxEntry<OnyxTyp
10451045
* @param report - The task report being deleted
10461046
* @returns The URL to navigate to
10471047
*/
1048-
function getNavigationUrlOnTaskDelete(report: OnyxEntry<OnyxTypes.Report>, lastAccessedReportID: string | undefined): string | undefined {
1048+
function getNavigationUrlOnTaskDelete(report: OnyxEntry<OnyxTypes.Report>): string | undefined {
10491049
if (!report) {
10501050
return undefined;
10511051
}
@@ -1062,7 +1062,7 @@ function getNavigationUrlOnTaskDelete(report: OnyxEntry<OnyxTypes.Report>, lastA
10621062
}
10631063

10641064
// If no parent report, try to navigate to most recent report
1065-
const mostRecentReportID = getMostRecentReportID(lastAccessedReportID);
1065+
const mostRecentReportID = getMostRecentReportID(report);
10661066
if (mostRecentReportID) {
10671067
return ROUTES.REPORT_WITH_ID.getRoute(mostRecentReportID);
10681068
}
@@ -1073,7 +1073,7 @@ function getNavigationUrlOnTaskDelete(report: OnyxEntry<OnyxTypes.Report>, lastA
10731073
/**
10741074
* Cancels a task by setting the report state to SUBMITTED and status to CLOSED
10751075
*/
1076-
function deleteTask(report: OnyxEntry<OnyxTypes.Report>, lastAccessedReportID: string | undefined) {
1076+
function deleteTask(report: OnyxEntry<OnyxTypes.Report>) {
10771077
if (!report) {
10781078
return;
10791079
}
@@ -1212,7 +1212,7 @@ function deleteTask(report: OnyxEntry<OnyxTypes.Report>, lastAccessedReportID: s
12121212
API.write(WRITE_COMMANDS.CANCEL_TASK, parameters, {optimisticData, successData, failureData});
12131213
notifyNewAction(report.reportID, currentUserAccountID);
12141214

1215-
const urlToNavigateBack = getNavigationUrlOnTaskDelete(report, lastAccessedReportID);
1215+
const urlToNavigateBack = getNavigationUrlOnTaskDelete(report);
12161216
if (urlToNavigateBack) {
12171217
Navigation.goBack();
12181218
return urlToNavigateBack;

src/libs/navigateAfterOnboarding.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import type {OnyxEntry} from 'react-native-onyx';
21
import ROUTES from '@src/ROUTES';
3-
import type {Report} from '@src/types/onyx';
42
import {setDisableDismissOnEscape} from './actions/Modal';
3+
import shouldOpenOnAdminRoom from './Navigation/helpers/shouldOpenOnAdminRoom';
54
import Navigation from './Navigation/Navigation';
6-
import {isConciergeChatReport} from './ReportUtils';
5+
import {findLastAccessedReport, isConciergeChatReport} from './ReportUtils';
76

87
const navigateAfterOnboarding = (
98
isSmallScreenWidth: boolean,
10-
lastAccessedReport: OnyxEntry<Report>,
9+
canUseDefaultRooms: boolean | undefined,
1110
onboardingPolicyID?: string,
1211
onboardingAdminsChatReportID?: string,
1312
shouldPreventOpenAdminRoom = false,
@@ -25,6 +24,7 @@ const navigateAfterOnboarding = (
2524
reportID = onboardingAdminsChatReportID;
2625
}
2726
} else {
27+
const lastAccessedReport = findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom() && !shouldPreventOpenAdminRoom);
2828
const lastAccessedReportID = lastAccessedReport?.reportID;
2929
// we don't want to navigate to newly created workspaces after onboarding is completed.
3030
if (lastAccessedReportID && lastAccessedReport.policyID !== onboardingPolicyID && !isConciergeChatReport(lastAccessedReport)) {
@@ -52,13 +52,13 @@ const navigateAfterOnboarding = (
5252

5353
const navigateAfterOnboardingWithMicrotaskQueue = (
5454
isSmallScreenWidth: boolean,
55-
lastAccessedReport: OnyxEntry<Report>,
55+
canUseDefaultRooms: boolean | undefined,
5656
onboardingPolicyID?: string,
5757
onboardingAdminsChatReportID?: string,
5858
shouldPreventOpenAdminRoom = false,
5959
) => {
6060
Navigation.setNavigationActionToMicrotaskQueue(() => {
61-
navigateAfterOnboarding(isSmallScreenWidth, lastAccessedReport, onboardingPolicyID, onboardingAdminsChatReportID, shouldPreventOpenAdminRoom);
61+
navigateAfterOnboarding(isSmallScreenWidth, canUseDefaultRooms, onboardingPolicyID, onboardingAdminsChatReportID, shouldPreventOpenAdminRoom);
6262
});
6363
};
6464

0 commit comments

Comments
 (0)