import { recordTracksEvent } from '@automattic/calypso-analytics'; import config from '@automattic/calypso-config'; import { Popover } from '@automattic/components'; import { Button } from '@wordpress/components'; import { Icon, chevronDown, chevronUp, check } from '@wordpress/icons'; import clsx from 'clsx'; import { useState, useRef } from 'react'; import { OPTION_KEYS as SELECTED_OPTION_KEYS } from './stats-module-utm'; import './stats-module-utm-dropdown.scss'; interface UTMDropdownProps { className: string; buttonLabel: string; onSelect: ( key: string ) => void; selectOptions: Record< string, { selectLabel: string; isGrouped?: boolean } >; selected: keyof typeof SELECTED_OPTION_KEYS; } const BASE_CLASS_NAME = 'stats-utm-picker'; const UTMDropdown: React.FC< UTMDropdownProps > = ( { className, buttonLabel, onSelect, selectOptions, selected, // which option is indicated as selected } ) => { const isOdysseyStats = config.isEnabled( 'is_running_in_jetpack_site' ); const infoReferenceElement = useRef( null ); const [ popoverOpened, togglePopoverOpened ] = useState( false ); const togglePopoverVisibility = () => { const event_from = isOdysseyStats ? 'jetpack_odyssey' : 'calypso'; if ( ! popoverOpened ) { // record an event for opening the date picker recordTracksEvent( `${ event_from }_stats_utm_dropdown_opened` ); } togglePopoverOpened( ! popoverOpened ); }; const handleOptionSelection = ( key: string ) => { onSelect( key ); // publish an event const event_from = isOdysseyStats ? 'jetpack_odyssey' : 'calypso'; recordTracksEvent( `${ event_from }_stats_utm_dropdown_option_selected`, { option: key, } ); togglePopoverOpened( false ); }; return (
togglePopoverOpened( false ) } hideArrow >
); }; export default UTMDropdown;