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

Ensure OpenReport is always called when deeplinking from an outside source #15994

Merged
merged 4 commits into from
Mar 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import styles from '../../../styles/styles';
import Navigation from '../../../libs/Navigation/Navigation';
import AnchorForCommentsOnly from '../../AnchorForCommentsOnly';
import AnchorForAttachmentsOnly from '../../AnchorForAttachmentsOnly';
import * as Report from '../../../libs/actions/Report';
import * as Url from '../../../libs/Url';
import ROUTES from '../../../ROUTES';

Expand Down Expand Up @@ -48,13 +47,6 @@ const AnchorRenderer = (props) => {
// If we are handling a New Expensify link then we will assume this should be opened by the app internally. This ensures that the links are opened internally via react-navigation
// instead of in a new tab or with a page refresh (which is the default behavior of an anchor tag)
if (internalNewExpensifyPath) {
// If we're navigating to a report, we need to call OpenReport here since componentDidMount doesn't get called
// when we're deeplinking to a report from a different report (it never unmounts).
if (attrPath.startsWith('r/')) {
const reportID = attrPath.split('/')[1];
Report.openReport(reportID);
}

Navigation.navigate(internalNewExpensifyPath);
return;
}
Expand Down
10 changes: 8 additions & 2 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ class ReportScreen extends React.Component {
}

componentDidUpdate(prevProps) {
if (this.props.route.params.reportID === prevProps.route.params.reportID) {
// If you already have a report open and are deeplinking to a new report on native,
// the ReportScreen never actually unmounts and the reportID in the route also doesn't change.
// Therefore, we need to compare if the existing reportID is the same as the one in the route
// before deciding that we shouldn't call OpenReport.
const onyxReportID = this.props.report.reportID;
const routeReportID = getReportID(this.props.route);
if (routeReportID === prevProps.route.params.reportID && (!onyxReportID || onyxReportID === routeReportID)) {
return;
}

Expand Down Expand Up @@ -159,7 +165,7 @@ class ReportScreen extends React.Component {
// It possible that we may not have the report object yet in Onyx yet e.g. we navigated to a URL for an accessible report that
// is not stored locally yet. If props.report.reportID exists, then the report has been stored locally and nothing more needs to be done.
// If it doesn't exist, then we fetch the report from the API.
if (this.props.report.reportID) {
if (this.props.report.reportID && this.props.report.reportID === getReportID(this.props.route)) {
return;
}

Expand Down