-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dataset-view): add dataset-list component
- Loading branch information
1 parent
9a4baa2
commit 92766cc
Showing
6 changed files
with
153 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import * as React from 'react' | ||
|
||
const datasets = [ | ||
{ | ||
id: 1, | ||
title: 'USGS Earthquakes', | ||
name: 'chriswhong/usgs_earthquakes' | ||
}, | ||
{ | ||
id: 2, | ||
title: 'World Bank Population', | ||
name: 'b5/world_bank_population' | ||
}, | ||
{ | ||
id: 3, | ||
title: 'Baltimore Bus Timeliness (June 2019)', | ||
name: 'chriswhong/baltimore_bus_timeliness' | ||
}, | ||
{ | ||
id: 4, | ||
title: 'PLUTO Modified Parcels', | ||
name: 'chriswhong/nyc_pluto_modified_parcels' | ||
} | ||
] | ||
|
||
export default class DatasetList extends React.Component<{}, { activeTab: string, filterString: string }> { | ||
constructor (p: {}) { | ||
super(p) | ||
this.state = { | ||
activeTab: 'history', | ||
filterString: '' | ||
} | ||
} | ||
|
||
handleTabClick (activeTab: string) { | ||
this.setState({ activeTab }) | ||
} | ||
|
||
handleFilterKeyUp (e: any) { | ||
this.setState({ filterString: e.target.value }) | ||
} | ||
|
||
render () { | ||
let filteredDatasets = datasets | ||
const { filterString } = this.state | ||
|
||
if (filterString !== '') { | ||
filteredDatasets = datasets.filter((dataset) => { | ||
const lowercasedFilterString = filterString.toLowerCase() | ||
if (dataset.name.toLowerCase().includes(lowercasedFilterString)) return true | ||
if (dataset.title.toLowerCase().includes(lowercasedFilterString)) return true | ||
|
||
return false | ||
}) | ||
} | ||
|
||
const listContent = filteredDatasets.length > 0 | ||
? filteredDatasets.map(({ id, title, name }) => ( | ||
<div key={id} className='sidebar-list-item sidebar-list-item-text '> | ||
<div className='text'>{title}</div> | ||
<div className='subtext'>{name}</div> | ||
</div> | ||
)) | ||
: <div className='sidebar-list-item-text'>Oops, no matches found for <strong>'{filterString}'</strong></div> | ||
|
||
return ( | ||
<div className='dataset-sidebar'> | ||
<div className='sidebar-list-item sidebar-list-item-text'> | ||
<div id='controls'> | ||
<input | ||
type='text' | ||
name='filter' | ||
placeholder='Filter' | ||
onKeyUp={(e) => this.handleFilterKeyUp(e)} | ||
/> | ||
<div id='add-button'>Add</div> | ||
</div> | ||
<div className='strong-message'>You have {datasets.length} local datasets</div> | ||
</div> | ||
<div id='list'> | ||
{listContent} | ||
</div> | ||
</div> | ||
) | ||
} | ||
} |
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
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,16 @@ | ||
.dataset-list { | ||
#controls { | ||
display: flex; | ||
flex-direction: row; | ||
padding-bottom: 6px; | ||
|
||
input { | ||
margin-right: 10px; | ||
flex: 1; | ||
} | ||
|
||
#add-button { | ||
align-self: flex-end; | ||
} | ||
} | ||
} |
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