-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix crash app when opening split bill detail page by deep link #23977
Changes from 2 commits
b86968f
a809aa3
60a7ea3
1965a7a
ead3a3d
70e497f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,147 @@ | ||||||
import PropTypes from 'prop-types'; | ||||||
import React, {useEffect, useRef} from 'react'; | ||||||
import {withOnyx} from 'react-native-onyx'; | ||||||
import _ from 'underscore'; | ||||||
import getComponentDisplayName from '../../../libs/getComponentDisplayName'; | ||||||
import NotFoundPage from '../../ErrorPage/NotFoundPage'; | ||||||
import ONYXKEYS from '../../../ONYXKEYS'; | ||||||
import reportPropTypes from '../../reportPropTypes'; | ||||||
import reportActionPropTypes from './reportActionPropTypes'; | ||||||
import FullscreenLoadingIndicator from '../../../components/FullscreenLoadingIndicator'; | ||||||
import * as ReportUtils from '../../../libs/ReportUtils'; | ||||||
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils'; | ||||||
import * as Report from '../../../libs/actions/Report'; | ||||||
import compose from '../../../libs/compose'; | ||||||
import withWindowDimensions from '../../../components/withWindowDimensions'; | ||||||
|
||||||
export default function (WrappedComponent) { | ||||||
const propTypes = { | ||||||
/** The HOC takes an optional ref as a prop and passes it as a ref to the wrapped component. | ||||||
* That way, if a ref is passed to a component wrapped in the HOC, the ref is a reference to the wrapped component, not the HOC. */ | ||||||
forwardedRef: PropTypes.func, | ||||||
|
||||||
/** The report currently being looked at */ | ||||||
report: reportPropTypes, | ||||||
|
||||||
/** Array of report actions for this report */ | ||||||
reportActions: PropTypes.shape(reportActionPropTypes), | ||||||
|
||||||
/** The policies which the user has access to */ | ||||||
policies: PropTypes.objectOf( | ||||||
PropTypes.shape({ | ||||||
/** The policy name */ | ||||||
name: PropTypes.string, | ||||||
|
||||||
/** The type of the policy */ | ||||||
type: PropTypes.string, | ||||||
}), | ||||||
), | ||||||
|
||||||
/** Route params */ | ||||||
route: PropTypes.shape({ | ||||||
params: PropTypes.shape({ | ||||||
/** Report ID passed via route */ | ||||||
reportID: PropTypes.string, | ||||||
|
||||||
/** ReportActionID passed via route */ | ||||||
reportActionID: PropTypes.string, | ||||||
}), | ||||||
}).isRequired, | ||||||
|
||||||
/** Beta features list */ | ||||||
betas: PropTypes.arrayOf(PropTypes.string), | ||||||
|
||||||
/** Indicated whether the report data is loading */ | ||||||
isLoadingReportData: PropTypes.bool, | ||||||
|
||||||
/** Is the window width narrow, like on a mobile device? */ | ||||||
isSmallScreenWidth: PropTypes.bool.isRequired, | ||||||
}; | ||||||
|
||||||
const defaultProps = { | ||||||
forwardedRef: () => {}, | ||||||
reportActions: {}, | ||||||
report: { | ||||||
isLoadingReportActions: true, | ||||||
}, | ||||||
policies: {}, | ||||||
betas: [], | ||||||
isLoadingReportData: true, | ||||||
}; | ||||||
|
||||||
// eslint-disable-next-line rulesdir/no-negated-variables | ||||||
function WithReportAndReportActionOrNotFound(props) { | ||||||
// For small screen, we don't call openReport API when we go to a sub report page by deeplinnk | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to verify this, can you confirm if this is documented somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we open a sub report link the app doesn't call openReport API in openReportByDeepLink function. And in small screen, we go to sidebar after login in. That is why it doesn't call openReport API in small screen after login. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested this in small screen without this and it display not found page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we should alway call openReport one time here if props.report is empty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// So we need to call openReport here for small screen | ||||||
const firstRef = useRef(true); | ||||||
useEffect(() => { | ||||||
if (!firstRef.current) { | ||||||
return; | ||||||
} | ||||||
firstRef.current = false; | ||||||
if (props.isSmallScreenWidth) { | ||||||
Report.openReport(props.route.params.reportID); | ||||||
} | ||||||
}, [props.isSmallScreenWidth, props.route.params.reportID]); | ||||||
|
||||||
const isLoadingReport = props.isLoadingReportData && (_.isEmpty(props.report) || !props.report.reportID); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand these checks are complex, but we generally try to early return. Is it possible to structure the code:
|
||||||
const shouldHideReport = !isLoadingReport && (_.isEmpty(props.report) || !props.report.reportID || !ReportUtils.canAccessReport(props.report, props.policies, props.betas)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible to move this check after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. testing again if it's possible |
||||||
|
||||||
let reportAction = props.reportActions[`${props.route.params.reportActionID.toString()}`]; | ||||||
// Handle threads if needed | ||||||
if (reportAction === undefined || reportAction.reportActionID === undefined) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this section can be moved to this own method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be checked here to verify the reportAction is exist or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine, I am saying just move this block to it's own method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean we should create a method for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole block.
|
||||||
reportAction = ReportActionsUtils.getParentReportAction(props.report); | ||||||
} | ||||||
const isLoadingReportAction = _.isEmpty(props.reportActions) || (props.report.isLoadingReportActions && _.isEmpty(reportAction)); | ||||||
|
||||||
if ((isLoadingReport || isLoadingReportAction) && !shouldHideReport) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inline with the above comment, anyway to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is necessary here. if reportID is not found There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay thanks. |
||||||
return <FullscreenLoadingIndicator />; | ||||||
} | ||||||
if (shouldHideReport || _.isEmpty(reportAction)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check my comment above and then I feel There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will check and re-test again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some reports contain data but we can not access this report by |
||||||
return <NotFoundPage />; | ||||||
} | ||||||
const rest = _.omit(props, ['forwardedRef']); | ||||||
return ( | ||||||
<WrappedComponent | ||||||
// eslint-disable-next-line react/jsx-props-no-spreading | ||||||
{...rest} | ||||||
ref={props.forwardedRef} | ||||||
/> | ||||||
); | ||||||
} | ||||||
|
||||||
WithReportAndReportActionOrNotFound.propTypes = propTypes; | ||||||
WithReportAndReportActionOrNotFound.defaultProps = defaultProps; | ||||||
WithReportAndReportActionOrNotFound.displayName = `withReportAndReportActionOrNotFound(${getComponentDisplayName(WrappedComponent)})`; | ||||||
|
||||||
// eslint-disable-next-line rulesdir/no-negated-variables | ||||||
const withReportAndReportActionOrNotFound = React.forwardRef((props, ref) => ( | ||||||
<WithReportAndReportActionOrNotFound | ||||||
// eslint-disable-next-line react/jsx-props-no-spreading | ||||||
{...props} | ||||||
forwardedRef={ref} | ||||||
/> | ||||||
)); | ||||||
|
||||||
return compose( | ||||||
withWindowDimensions, | ||||||
withOnyx({ | ||||||
report: { | ||||||
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`, | ||||||
}, | ||||||
isLoadingReportData: { | ||||||
key: ONYXKEYS.IS_LOADING_REPORT_DATA, | ||||||
}, | ||||||
betas: { | ||||||
key: ONYXKEYS.BETAS, | ||||||
}, | ||||||
policies: { | ||||||
key: ONYXKEYS.COLLECTION.POLICY, | ||||||
}, | ||||||
reportActions: { | ||||||
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${route.params.reportID}`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Original code explicitly added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that fine because we wrap it in `` that is a string. |
||||||
canEvict: false, | ||||||
}, | ||||||
}), | ||||||
)(withReportAndReportActionOrNotFound); | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need
isLoadingReportingActions: true
in default props? Why can't we have empty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we can remove this. I add this to verify that this will loading until the API is complete.