Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/hooks/useAutoCreateTrackWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {setOnboardingAdminsChatReportID, setOnboardingPolicyID} from '@userActio
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OnboardingPurpose, OnboardingRHPVariant, Policy} from '@src/types/onyx';
import useArchivedReportsIDSet from './useArchivedReportsIDSet';
import useOnboardingWorkspaceCreationState from './useOnboardingWorkspaceCreationState';
import useOnyx from './useOnyx';
import usePermissions from './usePermissions';
Expand Down Expand Up @@ -52,7 +51,7 @@ function useAutoCreateTrackWorkspace() {

const [conciergeChatReportID = ''] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING);
const archivedReportsIDSet = useArchivedReportsIDSet();
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const {isBetaEnabled} = usePermissions();

const mergedAccountConciergeReportID = !onboardingValues?.shouldRedirectToClassicAfterMerge && onboardingValues?.shouldValidate ? conciergeChatReportID : undefined;
Expand Down Expand Up @@ -126,7 +125,7 @@ function useAutoCreateTrackWorkspace() {
shouldUseNarrowLayout,
isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS),
conciergeChatReportID,
archivedReportsIDSet,
reportNameValuePairs,
newPolicyID,
mergedAccountConciergeReportID,
false,
Expand Down Expand Up @@ -155,7 +154,7 @@ function useAutoCreateTrackWorkspace() {
shouldUseNarrowLayout,
isBetaEnabled,
conciergeChatReportID,
archivedReportsIDSet,
reportNameValuePairs,
mergedAccountConciergeReportID,
],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState} from 'react';
import useArchivedReportsIDSet from '@hooks/useArchivedReportsIDSet';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator';
import FreezeWrapper from '@libs/Navigation/AppNavigator/FreezeWrapper';
Expand All @@ -11,6 +11,7 @@ import type {ReportsSplitNavigatorParamList, TabNavigatorParamList} from '@libs/
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import type NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
Expand All @@ -26,7 +27,7 @@ const Split = createSplitNavigator<ReportsSplitNavigatorParamList>();
function ReportsSplitNavigator({route}: PlatformStackScreenProps<TabNavigatorParamList, typeof NAVIGATORS.REPORTS_SPLIT_NAVIGATOR>) {
const {isBetaEnabled} = usePermissions();
const splitNavigatorScreenOptions = useSplitNavigatorScreenOptions();
const archivedReportsIDSet = useArchivedReportsIDSet();
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const isOpenOnAdminRoom = shouldOpenOnAdminRoom();

const [initialReportID] = useState(() => {
Expand All @@ -50,7 +51,7 @@ function ReportsSplitNavigator({route}: PlatformStackScreenProps<TabNavigatorPar
return '';
}

const initialReport = ReportUtils.findLastAccessedReport(!isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS), isOpenOnAdminRoom, undefined, archivedReportsIDSet);
const initialReport = ReportUtils.findLastAccessedReport(!isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS), isOpenOnAdminRoom, undefined, reportNameValuePairs);
// eslint-disable-next-line rulesdir/no-default-id-values
return initialReport?.reportID ?? '';
});
Expand Down
10 changes: 8 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,13 @@ function getMostRecentlyVisitedReport(reports: Array<OnyxEntry<Report>>, lastVis
* This function is used to find the last accessed report and we don't need to subscribe the data in the UI.
* So please use `Onyx.connectWithoutView()` to get the necessary data when we remove the `Onyx.connect()`
*/
function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = false, excludeReportID?: string, archivedReportsIDSet?: ArchivedReportsIDSet): OnyxEntry<Report> {
function findLastAccessedReport(
ignoreDomainRooms: boolean,
openOnAdminRoom = false,
excludeReportID?: string,
reportNameValuePairs?: OnyxCollection<ReportNameValuePairs>,
): OnyxEntry<Report> {
const reportNameValuePairsCollection = reportNameValuePairs ?? allReportNameValuePair;
let reportsValues = Object.values(deprecatedAllReports ?? {});

if (openOnAdminRoom) {
Expand Down Expand Up @@ -2450,7 +2456,7 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa
reportsValues =
reportsValues.filter((report) => {
const reportNameValuePairsKey = `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`;
const isArchived = archivedReportsIDSet ? archivedReportsIDSet.has(reportNameValuePairsKey) : isArchivedReport(allReportNameValuePair?.[reportNameValuePairsKey]);
const isArchived = isArchivedReport(reportNameValuePairsCollection?.[reportNameValuePairsKey]);
return !isSystemChat(report) && !isArchived;
}) ?? [];

Expand Down
17 changes: 8 additions & 9 deletions src/libs/navigateAfterOnboarding.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {handleRHPVariantNavigation, shouldOpenRHPVariant} from '@components/SidePanel/RHPVariantTest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type {OnboardingRHPVariant} from '@src/types/onyx';
import type {OnboardingRHPVariant, ReportNameValuePairs} from '@src/types/onyx';
import {setDisableDismissOnEscape} from './actions/Modal';
import SidePanelActions from './actions/SidePanel';
import {setOnboardingRHPVariant} from './actions/Welcome';
import shouldOpenOnAdminRoom from './Navigation/helpers/shouldOpenOnAdminRoom';
import Navigation from './Navigation/Navigation';
import {findLastAccessedReport, isConciergeChatReport, isSelfDM} from './ReportUtils';
import type {ArchivedReportsIDSet} from './SearchUIUtils';

let onboardingRHPVariant: OnyxEntry<OnboardingRHPVariant>;
Onyx.connectWithoutView({
Expand All @@ -31,7 +30,7 @@ function getReportIDAfterOnboarding(
isSmallScreenWidth: boolean,
canUseDefaultRooms: boolean | undefined,
conciergeReportID: string,
archivedReportsIDSet: ArchivedReportsIDSet,
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>,
onboardingPolicyID?: string,
onboardingAdminsChatReportID?: string,
shouldPreventOpenAdminRoom = false,
Expand All @@ -46,7 +45,7 @@ function getReportIDAfterOnboarding(
return undefined;
}

const lastAccessedReport = findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom() && !shouldPreventOpenAdminRoom, undefined, archivedReportsIDSet);
const lastAccessedReport = findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom() && !shouldPreventOpenAdminRoom, undefined, reportNameValuePairs);
const lastAccessedReportID = lastAccessedReport?.reportID;

// When the user goes through the onboarding flow, a workspace can be created if the user selects specific options. The user should be taken to the #admins room for that workspace because it is the most natural place for them to start their experience in the app.
Expand All @@ -62,7 +61,7 @@ function navigateAfterOnboarding(
isSmallScreenWidth: boolean,
canUseDefaultRooms: boolean | undefined,
conciergeReportID: string,
archivedReportsIDSet: ArchivedReportsIDSet,
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>,
onboardingPolicyID?: string,
onboardingAdminsChatReportID?: string,
shouldPreventOpenAdminRoom = false,
Expand All @@ -89,7 +88,7 @@ function navigateAfterOnboarding(
isSmallScreenWidth,
canUseDefaultRooms,
conciergeReportID,
archivedReportsIDSet,
reportNameValuePairs,
onboardingPolicyID,
onboardingAdminsChatReportID,
shouldPreventOpenAdminRoom,
Expand All @@ -106,7 +105,7 @@ function navigateAfterOnboardingWithMicrotaskQueue(
isSmallScreenWidth: boolean,
canUseDefaultRooms: boolean | undefined,
conciergeReportID: string,
archivedReportsIDSet: ArchivedReportsIDSet,
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>,
onboardingPolicyID?: string,
onboardingAdminsChatReportID?: string,
shouldPreventOpenAdminRoom = false,
Expand All @@ -118,7 +117,7 @@ function navigateAfterOnboardingWithMicrotaskQueue(
isSmallScreenWidth,
canUseDefaultRooms,
conciergeReportID,
archivedReportsIDSet,
reportNameValuePairs,
onboardingPolicyID,
onboardingAdminsChatReportID,
shouldPreventOpenAdminRoom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Section from '@components/Section';
import isSidePanelReportSupported from '@components/SidePanel/isSidePanelReportSupported';
import Text from '@components/Text';
import useActivePolicy from '@hooks/useActivePolicy';
import useArchivedReportsIDSet from '@hooks/useArchivedReportsIDSet';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useHasActiveAdminPolicies from '@hooks/useHasActiveAdminPolicies';
import useLastWorkspaceNumber from '@hooks/useLastWorkspaceNumber';
Expand Down Expand Up @@ -65,7 +64,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin
const {isBetaEnabled} = usePermissions();
const [session] = useOnyx(ONYXKEYS.SESSION);
const [conciergeReportID = ''] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const archivedReportsIDSet = useArchivedReportsIDSet();
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const activePolicy = useActivePolicy();
const hasActiveAdminPolicies = useHasActiveAdminPolicies();
const lastWorkspaceNumber = useLastWorkspaceNumber();
Expand Down Expand Up @@ -252,7 +251,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin
isSmallScreenWidth,
isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS),
conciergeReportID,
archivedReportsIDSet,
reportNameValuePairs,
policyID,
adminsChatReportID,
// Onboarding tasks would show in Concierge instead of admins room for testing accounts, we should open where onboarding tasks are located
Expand All @@ -267,7 +266,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin
}, [
isBetaEnabled,
isSmallScreenWidth,
archivedReportsIDSet,
reportNameValuePairs,
onboardingAdminsChatReportID,
onboardingCompanySize,
onboardingMessages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails';
import useArchivedReportsIDSet from '@hooks/useArchivedReportsIDSet';
import useAutoCreateSubmitWorkspace from '@hooks/useAutoCreateSubmitWorkspace';
import useAutoCreateTrackWorkspace from '@hooks/useAutoCreateTrackWorkspace';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
Expand Down Expand Up @@ -47,7 +46,7 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID);
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const archivedReportsIDSet = useArchivedReportsIDSet();
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const [loginList] = useOnyx(ONYXKEYS.LOGINS, {selector: expensifyLoginsSelector});
const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING);
const [conciergeChatReportID = ''] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
Expand Down Expand Up @@ -107,7 +106,7 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
isSmallScreenWidth,
isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS),
conciergeChatReportID,
archivedReportsIDSet,
reportNameValuePairs,
onboardingPolicyID,
mergedAccountConciergeReportID,
false,
Expand All @@ -125,7 +124,7 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
onboardingMessages,
onboardingPolicyID,
isBetaEnabled,
archivedReportsIDSet,
reportNameValuePairs,
isSmallScreenWidth,
mergedAccountConciergeReportID,
conciergeChatReportID,
Expand Down
5 changes: 2 additions & 3 deletions src/pages/OnboardingWorkspaces/BaseOnboardingWorkspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import BareUserListItem from '@components/SelectionList/ListItem/BareUserListItem';
import Text from '@components/Text';
import useArchivedReportsIDSet from '@hooks/useArchivedReportsIDSet';
import useAutoCreateSubmitWorkspace from '@hooks/useAutoCreateSubmitWorkspace';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -59,7 +58,7 @@ function BaseOnboardingWorkspaces({route, shouldUseNativeStyles}: BaseOnboarding
const [session] = useOnyx(ONYXKEYS.SESSION);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const archivedReportsIDSet = useArchivedReportsIDSet();
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);

const isValidated = isCurrentUserValidated(loginList, session?.email);

Expand Down Expand Up @@ -107,7 +106,7 @@ function BaseOnboardingWorkspaces({route, shouldUseNativeStyles}: BaseOnboarding
isSmallScreenWidth,
isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS),
conciergeReportID,
archivedReportsIDSet,
reportNameValuePairs,
policy.automaticJoiningEnabled ? policy.policyID : undefined,
undefined,
false,
Expand Down
7 changes: 4 additions & 3 deletions src/pages/inbox/ReportRouteParamHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useFocusEffect, useNavigation, useRoute} from '@react-navigation/native';
import useArchivedReportsIDSet from '@hooks/useArchivedReportsIDSet';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
Expand All @@ -8,6 +8,7 @@ import {findLastAccessedReport} from '@libs/ReportUtils';
import {isNumeric} from '@libs/ValidationUtils';
import type {ReportsSplitNavigatorParamList, RightModalNavigatorParamList} from '@navigation/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';

type ReportScreenRoute =
Expand All @@ -22,7 +23,7 @@ function ReportRouteParamHandler() {
const route = useRoute<ReportScreenRoute>();
const navigation = useNavigation();
const {isBetaEnabled} = usePermissions();
const archivedReportsIDSet = useArchivedReportsIDSet();
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);

useFocusEffect(() => {
// Don't update if there is a reportID in the params already
Expand All @@ -39,7 +40,7 @@ function ReportRouteParamHandler() {
!isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS),
'openOnAdminRoom' in route.params && !!route.params.openOnAdminRoom,
undefined,
archivedReportsIDSet,
reportNameValuePairs,
)?.reportID;

// It's possible that reports aren't fully loaded yet
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7831,8 +7831,10 @@ describe('ReportUtils', () => {
});

it('should not return an archived report even if it was most recently accessed', () => {
const archivedReportsIDSet = new Set<string>([`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${archivedReport.reportID}`]);
const result = findLastAccessedReport(false, false, undefined, archivedReportsIDSet);
const reportNameValuePairsCollection = {
[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${archivedReport.reportID}`]: {private_isArchived: DateUtils.getDBTime()},
};
const result = findLastAccessedReport(false, false, undefined, reportNameValuePairsCollection);

// Even though the archived report has a more recent lastVisitTime,
// the function should filter it out and return the normal report
Expand Down
Loading
Loading