Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added search filter to data points category #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions opendatavisualization/src/components/MapContainer/dataPoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from "react";
import Card from "react-bootstrap/Card";
import Button from "react-bootstrap/Button"
import Accordion from 'react-bootstrap/Accordion'
import ListGroup from 'react-bootstrap/ListGroup'

export default class DataPoint extends React.Component {
constructor(props) {
super(props);
console.log(props)
this.filterList = this.filterList.bind(this)
this.state = {visibleItems:props.data}
}

filterList(event) {
var allItems = this.props.data.slice();
let visibleItems = allItems.filter((item) => {
return item[this.props.data_type.fields[0]].toLowerCase().search(
event.target.value.toLowerCase()) !== -1;
});
this.setState({visibleItems:visibleItems})
}

componentDidMount() {
console.log(this.props)
}

render(){
let props = this.props;
let visibleData = this.state.visibleItems.length > 0 ? this.state.visibleItems : props.data
return(
<Card>
<Accordion.Toggle as={Card.Header} eventKey="data_points">
Data Points
</Accordion.Toggle>
<Accordion.Collapse as={Card.Body} eventKey="data_points">
<div style={{overflowY:"auto"}}>
<input type="text" placeholder="Search" onChange={this.filterList} style={{width:'100%'}}/>
<Accordion>
{visibleData.map((data,index)=>{
return(
<Card key={`card-${index}-${data[props.data_type.id]}`}>
<Card.Header >
<Accordion.Toggle as={Button} variant="link" eventKey={data[props.data_type.id]}>
{data[props.data_type.fields[0]]}
</Accordion.Toggle>
</Card.Header>
<Accordion.Collapse eventKey={data[props.data_type.id]}>
<ListGroup>
{props.data_type.fields.map((field)=>{
return(
<ListGroup.Item key={`lg-${data[field]}`}><b>{field}:</b> {data[field]}</ListGroup.Item>
)
})}
</ListGroup>
</Accordion.Collapse>
</Card>
)
})}
</Accordion>
</div>
</Accordion.Collapse>
</Card>
)}
}
34 changes: 2 additions & 32 deletions opendatavisualization/src/components/MapContainer/mapControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Accordion from 'react-bootstrap/Accordion'
import ListGroup from 'react-bootstrap/ListGroup'
import ButtonGroup from "react-bootstrap/ButtonGroup";
import {getColor} from "./mapContainer";
import DataPoint from "./dataPoints"

function MapControls(props) {
const data_type = DATA_SETS[props.data_set];
Expand Down Expand Up @@ -72,38 +73,7 @@ function MapControls(props) {
</Card>
)
})}
<Card>
<Accordion.Toggle as={Card.Header} eventKey="data_points">
Data Points
</Accordion.Toggle>
<Accordion.Collapse as={Card.Body} eventKey="data_points">
<div style={{overflowY:"auto"}}>
<Accordion>
{props.data.map((data,index)=>{
return(
<Card key={`card-${index}-${data[data_type.id]}`}>
<Card.Header >
<Accordion.Toggle as={Button} variant="link" eventKey={data[data_type.id]}>
{data[data_type.fields[0]]}
</Accordion.Toggle>
</Card.Header>
<Accordion.Collapse eventKey={data[data_type.id]}>
<ListGroup>
{data_type.fields.map((field)=>{
return(
<ListGroup.Item key={`lg-${data[field]}`}><b>{field}:</b> {data[field]}</ListGroup.Item>
)
})}
</ListGroup>
</Accordion.Collapse>
</Card>

)
})}
</Accordion>
</div>
</Accordion.Collapse>
</Card>
<DataPoint data={props.data} data_type= {data_type} />
</Accordion>
</div>
)
Expand Down