File size: 4,472 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | import { StatsCard } from '@automattic/components';
import { mapMarker } from '@wordpress/icons';
import { useTranslate } from 'i18n-calypso';
import React from 'react';
import QuerySiteStats from 'calypso/components/data/query-site-stats';
import InlineSupportLink from 'calypso/components/inline-support-link';
import StatsInfoArea from 'calypso/my-sites/stats/features/modules/shared/stats-info-area';
import { useShouldGateStats } from 'calypso/my-sites/stats/hooks/use-should-gate-stats';
import { useSelector } from 'calypso/state';
import { isJetpackSite } from 'calypso/state/sites/selectors';
import {
isRequestingSiteStatsForQuery,
getSiteStatsNormalizedData,
} from 'calypso/state/stats/lists/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import EmptyModuleCard from '../../../components/empty-module-card/empty-module-card';
import Geochart from '../../../geochart';
import StatsModule from '../../../stats-module';
import StatsCardSkeleton from '../shared/stats-card-skeleton';
import type { StatsDefaultModuleProps, StatsStateProps } from '../types';
import './style.scss';
const StatsCountries: React.FC< StatsDefaultModuleProps > = ( {
period,
query,
moduleStrings,
className,
summaryUrl,
summary,
listItemClassName,
isRealTime = false,
} ) => {
const translate = useTranslate();
const siteId = useSelector( getSelectedSiteId ) as number;
const statType = 'statsCountryViews';
const isSiteJetpackNotAtomic = useSelector( ( state ) =>
isJetpackSite( state, siteId, { treatAtomicAsJetpackSite: false } )
);
const supportContext = isSiteJetpackNotAtomic ? 'stats-countries-jetpack' : 'stats-countries';
// Use StatsModule to display paywall upsell.
const shouldGateStatsModule = useShouldGateStats( statType );
// TODO: Determine if data is being requested for real-time stats.
const isRequestingData =
useSelector( ( state: StatsStateProps ) =>
isRequestingSiteStatsForQuery( state, siteId, statType, query )
) && ! isRealTime;
const data = useSelector( ( state ) =>
getSiteStatsNormalizedData( state, siteId, statType, query )
) as [ id: number, label: string ];
return (
<>
{ ! shouldGateStatsModule && siteId && statType && (
<QuerySiteStats statType={ statType } siteId={ siteId } query={ query } />
) }
{ isRequestingData && (
<StatsCardSkeleton
isLoading={ isRequestingData }
className={ className }
title={ moduleStrings.title }
type={ 3 }
withHero
/>
) }
{ ( ( ! isRequestingData && !! data?.length ) || shouldGateStatsModule ) && (
// show data or an overlay
<StatsModule
path="countryviews"
titleNodes={
<StatsInfoArea>
{ translate( 'Stats on visitors and their {{link}}viewing location{{/link}}.', {
comment: '{{link}} links to support documentation.',
components: {
link: <InlineSupportLink supportContext={ supportContext } showIcon={ false } />,
},
context: 'Stats: Link in a popover for Countries module when the module has data',
} ) }
</StatsInfoArea>
}
moduleStrings={ moduleStrings }
period={ period }
query={ query }
statType={ statType }
showSummaryLink={ !! summary }
className={ className }
summary={ summary }
listItemClassName={ listItemClassName }
skipQuery
isRealTime={ isRealTime }
>
<Geochart query={ query } skipQuery isRealTime={ isRealTime } />
</StatsModule>
) }
{ ! isRequestingData && ! data?.length && ! shouldGateStatsModule && (
// show empty state
<StatsCard
className={ className }
title={ translate( 'Locations' ) }
isEmpty
emptyMessage={
<EmptyModuleCard
icon={ mapMarker }
description={ translate(
'Stats on visitors and their {{link}}viewing location{{/link}} will appear here to learn from where you are getting visits.',
{
comment: '{{link}} links to support documentation.',
components: {
link: (
<InlineSupportLink supportContext={ supportContext } showIcon={ false } />
),
},
context: 'Stats: Info box label when the Countries module is empty',
}
) }
/>
}
footerAction={
summaryUrl
? {
url: summaryUrl,
label: translate( 'View more' ),
}
: undefined
}
/>
) }
</>
);
};
export default StatsCountries;
|