File size: 843 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
import { itemLinkMatches } from 'calypso/my-sites/sidebar/utils';
import { A4A_SITES_LINK } from './constants';

type MenuItemProps = {
	id?: string;
	icon: JSX.Element;
	link: string;
	path: string;
	title: string;
	withChevron?: boolean;
	isExternalLink?: boolean;
	isSelected?: boolean;
	trackEventProps?: { [ key: string ]: string };
	extraContent?: JSX.Element;
};

export const createItem = ( props: MenuItemProps, path: string ) => {
	const linkMatches = props.link.startsWith( A4A_SITES_LINK )
		? props.link === path
		: itemLinkMatches( props.link, path );

	// Use props.isSelected if defined, otherwise fallback to the linkMatches condition
	const isSelected = typeof props.isSelected !== 'undefined' ? props.isSelected : linkMatches;

	return {
		...props,
		trackEventName: 'calypso_a4a_sidebar_menu_click',
		isSelected,
	};
};