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

listView (furnitureList): list view for each room has redux form #257

Merged
merged 1 commit into from
Aug 19, 2016
Merged
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
84 changes: 51 additions & 33 deletions src/furniture/components/listView.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import AddItemButton from '../../app/addItemButton.component.jsx';
import { connect } from 'react-redux';
import furnitureHelper from '../furnitureHelper';
import FlatButton from 'material-ui/FlatButton';

import ListingFurnitureRow from './listingFurnitureRow.component.jsx';

class ListView extends Component {
toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
constructor(props) {
super(props);
}
state = {
filter: furnitureHelper.listByFurniture,
this.state = {
filter: furnitureHelper.listByFurniture,
editing: {}
}
}

filterByFurnitureName() {
Expand All @@ -32,50 +33,59 @@ class ListView extends Component {
unfilter() {
this.setState({filter: furnitureHelper.listByFurniture});
}
updateEditStatus(furniture, status) {
const editing = Object.assign({}, this.state.editing);
editing[furniture] = status;
this.setState({ editing });
}
render () {
const { rooms } = this.props;
const roomName = Object.keys(rooms);
const toTitleCase = this.toTitleCase;
let furnitureList = this.state.filter(rooms);
const roomSelected = this.props.roomSelected
console.log(furnitureList)
const _this = this;



return (

<div className="container">

<h4>Full furniture list</h4>

<Table>
<thead>
<tr>
<th data-field="room" onClick={()=> {this.filterByRoomName()}} >Room Name</th>
<th data-field="furniture" onClick={()=> {this.filterByFurnitureName()}} >Furniture Name</th>
<th data-field="price" onClick={()=> {this.filterByFurniturePrice()}} >Item Price</th>
<th data-field="size">Item Size</th>
</tr>
</thead>
{furnitureList.filter(function(data, i){
return data.roomName === roomSelected;
<h4>Full furniture list</h4>
<div className="table">
<div className="tr">
<span className="th room" data-field="room" onClick={()=> {this.filterByRoomName()}} >Room Name</span>
<span className="th furniture" data-field="furniture" onClick={()=> {this.filterByFurnitureName()}} >Furniture Name</span>
<span className="th price" data-field="price" onClick={()=> {this.filterByFurniturePrice()}} >Price</span>
<span className="th size" data-field="size">Size</span>
<span className="th color" data-field="color">Color</span>
<span className="th controls">&nbsp;</span>
</div>
{furnitureList.filter(function(room, i){
return room.roomName === roomSelected;
}).map(function(data, i){
return(
<tr key={i} id="table-item">
<td className="slimDown"><b>{ data.roomName || "" }</b></td>
<td className="slimDown"> { data.furnitureName } </td>
<td className="slimDown"> { data.furnitureObj.price } </td>
<td className="slimDown"> { data.furnitureObj.size } </td>
</tr>
)
})
const initialFormValues = {
itemName: data.furnitureName,
price: data.furnitureObj.price,
deliveryDate: data.furnitureObj.deliveryDate,
size: data.furnitureObj.size,
quantity: data.furnitureObj.quantity,
description: data.furnitureObj.description,
color: data.furnitureObj.color,
};
return(
<ListingFurnitureRow
editing={ _this.state.editing[data.furnitureName] }
data={ data } key={ i }
updateEditStatus={_this.updateEditStatus.bind(_this)}
initialValues={ initialFormValues }
/>
)
})
}
<tbody>
</tbody>
</Table>

</div>
</div>


)
}
}
Expand All @@ -85,3 +95,11 @@ function mapStateToProps({ rooms, roomSelected }) {
}

export default connect(mapStateToProps)(ListView);


// <tr key={i} id="table-item">
// <td className="slimDown"><b>{ data.roomName || "" }</b></td>
// <td className="slimDown"> { data.furnitureName } </td>
// <td className="slimDown"> { data.furnitureObj.price } </td>
// <td className="slimDown"> { data.furnitureObj.size } </td>
// </tr>