@@ -11,22 +11,34 @@ import QueryJetpackModules from 'calypso/components/data/query-jetpack-modules';
11
11
import SectionNav from 'calypso/components/section-nav' ;
12
12
import NavItem from 'calypso/components/section-nav/item' ;
13
13
import NavTabs from 'calypso/components/section-nav/tabs' ;
14
+ import version_compare from 'calypso/lib/version-compare' ;
15
+ import { STATS_FEATURE_PAGE_TRAFFIC } from 'calypso/my-sites/stats/constants' ;
14
16
import useNoticeVisibilityMutation from 'calypso/my-sites/stats/hooks/use-notice-visibility-mutation' ;
15
17
import { useNoticeVisibilityQuery } from 'calypso/my-sites/stats/hooks/use-notice-visibility-query' ;
18
+ import { shouldGateStats } from 'calypso/my-sites/stats/hooks/use-should-gate-stats' ;
16
19
import { canCurrentUser } from 'calypso/state/selectors/can-current-user' ;
17
20
import isGoogleMyBusinessLocationConnectedSelector from 'calypso/state/selectors/is-google-my-business-location-connected' ;
18
21
import isJetpackModuleActive from 'calypso/state/selectors/is-jetpack-module-active' ;
19
22
import isSiteStore from 'calypso/state/selectors/is-site-store' ;
20
23
import siteHasFeature from 'calypso/state/selectors/site-has-feature' ;
21
- import { getSiteOption , isSimpleSite } from 'calypso/state/sites/selectors' ;
24
+ import {
25
+ getJetpackStatsAdminVersion ,
26
+ getSiteOption ,
27
+ isSimpleSite ,
28
+ } from 'calypso/state/sites/selectors' ;
22
29
import getSiteAdminUrl from 'calypso/state/sites/selectors/get-site-admin-url' ;
23
30
import {
24
31
updateModuleToggles ,
25
32
requestModuleToggles ,
26
33
} from 'calypso/state/stats/module-toggles/actions' ;
27
34
import { getModuleToggles } from 'calypso/state/stats/module-toggles/selectors' ;
28
- import { navItems as allNavItems , intervals as intervalConstants } from './constants' ;
35
+ import {
36
+ AVAILABLE_PAGE_MODULES ,
37
+ navItems as allNavItems ,
38
+ intervals as intervalConstants ,
39
+ } from './constants' ;
29
40
import Intervals from './intervals' ;
41
+ import PageModuleToggler from './page-module-toggler' ;
30
42
31
43
import './style.scss' ;
32
44
@@ -166,9 +178,26 @@ class StatsNavigation extends Component {
166
178
isLegacy : PropTypes . bool ,
167
179
adminUrl : PropTypes . string ,
168
180
showLock : PropTypes . bool ,
181
+ hideModuleSettings : PropTypes . bool ,
169
182
delayTooltipPresentation : PropTypes . bool ,
170
183
} ;
171
184
185
+ state = {
186
+ // Dismiss the tooltip before the API call is finished.
187
+ isPageSettingsTooltipDismissed : ! ! localStorage . getItem (
188
+ 'notices_dismissed__traffic_page_settings'
189
+ ) ,
190
+ } ;
191
+
192
+ onTooltipDismiss = ( ) => {
193
+ if ( this . state . isPageSettingsTooltipDismissed || ! this . props . showSettingsTooltip ) {
194
+ return ;
195
+ }
196
+ this . setState ( { isPageSettingsTooltipDismissed : true } ) ;
197
+ localStorage . setItem ( 'notices_dismissed__traffic_page_settings' , 1 ) ;
198
+ this . props . mutateNoticeVisbilityAsync ( ) . finally ( this . props . refetchNotices ) ;
199
+ } ;
200
+
172
201
isValidItem = ( item ) => {
173
202
const {
174
203
isGoogleMyBusinessLocationConnected,
@@ -216,15 +245,45 @@ class StatsNavigation extends Component {
216
245
}
217
246
218
247
render ( ) {
219
- const { slug, selectedItem, interval, isLegacy, showLock, siteId, adminUrl } = this . props ;
248
+ const {
249
+ slug,
250
+ selectedItem,
251
+ interval,
252
+ isLegacy,
253
+ showSettingsTooltip,
254
+ statsAdminVersion,
255
+ showLock,
256
+ hideModuleSettings,
257
+ delayTooltipPresentation,
258
+ gatedTrafficPage,
259
+ siteId,
260
+ isStatsNavigationImprovementEnabled,
261
+ pageModuleToggles,
262
+ adminUrl,
263
+ } = this . props ;
264
+ const { isPageSettingsTooltipDismissed } = this . state ;
220
265
const { path } = allNavItems [ selectedItem ] ;
221
266
const slugPath = slug ? `/${ slug } ` : '' ;
222
267
const pathTemplate = `${ path } /{{ interval }}${ slugPath } ` ;
223
268
224
- const wrapperClass = clsx ( 'stats-navigation' , 'stats-navigation--improved' , {
269
+ const wrapperClass = clsx ( 'stats-navigation' , {
225
270
'stats-navigation--modernized' : ! isLegacy ,
271
+ 'stats-navigation--improved' : isStatsNavigationImprovementEnabled ,
226
272
} ) ;
227
273
274
+ // Module settings for Odyssey are not supported until stats-admin@0.9.0-alpha.
275
+ const isModuleSettingsSupported =
276
+ ! config . isEnabled ( 'is_running_in_jetpack_site' ) ||
277
+ ! ! ( statsAdminVersion && version_compare ( statsAdminVersion , '0.9.0-alpha' , '>=' ) ) ;
278
+
279
+ const shouldRenderModuleToggler =
280
+ isModuleSettingsSupported &&
281
+ AVAILABLE_PAGE_MODULES [ this . props . selectedItem ] &&
282
+ ! hideModuleSettings &&
283
+ ! gatedTrafficPage ;
284
+
285
+ // @TODO : Add loading status of modules settings to avoid toggling modules before they are loaded.
286
+
228
287
/** @type {Array<keyof typeof allNavItems> } Array of valid navigation item keys */
229
288
const navKeys = Object . keys ( allNavItems ) ;
230
289
const navItems = navKeys . filter ( this . isValidItem ) . map ( ( key ) => {
@@ -250,22 +309,46 @@ class StatsNavigation extends Component {
250
309
return (
251
310
< div className = { wrapperClass } >
252
311
{ siteId && < QueryJetpackModules siteId = { siteId } /> }
253
- < ComponentSwapper
254
- className = "full-width"
255
- breakpoint = "<480px"
256
- breakpointActiveComponent = {
257
- < SelectNav
258
- navItems = { navItems }
259
- selectedItemName = { selectedItem }
260
- isLegacy = { isLegacy }
261
- interval = { interval }
262
- pathTemplate = { pathTemplate }
263
- />
264
- }
265
- breakpointInactiveComponent = {
266
- < TabNav tabs = { navItems } selectedTabName = { selectedItem } />
267
- }
268
- />
312
+ { isStatsNavigationImprovementEnabled && (
313
+ < ComponentSwapper
314
+ className = "full-width"
315
+ breakpoint = "<480px"
316
+ breakpointActiveComponent = {
317
+ < SelectNav
318
+ navItems = { navItems }
319
+ selectedItemName = { selectedItem }
320
+ isLegacy = { isLegacy }
321
+ interval = { interval }
322
+ pathTemplate = { pathTemplate }
323
+ />
324
+ }
325
+ breakpointInactiveComponent = {
326
+ < TabNav tabs = { navItems } selectedTabName = { selectedItem } />
327
+ }
328
+ />
329
+ ) }
330
+ { ! isStatsNavigationImprovementEnabled && (
331
+ // TODO: remove following SelectNav after 'stats/navigation-improvement' launch.
332
+ < SelectNav
333
+ navItems = { navItems }
334
+ selectedItemName = { selectedItem }
335
+ isLegacy = { isLegacy }
336
+ interval = { interval }
337
+ pathTemplate = { pathTemplate }
338
+ />
339
+ ) }
340
+
341
+ { ! isStatsNavigationImprovementEnabled && shouldRenderModuleToggler && (
342
+ < PageModuleToggler
343
+ siteId = { siteId }
344
+ selectedItem = { selectedItem }
345
+ moduleToggles = { pageModuleToggles }
346
+ isTooltipShown = {
347
+ showSettingsTooltip && ! isPageSettingsTooltipDismissed && ! delayTooltipPresentation
348
+ }
349
+ onTooltipDismiss = { this . onTooltipDismiss }
350
+ />
351
+ ) }
269
352
</ div >
270
353
) ;
271
354
}
@@ -306,8 +389,13 @@ export default connect(
306
389
isSubscriptionsModuleActive : isJetpackModuleActive ( state , siteId , 'subscriptions' , true ) ,
307
390
siteId,
308
391
pageModuleToggles : getModuleToggles ( state , siteId , [ selectedItem ] ) ,
392
+ statsAdminVersion : getJetpackStatsAdminVersion ( state , siteId ) ,
309
393
adminUrl : getSiteAdminUrl ( state , siteId ) ,
310
394
delayTooltipPresentation : shouldDelayTooltipPresentation ( state , siteId ) ,
395
+ gatedTrafficPage :
396
+ config . isEnabled ( 'stats/paid-wpcom-v3' ) &&
397
+ shouldGateStats ( state , siteId , STATS_FEATURE_PAGE_TRAFFIC ) ,
398
+ isStatsNavigationImprovementEnabled : config . isEnabled ( 'stats/navigation-improvement' ) ,
311
399
} ;
312
400
} ,
313
401
{ requestModuleToggles, updateModuleToggles }
0 commit comments