Skip to content

Commit 13cb68e

Browse files
committed
Merge branch 'dev' of github.com:appbaseio/reactivesearch into dev
2 parents 186a9f3 + 4cc7dd9 commit 13cb68e

File tree

12 files changed

+143
-46
lines changed

12 files changed

+143
-46
lines changed

packages/web/src/components/basic/NumberBox.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface NumberBoxProps extends CommonProps {
88
defaultSelected?: number;
99
innerClass?: types.style;
1010
labelPosition?: types.labelPosition;
11+
nestedField?: string;
1112
queryFormat?: types.queryFormatNumberBox;
1213
react?: types.react;
1314
title?: types.title;

packages/web/src/components/basic/NumberBox.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import {
1111
checkValueChange,
1212
checkPropChange,
13+
checkSomePropChange,
1314
getClassName,
1415
} from '@appbaseio/reactivecore/lib/utils/helper';
1516
import types from '@appbaseio/reactivecore/lib/utils/types';
@@ -53,7 +54,7 @@ class NumberBox extends Component {
5354
checkPropChange(this.props.queryFormat, nextProps.queryFormat, () => {
5455
this.updateQuery(this.state.currentValue, nextProps);
5556
});
56-
checkPropChange(this.props.dataField, nextProps.dataField, () => {
57+
checkSomePropChange(this.props, nextProps, ['dataField', 'nestedField'], () => {
5758
this.updateQuery(this.state.currentValue, nextProps);
5859
});
5960
}
@@ -63,24 +64,27 @@ class NumberBox extends Component {
6364
}
6465

6566
static defaultQuery = (value, props) => {
67+
let query = null;
6668
switch (props.queryFormat) {
6769
case 'exact':
68-
return {
70+
query = {
6971
term: {
7072
[props.dataField]: value,
7173
},
7274
};
75+
break;
7376
case 'lte':
74-
return {
77+
query = {
7578
range: {
7679
[props.dataField]: {
7780
lte: value,
7881
boost: 2.0,
7982
},
8083
},
8184
};
85+
break;
8286
default:
83-
return {
87+
query = {
8488
range: {
8589
[props.dataField]: {
8690
gte: value,
@@ -89,6 +93,18 @@ class NumberBox extends Component {
8993
},
9094
};
9195
}
96+
97+
if (query && props.nestedField) {
98+
return {
99+
query: {
100+
nested: {
101+
path: props.nestedField,
102+
query,
103+
},
104+
},
105+
};
106+
}
107+
return query;
92108
};
93109

94110
setReact(props) {
@@ -202,6 +218,7 @@ NumberBox.propTypes = {
202218
defaultSelected: types.number,
203219
innerClass: types.style,
204220
labelPosition: types.labelPosition,
221+
nestedField: types.string,
205222
onQueryChange: types.func,
206223
queryFormat: types.queryFormatNumberBox,
207224
react: types.react,

packages/web/src/components/basic/TagCloud.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface TagCloudProps extends CommonProps {
1111
innerClass?: types.style;
1212
loader?: any;
1313
multiSelect?: boolean;
14+
nestedField?: string;
1415
onValueChange?: (...args: any[]) => any;
1516
queryFormat?: types.queryFormatSearch;
1617
react?: types.react;

packages/web/src/components/basic/TagCloud.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
2625
import TagList from '../../styles/TagList';
2726
import Container from '../../styles/Container';
2827
import { connect } from '../../utils';
28+
import { getAggsQuery } from '../list/utils';
2929

3030
class 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

333347
const mapDispatchtoProps = dispatch => ({
334348
addComponent: component => dispatch(addComponent(component)),

packages/web/src/components/basic/TextField.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface TextFieldProps extends CommonProps {
1818
onKeyPress?: (...args: any[]) => any;
1919
onKeyUp?: (...args: any[]) => any;
2020
onValueChange?: (...args: any[]) => any;
21+
nestedField?: string;
2122
placeholder?: string;
2223
react?: types.react;
2324
ref?: (...args: any[]) => any;

packages/web/src/components/basic/TextField.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
checkValueChange,
1313
checkPropChange,
1414
getClassName,
15+
checkSomePropChange,
1516
} from '@appbaseio/reactivecore/lib/utils/helper';
1617
import types from '@appbaseio/reactivecore/lib/utils/types';
1718

@@ -49,7 +50,7 @@ class TextField extends Component {
4950
this.setReact(nextProps);
5051
});
5152

52-
checkPropChange(this.props.dataField, nextProps.dataField, () => {
53+
checkSomePropChange(this.props, nextProps, ['dataField', 'nestedField'], () => {
5354
this.updateQuery(this.state.currentValue, nextProps);
5455
});
5556

@@ -78,14 +79,25 @@ class TextField extends Component {
7879
}
7980

8081
static defaultQuery = (value, props) => {
82+
let query = null;
8183
if (value && value.trim() !== '') {
82-
return {
84+
query = {
8385
match: {
8486
[props.dataField]: value,
8587
},
8688
};
8789
}
88-
return null;
90+
if (query && props.nestedField) {
91+
return {
92+
query: {
93+
nested: {
94+
path: props.nestedField,
95+
query,
96+
},
97+
},
98+
};
99+
}
100+
return query;
89101
};
90102

91103
handleTextChange = debounce((value) => {
@@ -149,8 +161,7 @@ class TextField extends Component {
149161

150162
renderIcons = () => (
151163
<div>
152-
{this.state.currentValue
153-
&& this.props.showClear && (
164+
{this.state.currentValue && this.props.showClear && (
154165
<InputIcon onClick={this.clearValue} iconPosition="right">
155166
{this.renderCancelIcon()}
156167
</InputIcon>

packages/web/src/components/basic/ToggleButton.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface ToggleButtonProps extends CommonProps {
88
defaultSelected?: types.stringOrArray;
99
filterLabel?: string;
1010
innerClass?: types.style;
11+
nestedField?: string;
1112
multiSelect?: boolean;
1213
react?: types.react;
1314
showFilter?: boolean;

packages/web/src/components/basic/ToggleButton.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
isEqual,
1212
checkValueChange,
1313
checkPropChange,
14+
checkSomePropChange,
1415
getClassName,
1516
} from '@appbaseio/reactivecore/lib/utils/helper';
1617
import types from '@appbaseio/reactivecore/lib/utils/types';
@@ -47,7 +48,7 @@ class ToggleButton extends Component {
4748
this.setReact(nextProps);
4849
});
4950

50-
checkPropChange(this.props.dataField, nextProps.dataField, () => {
51+
checkSomePropChange(this.props, nextProps, ['dataField', 'nestedField'], () => {
5152
this.updateQuery(this.state.currentValue, nextProps);
5253
});
5354

@@ -95,6 +96,18 @@ class ToggleButton extends Component {
9596
},
9697
};
9798
}
99+
100+
if (query && props.nestedField) {
101+
return {
102+
query: {
103+
nested: {
104+
path: props.nestedField,
105+
query,
106+
},
107+
},
108+
};
109+
}
110+
98111
return query;
99112
};
100113

@@ -181,7 +194,9 @@ class ToggleButton extends Component {
181194
</Title>
182195
)}
183196
{this.props.data.map((item) => {
184-
const isSelected = this.state.currentValue.some(value => value.value === item.value);
197+
const isSelected = this.state.currentValue.some(
198+
value => value.value === item.value,
199+
);
185200
return (
186201
<Button
187202
className={`${getClassName(this.props.innerClass, 'button')} ${
@@ -217,6 +232,7 @@ ToggleButton.propTypes = {
217232
filterLabel: types.string,
218233
innerClass: types.style,
219234
multiSelect: types.bool,
235+
nestedField: types.string,
220236
onQueryChange: types.func,
221237
react: types.react,
222238
showFilter: types.bool,

packages/web/src/components/list/MultiDataList.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface MultiDataList extends CommonProps {
1111
filterLabel?: string;
1212
innerClass?: types.style;
1313
onValueChange?: (...args: any[]) => any;
14+
nestedField?: string;
1415
placeholder?: string;
1516
queryFormat?: types.queryFormatSearch;
1617
react?: types.react;
@@ -20,7 +21,7 @@ export interface MultiDataList extends CommonProps {
2021
showSearch?: boolean;
2122
themePreset?: types.themePreset;
2223
title?: types.title;
23-
showCount?: boolean,
24+
showCount?: boolean;
2425
renderListItem?: (...args: any[]) => any;
2526
}
2627

0 commit comments

Comments
 (0)