Download wp-calypso/client/lib/jetpack/use-target-url.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/jetpack/use-target-url.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/jetpack/use-target-url.ts
-
curl -L -o use-target-url.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/jetpack/use-target-url.ts
1.93 kB
| import { useSelector } from 'calypso/state'; | |
| import isJetpackCloudEligible from 'calypso/state/selectors/is-jetpack-cloud-eligible'; | |
| import isJetpackSectionEnabledForSite from 'calypso/state/selectors/is-jetpack-section-enabled-for-site'; | |
| import { getSiteSlug } from 'calypso/state/sites/selectors'; | |
| import { getSelectedSiteId } from 'calypso/state/ui/selectors'; | |
| import type { AppState } from 'calypso/types'; | |
| /** | |
| * Constants | |
| */ | |
| const SOURCE_TO_JETPACK_PATH = { | |
| 'calypso-scanner': '/scan/[site]', | |
| 'calypso-backups': '/backup/[site]', | |
| 'calypso-activity-log': '/backup/activity/[site]', | |
| 'calypso-settings-security': '/settings/jetpack/[site]', | |
| }; | |
| const SOURCE_TO_CALYPSO_PATH = { | |
| 'calypso-scanner': '/activity-log/[site]', | |
| 'calypso-backups': '/activity-log/[site]', | |
| 'calypso-activity-log': '/activity-log/[site]', | |
| 'calypso-settings-security': '/settings/security/[site]', | |
| }; | |
| interface SourceToPath { | |
| [ key: string ]: string; | |
| } | |
| export function useTargetUrl( siteId: number | null ) { | |
| const isCloudEligible = useSelector( ( state ) => | |
| isJetpackCloudEligible( state, siteId as number ) | |
| ); | |
| const siteSlug = useSelector( ( state ) => getSiteSlug( state, siteId as number ) ); | |
| const shouldUseJetpackPath = useSelector( ( state: AppState ) => | |
| isJetpackSectionEnabledForSite( state, siteId ) | |
| ); | |
| const sourceToUrl = ( source: string ): string | null => { | |
| if ( ! siteId ) { | |
| return null; | |
| } | |
| if ( isCloudEligible ) { | |
| return `https://jetpack.com/redirect/?source=${ source }&site=${ siteId }`; | |
| } | |
| const paths = shouldUseJetpackPath | |
| ? ( SOURCE_TO_JETPACK_PATH as SourceToPath ) | |
| : ( SOURCE_TO_CALYPSO_PATH as SourceToPath ); | |
| if ( ! paths[ source ] ) { | |
| return source; | |
| } | |
| return paths[ source ].replace( '[site]', siteSlug ?? '' ); | |
| }; | |
| return sourceToUrl; | |
| } | |
| export function useTargetUrlForSelected() { | |
| const siteId = useSelector( getSelectedSiteId ); | |
| return useTargetUrl( siteId ); | |
| } | |