From 6754620d7abfb7273cff5f173349eb507fc0c8b7 Mon Sep 17 00:00:00 2001 From: Haishan Date: Fri, 8 Nov 2019 00:40:48 +0800 Subject: feat: connections inspection --- src/components/ConnectionTable.js | 99 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/components/ConnectionTable.js (limited to 'src/components/ConnectionTable.js') diff --git a/src/components/ConnectionTable.js b/src/components/ConnectionTable.js new file mode 100644 index 0000000..547925c --- /dev/null +++ b/src/components/ConnectionTable.js @@ -0,0 +1,99 @@ +import React from 'react'; +import { ArrowUp, ArrowDown } from 'react-feather'; +import prettyBytes from '../misc/pretty-bytes'; +import { formatDistance } from 'date-fns'; +import cx from 'classnames'; +import { useTable, useSortBy } from 'react-table'; + +import s from './ConnectionTable.module.css'; + +const columns = [ + { Header: 'Host', accessor: 'host' }, + { Header: 'Download', accessor: 'download' }, + { Header: 'Upload', accessor: 'upload' }, + { Header: 'Network', accessor: 'network' }, + { Header: 'Type', accessor: 'type' }, + { Header: 'Chains', accessor: 'chains' }, + { Header: 'Rule', accessor: 'rule' }, + { Header: 'Time', accessor: 'start' }, + { Header: 'Source IP', accessor: 'sourceIP' }, + { Header: 'Source Port', accessor: 'sourcePort' }, + { Header: 'Designation IP', accessor: 'destinationIP' }, + { Header: 'Designation Port', accessor: 'destinationPort' } +]; + +function renderCell(cell, now) { + switch (cell.column.id) { + case 'start': + return formatDistance(-cell.value, now); + case 'download': + case 'upload': + return prettyBytes(cell.value); + default: + return cell.value; + } +} + +function Table({ data }) { + const now = new Date(); + const { + getTableProps, + // getTableBodyProps, + headerGroups, + rows, + prepareRow + } = useTable( + { + columns, + data + }, + useSortBy + ); + return ( +
+
+ {headerGroups.map(headerGroup => ( +
+ {headerGroup.headers.map(column => ( +
+ {column.render('Header')} + + {column.isSorted ? ( + column.isSortedDesc ? ( + + ) : ( + + ) + ) : null} + +
+ ))} + + {rows.map((row, i) => { + prepareRow(row); + return row.cells.map((cell, j) => { + return ( +
+ {renderCell(cell, now)} +
+ ); + }); + })} +
+ ))} +
+
+ ); +} + +export default Table; -- cgit v1.3.1