Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan687 committed May 10, 2017
1 parent 7f3055c commit 6f96b3f
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 156 deletions.
2 changes: 1 addition & 1 deletion dist/css/style.min.css

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions lib/actuators/ResultCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var ResultCard = function (_Component) {
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
if (!this.state.showPlaceholder) {
if (!this.state.showPlaceholder && !this.props.scrollOnTarget) {
this.applyScroll();
}
}
Expand Down Expand Up @@ -702,6 +702,17 @@ var ResultCard = function (_Component) {
};
_reactivemaps.AppbaseSensorHelper.selectedSensor.set(obj, true, "sortChange");
}
}, {
key: "getComponentStyle",
value: function getComponentStyle() {
var componentStyle = {};
if (this.props.scrollOnTarget) {
componentStyle.maxHeight = "none";
componentStyle.height = "auto";
}
componentStyle = Object.assign(componentStyle, this.props.componentStyle);
return componentStyle;
}
}, {
key: "render",
value: function render() {
Expand Down Expand Up @@ -770,9 +781,9 @@ var ResultCard = function (_Component) {
{ className: "rbc rbc-resultcard" },
_react2.default.createElement(
"div",
{ ref: function ref(div) {
_defineProperty({ ref: function ref(div) {
_this9.listParentElement = div;
}, className: "rbc-resultcard-container card thumbnail " + cx, style: this.props.componentStyle },
}, className: "rbc-resultcard-container card thumbnail " + cx, style: this.props.componentStyle }, "style", this.getComponentStyle()),
title,
sortOptions,
this.props.showResultStats && this.state.resultStats.resultFound ? _react2.default.createElement(_reactivemaps.ResultStats, { onResultStats: this.props.onResultStats, took: this.state.resultStats.took, total: this.state.resultStats.total }) : null,
Expand Down
15 changes: 13 additions & 2 deletions lib/actuators/ResultList.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var ResultList = function (_Component) {
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
if (!this.state.showPlaceholder) {
if (!this.state.showPlaceholder && !this.props.scrollOnTarget) {
this.applyScroll();
}
}
Expand Down Expand Up @@ -707,6 +707,17 @@ var ResultList = function (_Component) {
};
_reactivemaps.AppbaseSensorHelper.selectedSensor.set(obj, true, "sortChange");
}
}, {
key: "getComponentStyle",
value: function getComponentStyle() {
var componentStyle = {};
if (this.props.scrollOnTarget) {
componentStyle.maxHeight = "none";
componentStyle.height = "auto";
}
componentStyle = Object.assign(componentStyle, this.props.componentStyle);
return componentStyle;
}
}, {
key: "render",
value: function render() {
Expand Down Expand Up @@ -779,7 +790,7 @@ var ResultList = function (_Component) {
"div",
{ ref: function ref(div) {
_this9.listParentElement = div;
}, className: "rbc-resultlist-container card thumbnail " + cx, style: this.props.componentStyle },
}, className: "rbc-resultlist-container card thumbnail " + cx, style: this.getComponentStyle() },
title,
sortOptions,
this.props.showResultStats && this.state.resultStats.resultFound ? _react2.default.createElement(_reactivemaps.ResultStats, { onResultStats: this.props.onResultStats, took: this.state.resultStats.took, total: this.state.resultStats.total }) : null,
Expand Down
17 changes: 11 additions & 6 deletions lib/sensors/CategorySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var CategorySearch = function (_Component) {
_this.type = "match_phrase";
_this.channelId = null;
_this.channelListener = null;
_this.urlParams = _reactivemaps.AppbaseSensorHelper.URLParams.get(_this.props.componentId);
_this.fieldType = _typeof(props.appbaseField);
_this.handleSearch = _this.handleSearch.bind(_this);
_this.optionRenderer = _this.optionRenderer.bind(_this);
Expand Down Expand Up @@ -338,8 +339,9 @@ var CategorySearch = function (_Component) {
}, {
key: "checkDefault",
value: function checkDefault() {
if (this.props.defaultSelected && this.defaultSelected !== this.props.defaultSelected) {
this.defaultSelected = this.props.defaultSelected;
var 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
Expand Down Expand Up @@ -370,7 +372,7 @@ var CategorySearch = function (_Component) {
if (this.props.onValueChange) {
this.props.onValueChange(obj.value);
}

_reactivemaps.AppbaseSensorHelper.URLParams.update(this.props.componentId, finalVal.value, this.props.URLParam);
_reactivemaps.AppbaseSensorHelper.selectedSensor.set(obj, true);
this.setState({
currentValue: value
Expand Down Expand Up @@ -442,14 +444,16 @@ CategorySearch.propTypes = {
onValueChange: _react2.default.PropTypes.func,
highlight: _react2.default.PropTypes.bool,
highlightFields: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.string, _react2.default.PropTypes.arrayOf(_react2.default.PropTypes.string)]),
componentStyle: _react2.default.PropTypes.object
componentStyle: _react2.default.PropTypes.object,
URLParam: _react2.default.PropTypes.bool
};

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

// context type
Expand All @@ -467,5 +471,6 @@ CategorySearch.types = {
placeholder: _reactivemaps.TYPES.STRING,
defaultSelected: _reactivemaps.TYPES.STRING,
customQuery: _reactivemaps.TYPES.FUNCTION,
highlight: _reactivemaps.TYPES.BOOLEAN
highlight: _reactivemaps.TYPES.BOOLEAN,
URLParam: _reactivemaps.TYPES.BOOLEAN
};
112 changes: 78 additions & 34 deletions lib/sensors/DynamicRangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var DynamicRangeSlider = function (_Component) {
_this.type = "range";
_this.channelId = null;
_this.channelListener = null;
_this.urlParams = _reactivemaps.AppbaseSensorHelper.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);
Expand All @@ -83,7 +84,8 @@ var DynamicRangeSlider = function (_Component) {
}, {
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
this.updateValues(nextProps.defaultSelected);
var defaultValue = this.urlParams !== null ? this.urlParams : nextProps.defaultSelected;
this.updateValues(defaultValue);
}

// stop streaming request and remove listener when component will unmount
Expand Down Expand Up @@ -129,21 +131,40 @@ var DynamicRangeSlider = function (_Component) {
}, {
key: "setRangeValue",
value: function setRangeValue() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "range";

var objValue = {
key: this.props.componentId + "-internal",
value: this.state.range
value: value
};
_reactivemaps.AppbaseSensorHelper.selectedSensor.set(objValue, true);
}
}, {
key: "histogramQuery",
value: function histogramQuery() {
return _defineProperty({}, this.props.appbaseField, {
"histogram": {
"field": this.props.appbaseField,
"interval": this.props.interval
}
});
var query = void 0;
var isHistogramQuery = _reactivemaps.AppbaseSensorHelper.selectedSensor.get(this.props.componentId + "-internal");
if (isHistogramQuery === "histogram") {
query = _defineProperty({}, 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
Expand Down Expand Up @@ -178,18 +199,27 @@ var DynamicRangeSlider = function (_Component) {
}
if (res.appliedQuery) {
var data = res.data;
var rawData = void 0;
if (res.mode === "streaming") {
rawData = _this2.state.rawData;
rawData.hits.hits.push(res.data);
} else if (res.mode === "historic") {
rawData = data;
if (data.aggregations.max && data.aggregations.min) {
_this2.setState({
range: {
min: data.aggregations.min.value,
max: data.aggregations.max.value
}
}, _this2.setRangeValue.bind(_this2, "histogram"));
} else {
var rawData = void 0;
if (res.mode === "streaming") {
rawData = _this2.state.rawData;
rawData.hits.hits.push(res.data);
} else if (res.mode === "historic") {
rawData = data;
}
_this2.setState({
queryStart: false,
rawData: rawData
});
_this2.setData(data);
}
_this2.setState({
queryStart: false,
rawData: rawData
});
_this2.setData(data);
}
});
this.listenLoadingChannel(channelObj);
Expand Down Expand Up @@ -277,13 +307,13 @@ var DynamicRangeSlider = function (_Component) {
if (itemLength > 1) {
this.setState({
counts: this.countCalc(min, max, newItems),
range: { min: min, max: max },
values: { min: min, max: max }
}, function () {
_this4.handleResults(null, { min: min, max: max });
});
}
this.updateValues(this.props.defaultSelected);
var defaultValue = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
this.updateValues(defaultValue);
}
}, {
key: "updateValues",
Expand All @@ -293,19 +323,20 @@ var DynamicRangeSlider = function (_Component) {
var min = _state$range.min;
var max = _state$range.max;

var _defaultSelected = defaultSelected(min, max);
var _ref = this.urlParams !== null ? this.urlParams : defaultSelected(min, max);

var start = _defaultSelected.start;
var end = _defaultSelected.end;
var start = _ref.start;
var end = _ref.end;


if (start >= min && end <= max) {
var values = {
min: start,
max: end
};
this.setState({
values: {
min: start,
max: end
}
});
values: values
}, this.handleResults.bind(this, null, values));
} else {
console.error("defaultSelected values must lie between " + min + " and " + max);
}
Expand Down Expand Up @@ -344,13 +375,24 @@ var DynamicRangeSlider = function (_Component) {
if (this.props.onValueChange) {
this.props.onValueChange(obj.value);
}

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

this.setState({
values: values
});
}
}, {
key: "setURLParam",
value: function setURLParam(value) {
if ("from" in value && "to" in value) {
value = {
start: value.from,
end: value.to
};
}
return JSON.stringify(value);
}
}, {
key: "render",
value: function render() {
Expand Down Expand Up @@ -435,15 +477,16 @@ DynamicRangeSlider.propTypes = {
react: _react2.default.PropTypes.object,
onValueChange: _react2.default.PropTypes.func,
interval: _react2.default.PropTypes.number,
componentStyle: _react2.default.PropTypes.object
componentStyle: _react2.default.PropTypes.object,
URLParam: _react2.default.PropTypes.bool
};

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

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

0 comments on commit 6f96b3f

Please sign in to comment.