-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathnav-tabs.tsx
More file actions
63 lines (57 loc) · 1.8 KB
/
Copy pathnav-tabs.tsx
File metadata and controls
63 lines (57 loc) · 1.8 KB
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
import page from '@automattic/calypso-router';
import { TabPanel } from '@wordpress/components';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import {
getPathWithUpdatedQueryString,
trackStatsAnalyticsEvent,
} from 'calypso/my-sites/stats/utils';
import getEnvStatsFeatureSupportChecks from 'calypso/state/sites/selectors/get-env-stats-feature-supports';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import useOptionLabels, {
MAIN_STAT_TYPE,
StatsModulePostsProps,
getValidQueryViewType,
} from './use-option-labels';
function NavTabs( { query }: StatsModulePostsProps ) {
const siteId = useSelector( getSelectedSiteId );
const { supportsArchiveStats } = useSelector( ( state: object ) =>
getEnvStatsFeatureSupportChecks( state, siteId )
);
const optionLabels = useOptionLabels();
const tabPanelTabs = useMemo( () => {
return Object.entries( optionLabels ).map( ( [ key, item ] ) => {
return {
name: key,
title: item.tabLabel,
className: `stats-navigation__${ key }`,
path: getPathWithUpdatedQueryString( {
viewType: key,
} ),
analyticsId: item.analyticsId,
};
} );
}, [ optionLabels ] );
const selectedTab =
getValidQueryViewType( query.viewType, supportsArchiveStats ) || MAIN_STAT_TYPE;
return (
<TabPanel
className="stats-navigation__tabs"
tabs={ tabPanelTabs }
initialTabName={ selectedTab }
onSelect={ ( tabName ) => {
const tab = tabPanelTabs.find( ( tab ) => tab.name === tabName );
if ( tab?.path ) {
trackStatsAnalyticsEvent( 'stats_posts_module_menu_clicked', {
stat_type: tab.analyticsId,
blog_id: siteId,
} );
page( tab.path );
}
} }
>
{ () => null /* Placeholder div since content is rendered elsewhere */ }
</TabPanel>
);
}
export default NavTabs;