/** * Internal dependencies */ import PostTypeSelectorControl from '../post-type-selector-control'; import PostFormatsSelectorControl from '../post-formats-selector-control'; import CategoriesSelectorControl from '../categories-selector-control'; import TagsSelectorControl from '../tags-selector-control'; import PostsSelectorControl from '../posts-selector-control'; /** * WordPress dependencies */ const { __, } = wp.i18n; const { Component, Fragment, } = wp.element; const { TextControl, SelectControl, } = wp.components; /** * Component */ export default class ComponentQueryControl extends Component { constructor() { super( ...arguments ); this.updateValue = this.updateValue.bind( this ); } updateValue( newData ) { const { value, onChange, } = this.props; const result = { ...value, ...newData, }; // reset categories, tags and posts filters if post_type != 'post' if ( 'post' === value.post_type && 'post' !== result.post_type ) { result.categories = ''; result.tags = ''; result.posts = ''; } onChange( result ); } render() { const { value: { posts_type = 'post', categories = '', tags = '', exclude_categories = '', exclude_tags = '', formats = '', posts = '', offset = '', orderby = 'date', order = 'DESC', time_frame = '', taxonomy = '', terms = '', }, } = this.props; return ( { this.updateValue( { posts_type: val, } ); } } /> { 'post' === posts_type ? ( { this.updateValue( { categories: val, } ); } } /> { this.updateValue( { tags: val, } ); } } /> ) : '' } { 'post' === posts_type ? ( { this.updateValue( { exclude_categories: val, } ); } } /> { this.updateValue( { exclude_tags: val, } ); } } /> ) : '' } { this.updateValue( { formats: val, } ); } } /> { this.updateValue( { posts: val, } ); } } /> { this.updateValue( { offset: val, } ); } } /> { this.updateValue( { orderby: val, } ); } } /> { 'views' === orderby ? ( { this.updateValue( { time_frame: val, } ); } } /> ) : '' } { this.updateValue( { order: val, } ); } } /> { this.updateValue( { taxonomy: val, } ); } } /> { this.updateValue( { terms: val, } ); } } /> ); } }