Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] fix: onboarding modal is not displayed in web #54329

Merged
merged 5 commits into from
Dec 19, 2024
Merged
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
6 changes: 6 additions & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
function getReportID(route: ReportScreenNavigationProps['route']): string {
// The report ID is used in an onyx key. If it's an empty string, onyx will return
// a collection instead of an individual report.
return String(route.params?.reportID || 0);

Check failure on line 76 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

}

/**
Expand All @@ -94,14 +94,14 @@
if (!parentReportActions || !parentReportActionID) {
return;
}
return parentReportActions[parentReportActionID ?? '0'];

Check failure on line 97 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

}

function ReportScreen({route, currentReportID = '', navigation}: ReportScreenProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const reportIDFromRoute = getReportID(route);
const reportActionIDFromRoute = route?.params?.reportActionID ?? '';

Check failure on line 104 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const isFocused = useIsFocused();
const prevIsFocused = usePrevious(isFocused);
const firstRenderRef = useRef(true);
Expand All @@ -112,13 +112,14 @@
const {isOffline} = useNetwork();
const {shouldUseNarrowLayout, isInNarrowPaneModal} = useResponsiveLayout();
const {activeWorkspaceID} = useActiveWorkspace();
const lastAccessedReportIDRef = useRef(false);

const [modal] = useOnyx(ONYXKEYS.MODAL);
const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {initialValue: false});
const [accountManagerReportID] = useOnyx(ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID, {initialValue: ''});
// If accountManagerReportID is an empty string, using ?? can crash the app.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${accountManagerReportID || '-1'}`);

Check failure on line 122 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const [userLeavingStatus] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`, {initialValue: false});
const [reportOnyx, reportResult] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true});
const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {initialValue: defaultReportMetadata});
Expand All @@ -126,9 +127,9 @@
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}});
const [betas] = useOnyx(ONYXKEYS.BETAS);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportOnyx?.parentReportID || -1}`, {

Check failure on line 130 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

canEvict: false,
selector: (parentReportActions) => getParentReportAction(parentReportActions, reportOnyx?.parentReportActionID ?? ''),

Check failure on line 132 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [workspaceTooltip] = useOnyx(ONYXKEYS.NVP_WORKSPACE_TOOLTIP);
Expand All @@ -151,6 +152,10 @@
return;
}

if (lastAccessedReportIDRef.current) {
return;
}

const lastAccessedReportID = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, !!route.params.openOnAdminRoom, activeWorkspaceID)?.reportID;

// It's possible that reports aren't fully loaded yet
Expand All @@ -160,6 +165,7 @@
}

Log.info(`[ReportScreen] no reportID found in params, setting it to lastAccessedReportID: ${lastAccessedReportID}`);
lastAccessedReportIDRef.current = true;
navigation.setParams({reportID: lastAccessedReportID});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the param is updating in the route, this useEffect can be triggered again, and navigation.setParams is called again with the outdated state that can cause the navigation stack to be overridden to the old state.

}, [activeWorkspaceID, canUseDefaultRooms, navigation, route, finishedLoadingApp]);

Expand Down Expand Up @@ -190,7 +196,7 @@
() =>
reportOnyx && {
lastReadTime: reportOnyx.lastReadTime,
reportID: reportOnyx.reportID ?? '',

Check failure on line 199 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

policyID: reportOnyx.policyID,
lastVisibleActionCreated: reportOnyx.lastVisibleActionCreated,
statusNum: reportOnyx.statusNum,
Expand Down Expand Up @@ -274,12 +280,12 @@
const hasHelpfulErrors = Object.keys(report?.errorFields ?? {}).some((key) => key !== 'notFound');
const shouldHideReport = !hasHelpfulErrors && !ReportUtils.canAccessReport(report, policies, betas);

const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportID ?? '', reportActions ?? [], isOffline);

Check failure on line 283 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const [transactionThreadReportActions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`);
const combinedReportActions = ReportActionsUtils.getCombinedReportActions(reportActions, transactionThreadReportID ?? null, Object.values(transactionThreadReportActions));
const lastReportAction = [...combinedReportActions, parentReportAction].find((action) => ReportUtils.canEditReportAction(action) && !ReportActionsUtils.isMoneyRequestAction(action));
const isSingleTransactionView = ReportUtils.isMoneyRequest(report) || ReportUtils.isTrackExpenseReport(report);
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '-1'}`];

Check failure on line 288 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const isTopMostReportId = currentReportID === reportIDFromRoute;
const didSubscribeToReportLeavingEvents = useRef(false);

Expand Down Expand Up @@ -321,7 +327,7 @@
}

useEffect(() => {
if (!transactionThreadReportID || !route?.params?.reportActionID || !ReportUtils.isOneTransactionThread(linkedAction?.childReportID ?? '-1', reportID ?? '', linkedAction)) {

Check failure on line 330 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(route?.params?.reportID));
Expand Down
Loading