Download wp-calypso/packages/command-palette/src/utils.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/command-palette/src/utils.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/command-palette/src/utils.ts
-
curl -L -o utils.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/command-palette/src/utils.ts
1.49 kB
| import { recordTracksEvent } from '@automattic/calypso-analytics'; | |
| import type { CommandCallBackParams } from './commands'; | |
| import type { SiteExcerptData } from '@automattic/sites'; | |
| export function isCustomDomain( siteSlug: string | null | undefined ): boolean { | |
| if ( ! siteSlug ) { | |
| return false; | |
| } | |
| return ! siteSlug.endsWith( '.wordpress.com' ) && ! siteSlug.endsWith( '.wpcomstaging.com' ); | |
| } | |
| export const siteUsesWpAdminInterface = ( site: SiteExcerptData | undefined ) => | |
| ( site?.jetpack && ! site?.is_wpcom_atomic ) || | |
| site?.options?.wpcom_admin_interface === 'wp-admin'; | |
| export const commandNavigation = | |
| ( path: string, openInNewTab?: boolean ) => | |
| ( { site, close, navigate, command, currentRoute }: CommandCallBackParams ) => { | |
| let url = path; | |
| url = url.replace( /:site/g, site?.slug ?? '' ); | |
| url = url.replace( /:siteId/g, site?.ID?.toString() ?? '' ); | |
| // Navigate from Calypso to WP Admin. | |
| if ( url.startsWith( '/wp-admin' ) && ! currentRoute.startsWith( '/wp-admin' ) ) { | |
| url = `https://${ site?.slug }${ url }`; | |
| } | |
| // Navigate from WP Admin to Calypso. | |
| if ( | |
| url.startsWith( '/' ) && | |
| ! url.startsWith( '/wp-admin' ) && | |
| currentRoute.startsWith( '/wp-admin' ) | |
| ) { | |
| url = `https://wordpress.com${ url }`; | |
| } | |
| recordTracksEvent( 'calypso_hosting_command_palette_navigate', { | |
| command: command.name, | |
| current_route: currentRoute, | |
| is_wp_admin: url.includes( '/wp-admin' ), | |
| } ); | |
| close(); | |
| navigate( url, openInNewTab ); | |
| }; | |