Skip to content

Commit 387445a

Browse files
committed
Add onQueryChange for PlacesSearch and resolves #72
1 parent 8423cd9 commit 387445a

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

app/sensors/PlacesSearch.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default class PlacesSearch extends Component {
3737
}
3838

3939
componentWillMount() {
40+
this.previousQuery = null; // initial value for onQueryChange
4041
this.googleMaps = window.google.maps;
4142
this.setQueryInfo();
4243
this.getUserLocation(this.setDefaultLocation);
@@ -122,12 +123,20 @@ export default class PlacesSearch extends Component {
122123

123124
// set the query type and input data
124125
setQueryInfo() {
126+
const getQuery = (value) => {
127+
const currentQuery = this.props.customQuery ? this.props.customQuery(value) : this.customQuery(value);
128+
if (this.props.onQueryChange && JSON.stringify(this.previousQuery) !== JSON.stringify(currentQuery)) {
129+
this.props.onQueryChange(this.previousQuery, currentQuery);
130+
}
131+
this.previousQuery = currentQuery;
132+
return currentQuery;
133+
};
125134
const obj = {
126135
key: this.props.componentId,
127136
value: {
128137
queryType: this.type,
129138
inputData: this.props.dataField,
130-
customQuery: this.props.customQuery ? this.props.customQuery : this.customQuery,
139+
customQuery: getQuery,
131140
reactiveId: this.context.reactiveId,
132141
showFilter: this.props.showFilter,
133142
filterLabel: this.props.filterLabel ? this.props.filterLabel : this.props.componentId,
@@ -361,7 +370,8 @@ PlacesSearch.propTypes = {
361370
showFilter: React.PropTypes.bool,
362371
filterLabel: React.PropTypes.string,
363372
unit: React.PropTypes.oneOf(["mi", "miles", "yd", "yards", "ft", "feet", "in", "inch", "km", "kilometers", "m", "meters", "cm", "centimeters", "mm", "millimeters", "NM", "nmi", "nauticalmiles"]),
364-
className: React.PropTypes.string
373+
className: React.PropTypes.string,
374+
onQueryChange: React.PropTypes.func
365375
};
366376
// Default props value
367377
PlacesSearch.defaultProps = {
@@ -392,5 +402,6 @@ PlacesSearch.types = {
392402
URLParams: TYPES.BOOLEAN,
393403
showFilter: TYPES.BOOLEAN,
394404
filterLabel: TYPES.STRING,
395-
className: TYPES.STRING
405+
className: TYPES.STRING,
406+
onQueryChange: TYPES.FUNCTION
396407
};

0 commit comments

Comments
 (0)