Skip to content

Commit

Permalink
feat(dataset-view): add dataset-list component
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhong committed Jul 11, 2019
1 parent 9a4baa2 commit 92766cc
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 60 deletions.
86 changes: 86 additions & 0 deletions app/components/DatasetList.tsx
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>&apos;{filterString}&apos;</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>
)
}
}
24 changes: 13 additions & 11 deletions app/components/DatasetSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import * as React from 'react'

interface FileRowProps {
name: string
filename: string
}

const FileRow: React.SFC<FileRowProps> = (props) => {
return (
<div className='file-row sidebar-row'>
<div className='label'>{props.name}</div>
<div className='sidebar-list-item sidebar-list-item-text '>
<div className='text'>{props.name}</div>
<div className='subtext'>{props.filename}</div>
</div>
)
}
Expand All @@ -20,9 +22,9 @@ interface HistoryListItemProps {

const HistoryListItem: React.SFC<HistoryListItemProps> = (props) => {
return (
<div className='file-row sidebar-row history-list-item'>
<div className='title'>{props.commitTitle}</div>
<div className='userTimeInfo'>
<div className='sidebar-list-item sidebar-list-item-text'>
<div className='text'>{props.commitTitle}</div>
<div className='subtext'>
<img className= 'user-image' src = {props.avatarUrl} />
<div className='time-message'>
{props.userTimeMessage}
Expand Down Expand Up @@ -68,21 +70,21 @@ export default class DatasetSidebar extends React.Component<{}, { activeTab: str
render () {
const { activeTab } = this.state
return (
<div id='dataset-sidebar'>
<div id='tabs' className='sidebar-row'>
<div className='dataset-sidebar'>
<div id='tabs' className='sidebar-list-item'>
<div className={'tab ' + (activeTab === 'status' ? 'active' : '')} onClick={() => this.handleTabClick('status')}>Status</div>
<div className={'tab ' + (activeTab === 'status' ? '' : 'active')} onClick={() => this.handleTabClick('history')}>History</div>
</div>
<div id='content'>
<div id='status-content' className='sidebar-content' hidden = {activeTab !== 'status'}>
<div className='sidebar-row'>
<div className='sidebar-list-item'>
<div className='changes'>
Changes
</div>
</div>
<FileRow name='Meta' />
<FileRow name='Body' />
<FileRow name='Schema' />
<FileRow name='Meta' filename='meta.json' />
<FileRow name='Body' filename='body.csv' />
<FileRow name='Schema' filename='schema.json' />
</div>
<div id='history-content' className='sidebar-content' hidden = {activeTab === 'status'}>
{
Expand Down
3 changes: 2 additions & 1 deletion app/containers/DatasetContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import { Resizable } from '../components/resizable'
import DatasetSidebar from '../components/DatasetSidebar'
import DatasetList from '../components/DatasetList'

const defaultSidebarWidth = 250
const logo = require('../assets/qri-blob-logo-tiny.png') //eslint-disable-line
Expand Down Expand Up @@ -73,7 +74,7 @@ export default class DatasetContainer extends React.Component<{}, { showDatasetL
className='dataset-list'
style={{ width: sidebarWidth }}
>
Dataset List
<DatasetList />
</div>
)
}
Expand Down
83 changes: 35 additions & 48 deletions app/scss/_dataset-container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
.content {
background-color: #d8d8d8;
flex: 1;
position: relative;

.overlay {
position: absolute;
Expand Down Expand Up @@ -130,32 +131,21 @@
// Dataset Sidebar //
////////////////////////////

#dataset-sidebar {
.dataset-sidebar {
height: 100%;
width: 100%;

.sidebar-row {
width: 100%;
font-size: .9rem;
border-bottom: 1px solid #979797;
cursor: default;
&:last-child {
border-right: 0;
}
}
font-size: .9rem;
cursor: default;

#tabs {
width: 100%;
height: 30px;
background-color: #FFF;
cursor: default;
display: flex;

.tab {
width: 50%;
display: inline-block;
height: 100%;
padding: 6px;
flex: 1;
text-align: center;
line-height: 1.9rem;
border-right: 1px solid #979797;

&:last-child {
Expand All @@ -178,50 +168,47 @@
background-color: #F6F8FA;
}

.file-row {
height: 60px;
padding: 8px;
$list-item-bottom-border: 1px solid #979797;
$sidebar-item-padding: 8px;

.label {
font-weight: 600;
font-size: 1.2rem;
}

&:hover {
background-color: #efefef;
}
// sidebar list items
.sidebar-list-item {
border-bottom: $list-item-bottom-border;
display: flex;
}
}

////////////////////////////
// History List Item //
////////////////////////////
.sidebar-list-item-text {
padding: $sidebar-item-padding;
flex-direction: column;

.history-list-item {
.title {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
line-height: 1.6rem;
}
.text {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
line-height: 1.6rem;
}

.userTimeInfo {
display: flex;
.subtext {
display: flex;

.user-image {
height: 16px;
width: 16px;
margin-right: 4px;
border-radius: 2px;
}
.user-image {
height: 16px;
width: 16px;
margin-right: 4px;
border-radius: 2px;
}

.time-message {
flex: 1;
font-size: .65rem;
line-height: 1.2rem;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}

.strong-message {
font-weight: 500;
font-size: 0.8rem;
}
}
}
16 changes: 16 additions & 0 deletions app/scss/_dataset-list.scss
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;
}
}
}
1 change: 1 addition & 0 deletions app/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@import "stylesheet";

@import "dataset-container";
@import "dataset-list";

#app, #app-container {
height: 100%;
Expand Down

0 comments on commit 92766cc

Please sign in to comment.