-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from AntonNazarenko/fix/orderhistory
add dynamic order history table
- Loading branch information
Showing
6 changed files
with
95 additions
and
44 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
11 changes: 11 additions & 0 deletions
11
src/components/OrderHistoryTable/OrderHistoryTable.container.js
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,11 @@ | ||
import { connect } from 'react-redux' | ||
|
||
import OrderHistoryTable from './OrderHistoryTable' | ||
|
||
const mapStateToProps = (state = {}) => ({ | ||
orderHistory: state.ws.orderHistory.orders, | ||
}) //eslint-disable-line | ||
|
||
const mapDispatchToProps = dispatch => ({}) //eslint-disable-line | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(OrderHistoryTable) |
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,43 @@ | ||
import React from 'react' | ||
|
||
import Table from '../../ui/Table' | ||
import Panel from '../../ui/Panel' | ||
import OrderHistoryTableColumns from './OrderHistoryTable.columns' | ||
import { propTypes, defaultProps } from './OrderHistoryTable.props' | ||
|
||
export default class OrderHistoryTable extends React.PureComponent { | ||
static propTypes = propTypes | ||
static defaultProps = defaultProps | ||
|
||
constructor(props) { | ||
super(props) | ||
this.onRowClick = this.onRowClick.bind(this) | ||
} | ||
|
||
onRowClick({ index } = {}) { | ||
const { onSelect, orders } = this.props | ||
onSelect(orders[index]) | ||
} | ||
|
||
render() { | ||
const { | ||
onRemove, dark, orderHistory, | ||
} = this.props | ||
return ( | ||
<Panel | ||
label='ORDER HISTORY' | ||
onRemove={onRemove} | ||
dark={dark} | ||
darkHeader={dark} | ||
> | ||
<Table | ||
data={orderHistory} | ||
columns={OrderHistoryTableColumns} | ||
onRowClick={this.onRowClick} | ||
defaultSortBy='mts' | ||
defaultSortDirection='ASC' | ||
/> | ||
</Panel> | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,42 +1,3 @@ | ||
import React from 'react' | ||
import OrderHistoryTable from './OrderHistoryTable.container' | ||
|
||
import Table from '../../ui/Table' | ||
import Panel from '../../ui/Panel' | ||
import OrderHistoryTableColumns from './OrderHistoryTable.columns' | ||
import { propTypes, defaultProps } from './OrderHistoryTable.props' | ||
|
||
export default class OrderHistoryTable extends React.PureComponent { | ||
static propTypes = propTypes | ||
static defaultProps = defaultProps | ||
|
||
constructor(props) { | ||
super(props) | ||
this.onRowClick = this.onRowClick.bind(this) | ||
} | ||
|
||
onRowClick({ index } = {}) { | ||
const { onSelect, orders } = this.props | ||
onSelect(orders[index]) | ||
} | ||
|
||
render() { | ||
const { orders, onRemove, dark } = this.props | ||
|
||
return ( | ||
<Panel | ||
label='ORDER HISTORY' | ||
onRemove={onRemove} | ||
dark={dark} | ||
darkHeader={dark} | ||
> | ||
<Table | ||
data={orders} | ||
columns={OrderHistoryTableColumns} | ||
onRowClick={this.onRowClick} | ||
defaultSortBy='mts' | ||
defaultSortDirection='ASC' | ||
/> | ||
</Panel> | ||
) | ||
} | ||
} | ||
export default OrderHistoryTable |
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,29 @@ | ||
import types from '../../constants/ws' | ||
import { orderAdapter } from '../../adapters/ws' | ||
|
||
const getInitialState = () => { | ||
return {} | ||
} | ||
|
||
export default (state = getInitialState(), action = {}) => { | ||
const { type, payload = [] } = action | ||
|
||
switch (type) { | ||
case types.DATA_ORDER_CLOSE: { | ||
const { order = [] } = payload | ||
const { orders = [] } = state | ||
const o = orderAdapter(order) | ||
return { | ||
...state, | ||
orders: [ | ||
o, | ||
...orders, | ||
], | ||
} | ||
} | ||
|
||
default: { | ||
return state | ||
} | ||
} | ||
} |