import React  from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import classnames from 'classnames'
import columns from './FlowColumns'

import { setSort } from '../../ducks/flows'

FlowTableHead.propTypes = {
    setSort: PropTypes.func.isRequired,
    sortDesc: PropTypes.bool.isRequired,
    sortColumn: PropTypes.string,
}

export function FlowTableHead({ sortColumn, sortDesc, setSort }) {
    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={() => setSort(Column.name, Column.name !== sortColumn ? false : !sortDesc)}>
                    {Column.headerName}
                </th>
            ))}
        </tr>
    )
}

export default connect(
    state => ({
        sortDesc: state.flows.sort.desc,
        sortColumn: state.flows.sort.column,
    }),
    {
        setSort
    }
)(FlowTableHead)
/option>
<option value='chaos_calmer'>chaos_calmer</option>
<option value='lede-17.01'>lede-17.01</option>
<option value='less-old-master'>less-old-master</option>
<option value='master'>master</option>
<option value='old-master'>old-master</option>
<option value='openwrt-18.06'>openwrt-18.06</option>
<option value='openwrt-19.07'>openwrt-19.07</option>
<option value='upstream'>upstream</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>upstream openwrt</td><td class='sub right'>James</td></tr></table>
<table class='tabs'><tr><td>
<a href='/cgit.cgi/openwrt/upstream/about/?h=v22.03.0-rc2'>about</a><a href='/cgit.cgi/openwrt/upstream/?h=v22.03.0-rc2'>summary</a><a href='/cgit.cgi/openwrt/upstream/refs/?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>refs</a><a href='/cgit.cgi/openwrt/upstream/log/target/linux/x86/Makefile?h=v22.03.0-rc2'>log</a><a class='active' href='/cgit.cgi/openwrt/upstream/tree/target/linux/x86/Makefile?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>tree</a><a href='/cgit.cgi/openwrt/upstream/commit/target/linux/x86/Makefile?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>commit</a><a href='/cgit.cgi/openwrt/upstream/diff/target/linux/x86/Makefile?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>diff</a><a href='/cgit.cgi/openwrt/upstream/stats/target/linux/x86/Makefile?h=v22.03.0-rc2'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/openwrt/upstream/log/target/linux/x86/Makefile'>
<input type='hidden' name='h' value='v22.03.0-rc2'/><input type='hidden' name='id' value='fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/openwrt/upstream/tree/?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>root</a>/<a href='/cgit.cgi/openwrt/upstream/tree/target?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>target</a>/<a href='/cgit.cgi/openwrt/upstream/tree/target/linux?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>linux</a>/<a href='/cgit.cgi/openwrt/upstream/tree/target/linux/x86?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>x86</a>/<a href='/cgit.cgi/openwrt/upstream/tree/target/linux/x86/Makefile?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>Makefile</a></div><div class='content'>blob: e42d87fbc99a86975a3f644eaa927a5dd539c976 (<a href='/cgit.cgi/openwrt/upstream/plain/target/linux/x86/Makefile?h=v22.03.0-rc2&amp;id=fd4ad6cae88d009e9560e4ee902bf20a5b42d36e'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
<a id='n14' href='#n14'>14</a>
<a id='n15' href='#n15'>15</a>
<a id='n16' href='#n16'>16</a>
<a id='n17' href='#n17'>17</a>
<a id='n18' href='#n18'>18</a>
<a id='n19' href='#n19'>19</a>
<a id='n20' href='#n20'>20</a>
<a id='n21' href='#n21'>21</a>
<a id='n22' href='#n22'>22</a>
<a id='n23' href='#n23'>23</a>
<a id='n24' href='#n24'>24</a>
<a id='n25' href='#n25'>25</a>
<a id='n26' href='#n26'>26</a>
<a id='n27' href='#n27'>27</a>
<a id='n28' href='#n28'>28</a>
</pre></td>
<td class='lines'><pre><code>