@@ -13,7 +13,6 @@ import {
1313 getQueryOptions ,
1414 pushToAndClause ,
1515 checkValueChange ,
16- getAggsOrder ,
1716 checkPropChange ,
1817 checkSomePropChange ,
1918 getClassName ,
@@ -26,6 +25,7 @@ import Title from '../../styles/Title';
2625import TagList from '../../styles/TagList' ;
2726import Container from '../../styles/Container' ;
2827import { connect } from '../../utils' ;
28+ import { getAggsQuery } from '../list/utils' ;
2929
3030class TagCloud extends Component {
3131 constructor ( props ) {
@@ -68,9 +68,10 @@ class TagCloud extends Component {
6868 } ) ;
6969 } ) ;
7070 checkSomePropChange ( this . props , nextProps , [ 'size' , 'sortBy' ] , ( ) =>
71- this . updateQueryOptions ( nextProps ) ) ;
71+ this . updateQueryOptions ( nextProps ) ,
72+ ) ;
7273
73- checkPropChange ( this . props . dataField , nextProps . dataField , ( ) => {
74+ checkSomePropChange ( this . props , nextProps , [ ' dataField' , 'nestedField' ] , ( ) => {
7475 this . updateQueryOptions ( nextProps ) ;
7576 this . updateQuery ( Object . keys ( this . state . currentValue ) , nextProps ) ;
7677 } ) ;
@@ -133,6 +134,17 @@ class TagCloud extends Component {
133134
134135 query = value . length ? listQuery : null ;
135136 }
137+
138+ if ( query && props . nestedField ) {
139+ return {
140+ query : {
141+ nested : {
142+ path : props . nestedField ,
143+ query,
144+ } ,
145+ } ,
146+ } ;
147+ }
136148 return query ;
137149 } ;
138150
@@ -204,17 +216,8 @@ class TagCloud extends Component {
204216 static generateQueryOptions ( props ) {
205217 const queryOptions = getQueryOptions ( props ) ;
206218 queryOptions . size = 0 ;
207- queryOptions . aggs = {
208- [ props . dataField ] : {
209- terms : {
210- field : props . dataField ,
211- size : props . size ,
212- order : getAggsOrder ( props . sortBy || 'asc' ) ,
213- } ,
214- } ,
215- } ;
216219
217- return queryOptions ;
220+ return getAggsQuery ( queryOptions , props ) ;
218221 }
219222
220223 updateQueryOptions = ( props ) => {
@@ -248,7 +251,7 @@ class TagCloud extends Component {
248251 ) }
249252 < TagList className = { getClassName ( this . props . innerClass , 'list' ) || null } >
250253 { this . state . options . map ( ( item ) => {
251- const size = ( ( item . doc_count / highestCount ) * ( max - min ) ) + min ;
254+ const size = ( item . doc_count / highestCount ) * ( max - min ) + min ; // eslint-disable-line
252255
253256 return (
254257 < span
@@ -297,6 +300,7 @@ TagCloud.propTypes = {
297300 isLoading : types . bool ,
298301 loader : types . title ,
299302 multiSelect : types . bool ,
303+ nestedField : types . string ,
300304 onQueryChange : types . func ,
301305 onValueChange : types . func ,
302306 queryFormat : types . queryFormatSearch ,
@@ -321,14 +325,24 @@ TagCloud.defaultProps = {
321325 URLParams : false ,
322326} ;
323327
324- const mapStateToProps = ( state , props ) => ( {
325- options : state . aggregations [ props . componentId ] ,
326- selectedValue :
327- ( state . selectedValues [ props . componentId ]
328- && state . selectedValues [ props . componentId ] . value )
329- || null ,
330- isLoading : state . isLoading [ props . componentId ] ,
331- } ) ;
328+ const mapStateToProps = ( state , props ) => {
329+ let options = { } ;
330+ if ( props . nestedField ) {
331+ options
332+ = state . aggregations [ props . componentId ]
333+ && state . aggregations [ props . componentId ] . reactivesearch_nested ;
334+ } else {
335+ options = state . aggregations [ props . componentId ] ;
336+ }
337+ return {
338+ options,
339+ selectedValue :
340+ ( state . selectedValues [ props . componentId ]
341+ && state . selectedValues [ props . componentId ] . value )
342+ || null ,
343+ isLoading : state . isLoading [ props . componentId ] ,
344+ } ;
345+ } ;
332346
333347const mapDispatchtoProps = dispatch => ( {
334348 addComponent : component => dispatch ( addComponent ( component ) ) ,
0 commit comments