-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18967 from dukenv0307/fix/18828
Fix open some pages by link display page not found
- Loading branch information
Showing
7 changed files
with
136 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import compose from '../../libs/compose'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import withPolicy, {policyPropTypes, policyDefaultProps} from './withPolicy'; | ||
import getComponentDisplayName from '../../libs/getComponentDisplayName'; | ||
import FullscreenLoadingIndicator from '../../components/FullscreenLoadingIndicator'; | ||
|
||
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, | ||
|
||
/** Indicated whether the report data is loading */ | ||
isLoadingReportData: PropTypes.bool, | ||
|
||
...policyPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
forwardedRef: () => {}, | ||
isLoadingReportData: true, | ||
...policyDefaultProps, | ||
}; | ||
|
||
const WithPolicyAndFullscreenLoading = (props) => { | ||
if (props.isLoadingReportData && _.isEmpty(props.policy)) { | ||
return <FullscreenLoadingIndicator />; | ||
} | ||
|
||
const rest = _.omit(props, ['forwardedRef']); | ||
return ( | ||
<WrappedComponent | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...rest} | ||
ref={props.forwardedRef} | ||
/> | ||
); | ||
}; | ||
|
||
WithPolicyAndFullscreenLoading.propTypes = propTypes; | ||
WithPolicyAndFullscreenLoading.defaultProps = defaultProps; | ||
WithPolicyAndFullscreenLoading.displayName = `WithPolicyAndFullscreenLoading(${getComponentDisplayName(WrappedComponent)})`; | ||
|
||
const withPolicyAndFullscreenLoading = React.forwardRef((props, ref) => ( | ||
<WithPolicyAndFullscreenLoading | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
forwardedRef={ref} | ||
/> | ||
)); | ||
|
||
return compose( | ||
withPolicy, | ||
withOnyx({ | ||
isLoadingReportData: { | ||
key: ONYXKEYS.IS_LOADING_REPORT_DATA, | ||
}, | ||
}), | ||
)(withPolicyAndFullscreenLoading); | ||
} |