From b528cf08ede73a76a669d99a6073fe2c96969b1e Mon Sep 17 00:00:00 2001 From: Sam Keen Date: Mon, 22 Aug 2022 15:52:14 +0100 Subject: [PATCH] Feat/1093: Visual tweaks to the validators table (#1098) * Feat/1093: Validators form scrollbar more visible * Feat/1093: Less tweaking, specific scrollbar styling * Feat/1093: Auto sorting and manual sizing of validators form. Also added the correct comparators for the validator and status columns * Feat/1093: A little extra spacing between epoch data and the validators table --- apps/token/src/routes/staking/node-list.tsx | 57 ++++++++++++--------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/apps/token/src/routes/staking/node-list.tsx b/apps/token/src/routes/staking/node-list.tsx index f6385b48f..f5e74d352 100644 --- a/apps/token/src/routes/staking/node-list.tsx +++ b/apps/token/src/routes/staking/node-list.tsx @@ -12,6 +12,7 @@ import { BigNumber } from '../../lib/bignumber'; import { formatNumber } from '@vegaprotocol/react-helpers'; import type { Nodes } from './__generated__/Nodes'; import type { Staking_epoch } from './__generated__/Staking'; +import type { ColDef } from 'ag-grid-community'; const VALIDATOR = 'validator'; const STATUS = 'status'; @@ -58,8 +59,6 @@ interface ValidatorRendererProps { data: { validator: { avatarUrl: string; name: string } }; } -const stripNonDigits = (string: string) => string.replace(/\D/g, ''); - const ValidatorRenderer = ({ data }: ValidatorRendererProps) => { const { avatarUrl, name } = data.validator; return ( @@ -81,7 +80,7 @@ const ValidatorRenderer = ({ data }: ValidatorRendererProps) => { // AG Grid places the scrollbar over the bottom validator, which obstructs const nodeListGridStyles = ` .ag-theme-balham-dark .ag-body-horizontal-scroll { - opacity: 0.25; + opacity: 0.75; } `; @@ -162,45 +161,66 @@ export const NodeList = ({ epoch }: NodeListProps) => { const gridRef = useRef(null); const NodeListTable = forwardRef((_, ref) => { - const colDefs = useMemo( + const colDefs = useMemo( () => [ { field: VALIDATOR, headerName: t('validator').toString(), cellRenderer: ValidatorRenderer, + comparator: ({ name: a }, { name: b }) => { + if (a === b) return 0; + return a > b ? 1 : -1; + }, + }, + { + field: STATUS, + headerName: t('status').toString(), + comparator: (a, b) => { + if (a === b) return 0; + return a > b ? 1 : -1; + }, + width: 100, }, - { field: STATUS, headerName: t('status').toString() }, { field: TOTAL_STAKE_THIS_EPOCH, headerName: t('totalStakeThisEpoch').toString(), + width: 160, }, { field: SHARE, headerName: t('share').toString(), + width: 80, }, { field: VALIDATOR_STAKE, headerName: t('validatorStake').toString(), + width: 120, }, { field: PENDING_STAKE, headerName: t('nextEpoch').toString(), + width: 100, }, { field: RANKING_SCORE, headerName: t('rankingScore').toString(), + width: 120, + sort: 'desc', }, { field: STAKE_SCORE, headerName: t('stakeScore').toString(), + width: 100, }, { field: PERFORMANCE_SCORE, headerName: t('performanceScore').toString(), + width: 100, }, { field: VOTING_POWER, headerName: t('votingPower').toString(), + width: 100, }, ], [] @@ -209,8 +229,8 @@ export const NodeList = ({ epoch }: NodeListProps) => { const defaultColDef = useMemo( () => ({ sortable: true, - comparator: (a: string, b: string) => - parseFloat(stripNonDigits(a)) - parseFloat(stripNonDigits(b)), + resizable: true, + comparator: (a: string, b: string) => parseFloat(a) - parseFloat(b), }), [] ); @@ -229,17 +249,6 @@ export const NodeList = ({ epoch }: NodeListProps) => { defaultColDef={defaultColDef} animateRows={true} suppressCellFocus={true} - onGridReady={(event) => { - event.columnApi.applyColumnState({ - state: [ - { - colId: RANKING_SCORE, - sort: 'desc', - }, - ], - }); - event.columnApi.autoSizeAllColumns(false); - }} onCellClicked={(event) => { navigate(event.data.id); }} @@ -251,11 +260,13 @@ export const NodeList = ({ epoch }: NodeListProps) => { return ( {epoch && epoch.timestamps.start && epoch.timestamps.expiry && ( - +
+ +
)}