-
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.
Browse files
Browse the repository at this point in the history
…comment Highlight linked comment
- Loading branch information
Showing
6 changed files
with
75 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import lodashFindLast from 'lodash/findLast'; | ||
import lodashGet from 'lodash/get'; | ||
|
||
// This function is in a separate file than Navigation.js to avoid cyclic dependency. | ||
|
||
/** | ||
* Find the last visited report screen in the navigation state and get the linked reportActionID of it. | ||
* | ||
* @param {Object} state - The react-navigation state | ||
* @returns {String | undefined} - It's possible that there is no report screen | ||
*/ | ||
function getTopmostReportActionID(state) { | ||
if (!state) { | ||
return; | ||
} | ||
const topmostCentralPane = lodashFindLast(state.routes, (route) => route.name === 'CentralPaneNavigator'); | ||
|
||
if (!topmostCentralPane) { | ||
return; | ||
} | ||
|
||
const directReportActionIDParam = lodashGet(topmostCentralPane, 'params.params.reportActionID'); | ||
|
||
if (!topmostCentralPane.state && !directReportActionIDParam) { | ||
return; | ||
} | ||
|
||
if (directReportActionIDParam) { | ||
return directReportActionIDParam; | ||
} | ||
|
||
const topmostReport = lodashFindLast(topmostCentralPane.state.routes, (route) => route.name === 'Report'); | ||
if (!topmostReport) { | ||
return; | ||
} | ||
|
||
const topmostReportActionID = lodashGet(topmostReport, 'params.reportActionID'); | ||
|
||
return topmostReportActionID; | ||
} | ||
|
||
export default getTopmostReportActionID; |
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