Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan687 committed May 10, 2017
2 parents e25d554 + 20d96ed commit 7f3055c
Showing 10 changed files with 201 additions and 106 deletions.
14 changes: 11 additions & 3 deletions app/actuators/ResultCard.js
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ export default class ResultCard extends Component {

// check the height and set scroll if scroll not exists
componentDidUpdate() {
if (!this.state.showPlaceholder) {
if (!this.state.showPlaceholder && !this.props.scrollOnTarget) {
this.applyScroll();
}
}
@@ -593,7 +593,15 @@ export default class ResultCard extends Component {
};
helper.selectedSensor.set(obj, true, "sortChange");
}

getComponentStyle() {
let componentStyle = {};
if(this.props.scrollOnTarget) {
componentStyle.maxHeight = "none";
componentStyle.height = "auto";
}
componentStyle = Object.assign(componentStyle, this.props.componentStyle);
return componentStyle;
}
render() {
let title = null,
placeholder = null,
@@ -639,7 +647,7 @@ export default class ResultCard extends Component {

return (
<div className="rbc rbc-resultcard">
<div ref={(div) => { this.listParentElement = div }} className={`rbc-resultcard-container card thumbnail ${cx}`} style={this.props.componentStyle}>
<div ref={(div) => { this.listParentElement = div }} className={`rbc-resultcard-container card thumbnail ${cx}`} style={this.props.componentStyle} style={this.getComponentStyle()}>
{title}
{sortOptions}
{this.props.showResultStats && this.state.resultStats.resultFound ? (<ResultStats onResultStats={this.props.onResultStats} took={this.state.resultStats.took} total={this.state.resultStats.total} />) : null}
14 changes: 12 additions & 2 deletions app/actuators/ResultList.js
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ export default class ResultList extends Component {

// check the height and set scroll if scroll not exists
componentDidUpdate() {
if (!this.state.showPlaceholder) {
if (!this.state.showPlaceholder && !this.props.scrollOnTarget) {
this.applyScroll();
}
}
@@ -597,6 +597,16 @@ export default class ResultList extends Component {
helper.selectedSensor.set(obj, true, "sortChange");
}

getComponentStyle() {
let componentStyle = {};
if(this.props.scrollOnTarget) {
componentStyle.maxHeight = "none";
componentStyle.height = "auto";
}
componentStyle = Object.assign(componentStyle, this.props.componentStyle);
return componentStyle;
}

render() {
let title = null,
placeholder = null,
@@ -642,7 +652,7 @@ export default class ResultList extends Component {

return (
<div ref={(div) => { this.resultListContainer = div }} className="rbc rbc-resultlist">
<div ref={(div) => { this.listParentElement = div }} className={`rbc-resultlist-container card thumbnail ${cx}`} style={this.props.componentStyle}>
<div ref={(div) => { this.listParentElement = div }} className={`rbc-resultlist-container card thumbnail ${cx}`} style={this.getComponentStyle()}>
{title}
{sortOptions}
{this.props.showResultStats && this.state.resultStats.resultFound ? (<ResultStats onResultStats={this.props.onResultStats} took={this.state.resultStats.took} total={this.state.resultStats.total} />) : null}
17 changes: 11 additions & 6 deletions app/sensors/CategorySearch.js
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ export default class CategorySearch extends Component {
this.type = "match_phrase";
this.channelId = null;
this.channelListener = null;
this.urlParams = helper.URLParams.get(this.props.componentId);
this.fieldType = typeof props.appbaseField;
this.handleSearch = this.handleSearch.bind(this);
this.optionRenderer = this.optionRenderer.bind(this);
@@ -268,8 +269,9 @@ export default class CategorySearch extends Component {
}

checkDefault() {
if (this.props.defaultSelected && this.defaultSelected !== this.props.defaultSelected) {
this.defaultSelected = this.props.defaultSelected;
const defaultValue = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
if (defaultValue && this.defaultSelected !== defaultValue) {
this.defaultSelected = defaultValue;
setTimeout(this.setValue.bind(this, this.defaultSelected), 100);
this.handleSearch({
value: this.defaultSelected
@@ -297,7 +299,7 @@ export default class CategorySearch extends Component {
if(this.props.onValueChange) {
this.props.onValueChange(obj.value);
}

helper.URLParams.update(this.props.componentId, finalVal.value, this.props.URLParam);
helper.selectedSensor.set(obj, true);
this.setState({
currentValue: value
@@ -363,14 +365,16 @@ CategorySearch.propTypes = {
React.PropTypes.string,
React.PropTypes.arrayOf(React.PropTypes.string)
]),
componentStyle: React.PropTypes.object
componentStyle: React.PropTypes.object,
URLParam: React.PropTypes.bool
};

// Default props value
CategorySearch.defaultProps = {
placeholder: "Search",
highlight: false,
componentStyle: {}
componentStyle: {},
URLParam: false
};

// context type
@@ -388,5 +392,6 @@ CategorySearch.types = {
placeholder: TYPES.STRING,
defaultSelected: TYPES.STRING,
customQuery: TYPES.FUNCTION,
highlight: TYPES.BOOLEAN
highlight: TYPES.BOOLEAN,
URLParam: TYPES.BOOLEAN
};
109 changes: 75 additions & 34 deletions app/sensors/DynamicRangeSlider.js
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ export default class DynamicRangeSlider extends Component {
this.type = "range";
this.channelId = null;
this.channelListener = null;
this.urlParams = helper.URLParams.get(this.props.componentId, false, true);
this.handleValuesChange = this.handleValuesChange.bind(this);
this.handleResults = this.handleResults.bind(this);
this.customQuery = this.customQuery.bind(this);
@@ -47,7 +48,8 @@ export default class DynamicRangeSlider extends Component {
}

componentWillReceiveProps(nextProps) {
this.updateValues(nextProps.defaultSelected);
const defaultValue = this.urlParams !== null ? this.urlParams : nextProps.defaultSelected;
this.updateValues(defaultValue);
}

// stop streaming request and remove listener when component will unmount
@@ -85,23 +87,40 @@ export default class DynamicRangeSlider extends Component {
this.setRangeValue();
}

setRangeValue() {
setRangeValue(value="range") {
const objValue = {
key: `${this.props.componentId}-internal`,
value: this.state.range
value
};
helper.selectedSensor.set(objValue, true);
}

histogramQuery() {
return {
[this.props.appbaseField]: {
"histogram": {
"field": this.props.appbaseField,
"interval": this.props.interval
let query;
const isHistogramQuery = helper.selectedSensor.get(`${this.props.componentId}-internal`);
if(isHistogramQuery === "histogram") {
query = {
[this.props.appbaseField]: {
"histogram": {
"field": this.props.appbaseField,
"interval": this.props.interval ? this.props.interval : Math.ceil((this.state.range.max - this.state.range.min)/10)
}
}
}
};
};
} else {
query = {
"max": {
"max": {
"field": this.props.appbaseField,
}
}, "min": {
"min": {
"field": this.props.appbaseField,
}
}
};
}
return query;
}

// Create a channel which passes the react and receive results whenever react changes
@@ -131,18 +150,27 @@ export default class DynamicRangeSlider extends Component {
}
if (res.appliedQuery) {
const data = res.data;
let rawData;
if (res.mode === "streaming") {
rawData = this.state.rawData;
rawData.hits.hits.push(res.data);
} else if (res.mode === "historic") {
rawData = data;
if(data.aggregations.max && data.aggregations.min) {
this.setState({
range: {
min: data.aggregations.min.value,
max: data.aggregations.max.value
}
}, this.setRangeValue.bind(this, "histogram"));
} else {
let rawData;
if (res.mode === "streaming") {
rawData = this.state.rawData;
rawData.hits.hits.push(res.data);
} else if (res.mode === "historic") {
rawData = data;
}
this.setState({
queryStart: false,
rawData
});
this.setData(data);
}
this.setState({
queryStart: false,
rawData
});
this.setData(data);
}
});
this.listenLoadingChannel(channelObj);
@@ -216,27 +244,28 @@ export default class DynamicRangeSlider extends Component {
if (itemLength > 1) {
this.setState({
counts: this.countCalc(min, max, newItems),
range: { min, max },
values: { min, max }
}, () => {
this.handleResults(null, { min, max });
});
}
this.updateValues(this.props.defaultSelected);
const defaultValue = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
this.updateValues(defaultValue);
}

updateValues(defaultSelected) {
if (defaultSelected) {
const { min, max } = this.state.range;
const { start, end } = defaultSelected(min, max);
const { start, end } = this.urlParams !== null ? this.urlParams : defaultSelected(min, max);

if (start >= min && end <= max) {
const values = {
min: start,
max: end
};
this.setState({
values: {
min: start,
max: end
}
});
values
}, this.handleResults.bind(this, null, values));
} else {
console.error(`defaultSelected values must lie between ${min} and ${max}`);
}
@@ -272,14 +301,24 @@ export default class DynamicRangeSlider extends Component {
if(this.props.onValueChange) {
this.props.onValueChange(obj.value);
}

helper.URLParams.update(this.props.componentId, this.setURLParam(obj.value), this.props.URLParam);
helper.selectedSensor.set(obj, true);

this.setState({
values
});
}

setURLParam(value) {
if("from" in value && "to" in value) {
value = {
start: value.from,
end: value.to
};
}
return JSON.stringify(value);
}

render() {
let title = null,
histogram = null,
@@ -354,15 +393,16 @@ DynamicRangeSlider.propTypes = {
react: React.PropTypes.object,
onValueChange: React.PropTypes.func,
interval: React.PropTypes.number,
componentStyle: React.PropTypes.object
componentStyle: React.PropTypes.object,
URLParam: React.PropTypes.bool
};

DynamicRangeSlider.defaultProps = {
title: null,
stepValue: 1,
showHistogram: true,
interval: 1,
componentStyle: {}
componentStyle: {},
URLParam: false
};

// context type
@@ -381,5 +421,6 @@ DynamicRangeSlider.types = {
stepValue: TYPES.NUMBER,
showHistogram: TYPES.BOOLEAN,
customQuery: TYPES.FUNCTION,
initialLoader: TYPES.OBJECT
initialLoader: TYPES.OBJECT,
URLParam: TYPES.BOOLEAN
};
Loading

0 comments on commit 7f3055c

Please sign in to comment.