2020-10-22 22:13:14 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
DropdownMenu,
|
|
|
|
MenuGroup,
|
|
|
|
MenuItemsChoice,
|
|
|
|
} from '@wordpress/components';
|
2020-11-06 17:53:03 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
2020-10-22 22:13:14 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-11-06 17:53:03 +00:00
|
|
|
import { useUserPreferences, OPTIONS_STORE_NAME } from '@woocommerce/data';
|
2020-10-22 22:13:14 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { DisplayIcon } from './icons/display';
|
|
|
|
import { SingleColumnIcon } from './icons/single-column';
|
|
|
|
import { TwoColumnsIcon } from './icons/two-columns';
|
|
|
|
|
|
|
|
const LAYOUTS = [
|
|
|
|
{
|
|
|
|
value: 'single_column',
|
|
|
|
label: (
|
|
|
|
<>
|
|
|
|
<SingleColumnIcon />
|
|
|
|
{ __( 'Single column', 'woocommerce-admin' ) }
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'two_columns',
|
|
|
|
label: (
|
|
|
|
<>
|
|
|
|
<TwoColumnsIcon />
|
|
|
|
{ __( 'Two columns', 'woocommerce-admin' ) }
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const DisplayOptions = () => {
|
2020-11-06 17:53:03 +00:00
|
|
|
const defaultHomescreenLayout = useSelect( ( select ) => {
|
|
|
|
const { getOption } = select( OPTIONS_STORE_NAME );
|
|
|
|
return (
|
|
|
|
getOption( 'woocommerce_default_homepage_layout' ) ||
|
|
|
|
'single_column'
|
|
|
|
);
|
|
|
|
} );
|
2020-10-22 22:13:14 +00:00
|
|
|
const {
|
|
|
|
updateUserPreferences,
|
|
|
|
homepage_layout: layout,
|
|
|
|
} = useUserPreferences();
|
|
|
|
return (
|
|
|
|
<DropdownMenu
|
|
|
|
icon={ <DisplayIcon /> }
|
|
|
|
/* translators: button label text should, if possible, be under 16 characters. */
|
|
|
|
label={ __( 'Display options', 'woocommerce-admin' ) }
|
|
|
|
toggleProps={ {
|
|
|
|
className:
|
|
|
|
'woocommerce-layout__activity-panel-tab display-options',
|
|
|
|
onClick: () => recordEvent( 'homescreen_display_click' ),
|
|
|
|
} }
|
|
|
|
popoverProps={ {
|
|
|
|
className: 'woocommerce-layout__activity-panel-popover',
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ () => (
|
|
|
|
<MenuGroup
|
|
|
|
className="woocommerce-layout__homescreen-display-options"
|
|
|
|
label={ __( 'Layout', 'woocommerce-admin' ) }
|
|
|
|
>
|
|
|
|
<MenuItemsChoice
|
|
|
|
choices={ LAYOUTS }
|
|
|
|
onSelect={ ( newLayout ) => {
|
|
|
|
updateUserPreferences( {
|
|
|
|
homepage_layout: newLayout,
|
|
|
|
} );
|
|
|
|
recordEvent( 'homescreen_display_option', {
|
|
|
|
display_option: newLayout,
|
|
|
|
} );
|
|
|
|
} }
|
2020-11-06 17:53:03 +00:00
|
|
|
value={ layout || defaultHomescreenLayout }
|
2020-10-22 22:13:14 +00:00
|
|
|
/>
|
|
|
|
</MenuGroup>
|
|
|
|
) }
|
|
|
|
</DropdownMenu>
|
|
|
|
);
|
|
|
|
};
|