diff options
author | Jason <jason.daurus@gmail.com> | 2016-06-09 17:46:14 +0800 |
---|---|---|
committer | Jason <jason.daurus@gmail.com> | 2016-06-09 17:52:30 +0800 |
commit | f306cfa8b6445dd04c5f7188d1a5022bcb747a62 (patch) | |
tree | 8b229ee951b4e4756c3596b66cefee632bfb8870 /web/src/js/components/FlowTable/FlowTableHead.jsx | |
parent | 52754f40c29b95b8355627036660f7e182007e74 (diff) | |
download | mitmproxy-f306cfa8b6445dd04c5f7188d1a5022bcb747a62.tar.gz mitmproxy-f306cfa8b6445dd04c5f7188d1a5022bcb747a62.tar.bz2 mitmproxy-f306cfa8b6445dd04c5f7188d1a5022bcb747a62.zip |
[web] separate flowtable to multiple files
Diffstat (limited to 'web/src/js/components/FlowTable/FlowTableHead.jsx')
-rw-r--r-- | web/src/js/components/FlowTable/FlowTableHead.jsx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/web/src/js/components/FlowTable/FlowTableHead.jsx b/web/src/js/components/FlowTable/FlowTableHead.jsx new file mode 100644 index 00000000..a46219d1 --- /dev/null +++ b/web/src/js/components/FlowTable/FlowTableHead.jsx @@ -0,0 +1,43 @@ +import React, { PropTypes } from 'react' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import classnames from 'classnames' +import columns from './FlowColumns' + +import { setSort } from "../../ducks/flows" + +FlowTableHead.propTypes = { + onSort: PropTypes.func.isRequired, + sortDesc: React.PropTypes.bool.isRequired, + sortColumn: React.PropTypes.string, +} + +function FlowTableHead({ sortColumn, sortDesc, onSort }) { + const sortType = sortDesc ? 'sort-desc' : 'sort-asc' + + return ( + <tr> + {columns.map(Column => ( + <th className={classnames(Column.headerClass, sortColumn === Column.name && sortType)} + key={Column.name} + onClick={() => onClick(Column)}> + {Column.headerName} + </th> + ))} + </tr> + ) + + function onClick(Column) { + onSort({ sortColumn: Column.name, sortDesc: Column.name !== sortColumn ? false : !sortDesc }) + } +} + +export default connect( + state => ({ + sortDesc: state.flows.sort.sortDesc, + sortColumn: state.flows.sort.sortColumn, + }), + dispatch => bindActionCreators({ + onSort: setSort, + }, dispatch) +)(FlowTableHead) |