);
}
}
/**
* A list of all available ways to display products.
*/
class ProductsBlockSettingsEditorDisplayOptions extends React.Component {
/**
* Constructor.
*/
constructor( props ) {
super( props );
this.setWrapperRef = this.setWrapperRef.bind( this );
this.handleClickOutside = this.handleClickOutside.bind( this );
}
/**
* Hook in the listener for closing menu when clicked outside.
*/
componentDidMount() {
if ( this.props.existing ) {
document.addEventListener( 'mousedown', this.handleClickOutside );
}
}
/**
* Remove the listener for closing menu when clicked outside.
*/
componentWillUnmount() {
if ( this.props.existing ) {
document.removeEventListener( 'mousedown', this.handleClickOutside );
}
}
/**
* Set the wrapper reference.
*
* @param node DOMNode
*/
setWrapperRef( node ) {
this.wrapperRef = node;
}
/**
* Close the menu when user clicks outside the search area.
*/
handleClickOutside( evt ) {
if ( this.wrapperRef && ! this.wrapperRef.contains( event.target ) && 'wc-products-settings-heading__change-button button-link' !== event.target.getAttribute( 'class' ) ) {
this.props.closeMenu();
}
}
/**
* Render the list of options.
*/
render() {
let classes = 'wc-products-display-options';
if ( this.props.extended ) {
classes += ' wc-products-display-options--extended';
}
if ( this.props.existing ) {
classes += ' wc-products-display-options--popover';
}
let display_settings = [];
for ( var setting_key in PRODUCTS_BLOCK_DISPLAY_SETTINGS ) {
display_settings.push( );
}
let arrow = ;
let description =
{ __( 'Choose which products you\'d like to display:' ) }
);
}
}
/**
* The products block when in Edit mode.
*/
class ProductsBlockSettingsEditor extends React.Component {
/**
* Constructor.
*/
constructor( props ) {
super( props );
this.state = {
display: props.selected_display,
menu_visible: props.selected_display ? false : true,
expanded_group: '',
}
this.updateDisplay = this.updateDisplay.bind( this );
this.closeMenu = this.closeMenu.bind( this );
}
/**
* Update the display settings for the block.
*
* @param value String
*/
updateDisplay( value ) {
// If not a group update display.
let new_state = {
display: value,
menu_visible: false,
expanded_group: '',
};
const is_group = 'undefined' !== PRODUCTS_BLOCK_DISPLAY_SETTINGS[ value ].group_container && PRODUCTS_BLOCK_DISPLAY_SETTINGS[ value ].group_container;
if ( is_group ) {
// If the group has not been expanded, expand it.
new_state = {
menu_visible: true,
expanded_group: value,
}
// If the group has already been expanded, collapse it.
if ( this.state.expanded_group === PRODUCTS_BLOCK_DISPLAY_SETTINGS[ value ].group_container ) {
new_state.expanded_group = '';
}
}
this.setState( new_state );
// Only update the display setting if a non-group setting was selected.
if ( ! is_group ) {
this.props.update_display_callback( value );
}
}
closeMenu() {
this.setState( {
menu_visible: false
} );
}
/**
* Render the display settings dropdown and any extra contextual settings.
*/
render() {
let extra_settings = null;
if ( 'specific' === this.state.display ) {
extra_settings = ;
} else if ( 'category' === this.state.display ) {
extra_settings = ;
} else if ( 'attribute' === this.state.display ) {
extra_settings =
}
const menu = this.state.menu_visible ? : null;
let heading = null;
if ( this.state.display ) {
let menu_link = ;
heading = (