diff --git a/src/containers/Network/NodesTable.tsx b/src/containers/Network/NodesTable.tsx index 6ae11303a..bb20b02ee 100644 --- a/src/containers/Network/NodesTable.tsx +++ b/src/containers/Network/NodesTable.tsx @@ -1,4 +1,4 @@ -import { FC } from 'react' +import { FC, useState } from 'react' import { useTranslation } from 'react-i18next' import { Loader } from '../shared/components/Loader' import { durationToHuman } from '../shared/utils' @@ -15,21 +15,28 @@ const renderLastLedger = (ledger) => ) : ( unknown ) - -const renderLedgerHistory = (ledgers, range) => { +const getLedgerHistory = (ledgers, range, MAX_WIDTH = 160) => { let count = 0 - const MAX_WIDTH = 160 + let boxes = '' const min = Math.max(range[1] - 10000000, range[0]) const diff = range[1] - min if (ledgers) { - const boxes = ledgers.map((l) => { + boxes = ledgers.map((l) => { const [low, high] = l const width = Math.min((high - low + 1) / diff, 1) * MAX_WIDTH const left = Math.max((low - min) / diff, 0) * MAX_WIDTH count += high - low return
}) + } + return { boxes, count } +} +const renderLedgerHistory = (ledgers, range) => { + const MAX_WIDTH = 160 + + if (ledgers) { + const { boxes, count } = getLedgerHistory(ledgers, range, MAX_WIDTH) if (count < 0) { return null @@ -99,19 +106,38 @@ export const NodesTable: FC<{ nodes: NodeData[] }> = ({ }) => { const nodes = unformattedNodes ? formatLedgerHistory(unformattedNodes) : null const ledgerRange = nodes && getLedgerRange(nodes) + const [sortedField, setSortedField] = useState(null) + const [sortOrder, setSortOrder] = useState(null) + + const requestSort = (key) => { + let direction = 'desc' + if (sortedField === key && sortOrder === 'desc') { + direction = 'asc' + } + setSortOrder(direction) + setSortedField(key) + } const { t } = useTranslation() const renderNode = (node) => ({t('node_pubkey')} | -{t('ip')} | -{t('state')} | -{t('rippled_version')} | -{t('last_ledger')} | -{t('uptime')} | -{t('peers')} | ++ requestSort('pubkey')}> + + {t('node_pubkey')} + + | ++ requestSort('ip')}> + + {t('ip')} + + | ++ requestSort('server_state')}> + + {t('state')} + + | ++ requestSort('rippled_version')}> + + {t('rippled_version')}{' '} + + | ++ requestSort('last_ledger')}> + + {t('last_ledger')} + + | ++ requestSort('uptime')}> + + {t('uptime')} + + | ++ requestSort('peers')}> + + {t('peers')} + + | {t('in_out')} | -{t('ledger_history')} | -{t('quorum')} | -{t('load')} | -{t('latency')} | ++ requestSort('ledger_history')}> + + {t('ledger_history')} + + | ++ requestSort('quorum')}> + + {t('quorum')} + + | ++ requestSort('load')}> + + {t('load')} + + | ++ requestSort('latency')}> + + {t('latency')} + + | 1.1.2 | ', + '1.2.0-rc2 | ', + '1.2.0-rc2 | ', + ] + let index = 0 + rows.forEach((element) => { + expect(element.html()).toBe(expected[index]) + // eslint-disable-next-line no-plusplus + index++ + }) wrapper.unmount() done() })
---|