-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
25 additions
and
34 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 |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import SCREENS from '@src/SCREENS'; | ||
import extractPolicyIDFromQuery from './extractPolicyIDFromQuery'; | ||
import getTopmostBottomTabRoute from './getTopmostBottomTabRoute'; | ||
import getTopmostCentralPaneRoute from './getTopmostCentralPaneRoute'; | ||
import type {RootStackParamList, State} from './types'; | ||
|
||
/** | ||
* returns policyID value if one exists in navigation state | ||
* | ||
* PolicyID in this app can be stored in two ways: | ||
* - on most screens but NOT Search as `policyID` param | ||
* - on Search related screens as policyID filter inside `q` (SearchQuery) param | ||
* - on most screens but NOT Search as `policyID` param (on bottom tab screens) | ||
* - on Search related screens as policyID filter inside `q` (SearchQuery) param (only for SEARCH_CENTRAL_PANE) | ||
*/ | ||
const getPolicyIDFromState = (state: State<RootStackParamList>): string | undefined => { | ||
const topmostBottomTabRoute = getTopmostBottomTabRoute(state); | ||
|
||
const policyID = topmostBottomTabRoute && topmostBottomTabRoute.params && 'policyID' in topmostBottomTabRoute.params && topmostBottomTabRoute.params?.policyID; | ||
if (policyID) { | ||
return topmostBottomTabRoute.params?.policyID as string; | ||
if (!topmostBottomTabRoute) { | ||
return; | ||
} | ||
|
||
if (topmostBottomTabRoute.name === SCREENS.SEARCH.BOTTOM_TAB) { | ||
const topmostCentralPaneRoute = getTopmostCentralPaneRoute(state); | ||
return extractPolicyIDFromQuery(topmostCentralPaneRoute); | ||
} | ||
|
||
return extractPolicyIDFromQuery(topmostBottomTabRoute); | ||
const policyID = topmostBottomTabRoute && topmostBottomTabRoute.params && 'policyID' in topmostBottomTabRoute.params && topmostBottomTabRoute.params?.policyID; | ||
return policyID ? (topmostBottomTabRoute.params?.policyID as string) : undefined; | ||
}; | ||
|
||
export default getPolicyIDFromState; |
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