From 3b0b088b02825e66d75bd28e6deb6cef8f2ff530 Mon Sep 17 00:00:00 2001 From: Rebecca Spencer-Strong Date: Thu, 3 Oct 2019 16:20:06 -0400 Subject: [PATCH] added search filter to data points category --- .../src/components/MapContainer/dataPoints.js | 65 +++++++++++++++++++ .../components/MapContainer/mapControls.js | 34 +--------- 2 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 opendatavisualization/src/components/MapContainer/dataPoints.js diff --git a/opendatavisualization/src/components/MapContainer/dataPoints.js b/opendatavisualization/src/components/MapContainer/dataPoints.js new file mode 100644 index 0000000..d7f95ca --- /dev/null +++ b/opendatavisualization/src/components/MapContainer/dataPoints.js @@ -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( + + + Data Points + + +
+ + + {visibleData.map((data,index)=>{ + return( + + + + {data[props.data_type.fields[0]]} + + + + + {props.data_type.fields.map((field)=>{ + return( + {field}: {data[field]} + ) + })} + + + + ) + })} + +
+
+
+ )} +} \ No newline at end of file diff --git a/opendatavisualization/src/components/MapContainer/mapControls.js b/opendatavisualization/src/components/MapContainer/mapControls.js index 687beea..86f2f03 100644 --- a/opendatavisualization/src/components/MapContainer/mapControls.js +++ b/opendatavisualization/src/components/MapContainer/mapControls.js @@ -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]; @@ -72,38 +73,7 @@ function MapControls(props) { ) })} - - - Data Points - - -
- - {props.data.map((data,index)=>{ - return( - - - - {data[data_type.fields[0]]} - - - - - {data_type.fields.map((field)=>{ - return( - {field}: {data[field]} - ) - })} - - - - - ) - })} - -
-
-
+ )