-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4938f3
commit 7efded2
Showing
9 changed files
with
354 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.rbc.rbc-ratingsfilter { | ||
padding: 0; | ||
margin: 0; | ||
|
||
.row { | ||
margin: 4px 0; | ||
} | ||
|
||
.rbc-label { | ||
cursor: pointer; | ||
|
||
& > div { | ||
display: inline-block; | ||
} | ||
|
||
& > span { | ||
display: inline-block; | ||
margin-left: 8px; | ||
position: relative; | ||
top: -5px; | ||
} | ||
|
||
&:hover { | ||
color: #424242; | ||
} | ||
|
||
&.active { | ||
font-family: $font-bold; | ||
color: #333; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import React, { Component } from "react"; | ||
import classNames from "classnames"; | ||
import { | ||
TYPES, | ||
AppbaseSensorHelper as helper | ||
} from "@appbaseio/reactivebase"; | ||
import ReactStars from "react-stars"; | ||
|
||
export default class RatingsFilter extends Component { | ||
constructor(props, context) { | ||
super(props); | ||
this.state = { | ||
selected: null | ||
}; | ||
this.type = "range"; | ||
this.defaultSelected = this.props.defaultSelected; | ||
this.handleChange = this.handleChange.bind(this); | ||
this.customQuery = this.customQuery.bind(this); | ||
} | ||
|
||
// Set query information | ||
componentDidMount() { | ||
this.setQueryInfo(); | ||
if (this.defaultSelected && this.defaultSelected.start) { | ||
const records = this.props.data.filter(record => record.start === this.defaultSelected.start); | ||
if (records && records.length) { | ||
setTimeout(this.handleChange.bind(this, records[0]), 300); | ||
} | ||
} | ||
} | ||
|
||
componentWillUpdate() { | ||
setTimeout(() => { | ||
if (this.defaultSelected && this.defaultSelected.start !== this.props.defaultSelected.start) { | ||
this.defaultSelected = this.props.defaultSelected; | ||
const records = this.props.data.filter(record => record.start === this.defaultSelected.start); | ||
if (records && records.length) { | ||
setTimeout(this.handleChange.bind(this, records[0]), 300); | ||
} | ||
} | ||
}, 300); | ||
} | ||
|
||
// set the query type and input data | ||
setQueryInfo() { | ||
const obj = { | ||
key: this.props.componentId, | ||
value: { | ||
queryType: this.type, | ||
inputData: this.props.appbaseField, | ||
customQuery: this.props.customQuery ? this.props.customQuery : this.customQuery | ||
} | ||
}; | ||
helper.selectedSensor.setSensorInfo(obj); | ||
} | ||
|
||
// build query for this sensor only | ||
customQuery(record) { | ||
if (record) { | ||
return { | ||
range: { | ||
[this.props.appbaseField]: { | ||
gte: record.start, | ||
lte: record.end, | ||
boost: 2.0 | ||
} | ||
} | ||
}; | ||
} | ||
return null; | ||
} | ||
|
||
// handle the input change and pass the value inside sensor info | ||
handleChange(record) { | ||
this.setState({ | ||
selected: record | ||
}); | ||
const obj = { | ||
key: this.props.componentId, | ||
value: record | ||
}; | ||
// pass the selected sensor value with componentId as key, | ||
const isExecuteQuery = true; | ||
helper.selectedSensor.set(obj, isExecuteQuery); | ||
} | ||
|
||
renderButtons() { | ||
let buttons; | ||
const selectedItem = this.state.selected && this.state.selected.start ? this.state.selected.start : this.props.data.start; | ||
if (this.props.data) { | ||
buttons = this.props.data.map((record) => { | ||
const cx = selectedItem === record.start ? "active" : ""; | ||
return ( | ||
<div className="rbc-list-item row" key={record.label} onClick={() => this.handleChange(record)}> | ||
<label className={`rbc-label ${cx}`}> | ||
<ReactStars | ||
count={5} | ||
value={record.start} | ||
size={20} | ||
color1={"#bbb"} | ||
edit={false} | ||
color2={"#ffd700"} | ||
/> | ||
<span>{record.label}</span> | ||
</label> | ||
</div> | ||
); | ||
}); | ||
} | ||
return buttons; | ||
} | ||
|
||
// render | ||
render() { | ||
let title = null; | ||
if (this.props.title) { | ||
title = (<h4 className="rbc-title col s12 col-xs-12">{this.props.title}</h4>); | ||
} | ||
|
||
const cx = classNames({ | ||
"rbc-title-active": this.props.title, | ||
"rbc-title-inactive": !this.props.title | ||
}); | ||
|
||
return ( | ||
<div className={`rbc rbc-ratingsfilter col s12 col-xs-12 card thumbnail ${cx}`}> | ||
<div className="row"> | ||
{title} | ||
<div className="col s12 col-xs-12 rbc-list-container"> | ||
{this.renderButtons()} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
RatingsFilter.propTypes = { | ||
componentId: React.PropTypes.string.isRequired, | ||
appbaseField: React.PropTypes.string.isRequired, | ||
title: React.PropTypes.string, | ||
data: React.PropTypes.any.isRequired, | ||
defaultSelected: React.PropTypes.string, | ||
customQuery: React.PropTypes.func | ||
}; | ||
|
||
// Default props value | ||
RatingsFilter.defaultProps = { | ||
title: null | ||
}; | ||
|
||
// context type | ||
RatingsFilter.contextTypes = { | ||
appbaseRef: React.PropTypes.any.isRequired, | ||
type: React.PropTypes.any.isRequired | ||
}; | ||
|
||
RatingsFilter.types = { | ||
componentId: TYPES.STRING, | ||
appbaseField: TYPES.STRING, | ||
title: TYPES.STRING, | ||
data: TYPES.OBJECT, | ||
defaultSelected: TYPES.STRING, | ||
customQuery: TYPES.FUNCTION | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import React, { Component } from "react"; | ||
import { ReactiveBase, RatingsFilter, ReactiveList, AppbaseSensorHelper as helper } from "../app"; | ||
|
||
require("./list.css"); | ||
|
||
export default class RatingsFilterDefault extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.onData = this.onData.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
helper.ResponsiveStory(); | ||
} | ||
|
||
onData(res) { | ||
let result = null; | ||
if (res) { | ||
let combineData = res.currentData; | ||
if (res.mode === "historic") { | ||
combineData = res.currentData.concat(res.newData); | ||
} else if (res.mode === "streaming") { | ||
combineData = helper.combineStreamData(res.currentData, res.newData); | ||
} | ||
if (combineData) { | ||
result = combineData.map((markerData) => { | ||
const marker = markerData._source; | ||
return this.itemMarkup(marker, markerData); | ||
}); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
itemMarkup(marker, markerData) { | ||
return ( | ||
<a | ||
className="full_row single-record single_record_for_clone" | ||
key={markerData._id} | ||
> | ||
<div className="text-container full_row" style={{ paddingLeft: "10px" }}> | ||
<div className="text-head text-overflow full_row"> | ||
<span className="text-head-info text-overflow"> | ||
{marker.name ? marker.name : ""} - {marker.brand ? marker.brand : ""} | ||
</span> | ||
<span className="text-head-city">{marker.brand ? marker.brand : ""}</span> | ||
</div> | ||
<div className="text-description text-overflow full_row"> | ||
<ul className="highlight_tags"> | ||
{marker.price ? `Priced at $${marker.price}` : "Free Test Drive"} | ||
{`Rated ${marker.rating}`} | ||
</ul> | ||
</div> | ||
</div> | ||
</a> | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<ReactiveBase | ||
app="car-store" | ||
username="cf7QByt5e" | ||
password="d2d60548-82a9-43cc-8b40-93cbbe75c34c" | ||
> | ||
<div className="row"> | ||
<div className="col s6 col-xs-6"> | ||
<RatingsFilter | ||
componentId="RatingsSensor" | ||
appbaseField={this.props.mapping.rating} | ||
title="RatingsFilter" | ||
data={ | ||
[{ start: 4, end: 5, label: "4 stars and up" }, | ||
{ start: 3, end: 5, label: "3 stars and up" }, | ||
{ start: 2, end: 5, label: "2 stars and up" }, | ||
{ start: 1, end: 5, label: "> 1 stars" }] | ||
} | ||
{...this.props} | ||
/> | ||
</div> | ||
|
||
<div className="col s6 col-xs-6"> | ||
<ReactiveList | ||
componentId="SearchResult" | ||
appbaseField={this.props.mapping.name} | ||
title="Results" | ||
from={0} | ||
size={20} | ||
onData={this.onData} | ||
react={{ | ||
and: "RatingsSensor" | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</ReactiveBase> | ||
); | ||
} | ||
} | ||
|
||
RatingsFilterDefault.defaultProps = { | ||
mapping: { | ||
rating: "rating", | ||
name: "name" | ||
} | ||
}; | ||
|
||
RatingsFilterDefault.propTypes = { | ||
mapping: React.PropTypes.shape({ | ||
rating: React.PropTypes.number, | ||
name: React.PropTypes.string | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.