From f306cfa8b6445dd04c5f7188d1a5022bcb747a62 Mon Sep 17 00:00:00 2001
From: Jason <jason.daurus@gmail.com>
Date: Thu, 9 Jun 2016 17:46:14 +0800
Subject: [web] separate flowtable to multiple files

---
 web/src/js/components/FlowTable/FlowTableHead.jsx | 43 +++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 web/src/js/components/FlowTable/FlowTableHead.jsx

(limited to 'web/src/js/components/FlowTable/FlowTableHead.jsx')

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)
-- 
cgit v1.2.3

