Download wp-calypso/client/data/site-profiler/use-url-basic-metrics-query.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/site-profiler/use-url-basic-metrics-query.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/site-profiler/use-url-basic-metrics-query.ts
-
curl -L -o use-url-basic-metrics-query.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/site-profiler/use-url-basic-metrics-query.ts
1.16 kB
| import { useQuery } from '@tanstack/react-query'; | |
| import { BasicMetricsScored, UrlBasicMetricsQueryResponse } from 'calypso/data/site-profiler/types'; | |
| import wp from 'calypso/lib/wp'; | |
| import { getBasicMetricsScored } from './metrics-dictionaries'; | |
| function mapScores( response: UrlBasicMetricsQueryResponse ) { | |
| const { basic } = response; | |
| let basicMetricsScored = {} as BasicMetricsScored; | |
| if ( basic.success ) { | |
| basicMetricsScored = getBasicMetricsScored( basic.data ); | |
| } | |
| return { ...response, success: basic.success, basic: basicMetricsScored }; | |
| } | |
| export const useUrlBasicMetricsQuery = ( | |
| url?: string, | |
| hash?: string, | |
| advance = false, | |
| locale?: string | null | |
| ) => { | |
| return useQuery( { | |
| queryKey: [ 'url', 'basic-metrics', url, advance, locale ], | |
| queryFn: (): Promise< UrlBasicMetricsQueryResponse > => | |
| wp.req.get( | |
| { | |
| path: '/site-profiler/metrics/basic', | |
| apiNamespace: 'wpcom/v2', | |
| }, | |
| { url, ...( advance ? { advance: '1' } : {} ), locale } | |
| ), | |
| select: mapScores, | |
| meta: { | |
| persist: false, | |
| }, | |
| enabled: !! url && ! hash, // Disable if hash is present | |
| retry: false, | |
| refetchOnWindowFocus: false, | |
| } ); | |
| }; | |