From 6c1c5bf2a9c5c2291ffdfe777dce3863a0ee1af4 Mon Sep 17 00:00:00 2001 From: "m.ray" <16125548+MadalinaRaicu@users.noreply.github.com> Date: Wed, 22 Mar 2023 08:05:05 -0400 Subject: [PATCH] feat(trading): pin collateral row (#3218) --- .../src/integration/trading-accounts.cy.ts | 17 +++--------- libs/accounts/src/lib/accounts-manager.tsx | 6 ----- libs/accounts/src/lib/accounts-table.tsx | 27 ++++++++++++++++--- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/apps/trading-e2e/src/integration/trading-accounts.cy.ts b/apps/trading-e2e/src/integration/trading-accounts.cy.ts index ae50a86cc..c0e142b2d 100644 --- a/apps/trading-e2e/src/integration/trading-accounts.cy.ts +++ b/apps/trading-e2e/src/integration/trading-accounts.cy.ts @@ -10,7 +10,7 @@ beforeEach(() => { describe('accounts', { tags: '@smoke' }, () => { it('renders accounts', () => { - const tradingAccountRowId = '[row-id="asset-0"]'; + const tradingAccountRowId = '[row-id="t-0"]'; cy.getByTestId('Collateral').click(); cy.getByTestId('tab-accounts').should('be.visible'); @@ -44,9 +44,9 @@ describe('accounts', { tags: '@smoke' }, () => { describe('sorting by ag-grid columns should work well', () => { it('sorting by asset', () => { cy.getByTestId('Collateral').click(); - const marketsSortedDefault = ['tBTC', 'AST0', 'tEURO', 'tDAI', 'tBTC']; - const marketsSortedAsc = ['AST0', 'tBTC', 'tBTC', 'tDAI', 'tEURO']; - const marketsSortedDesc = ['tEURO', 'tDAI', 'tBTC', 'tBTC', 'AST0']; + const marketsSortedDefault = ['tBTC', 'tEURO', 'tDAI', 'tBTC']; + const marketsSortedAsc = ['tBTC', 'tBTC', 'tDAI', 'tEURO']; + const marketsSortedDesc = ['tEURO', 'tDAI', 'tBTC', 'tBTC']; checkSorting( 'asset.symbol', marketsSortedDefault, @@ -59,7 +59,6 @@ describe('accounts', { tags: '@smoke' }, () => { cy.getByTestId('Collateral').click(); const marketsSortedDefault = [ '1,000.00002', - '100,001.01', '1,000.01', '1,000.00', '1,000.00001', @@ -69,10 +68,8 @@ describe('accounts', { tags: '@smoke' }, () => { '1,000.00001', '1,000.00002', '1,000.01', - '100,001.01', ]; const marketsSortedDesc = [ - '100,001.01', '1,000.01', '1,000.00002', '1,000.00001', @@ -90,7 +87,6 @@ describe('accounts', { tags: '@smoke' }, () => { cy.getByTestId('Collateral').click(); const marketsSortedDefault = [ '0.000.00%', - '1.010.00%', '0.010.00%', '0.000.00%', '0.000.00%', @@ -100,10 +96,8 @@ describe('accounts', { tags: '@smoke' }, () => { '0.000.00%', '0.000.00%', '0.010.00%', - '1.010.00%', ]; const marketsSortedDesc = [ - '1.010.00%', '0.010.00%', '0.000.00%', '0.000.00%', @@ -121,7 +115,6 @@ describe('accounts', { tags: '@smoke' }, () => { cy.getByTestId('Collateral').click(); const marketsSortedDefault = [ '1,000.00002', - '100,001.01', '1,000.01', '1,000.00', '1,000.00001', @@ -131,10 +124,8 @@ describe('accounts', { tags: '@smoke' }, () => { '1,000.00001', '1,000.00002', '1,000.01', - '100,001.01', ]; const marketsSortedDesc = [ - '100,001.01', '1,000.01', '1,000.00002', '1,000.00001', diff --git a/libs/accounts/src/lib/accounts-manager.tsx b/libs/accounts/src/lib/accounts-manager.tsx index f9d07a445..2d67b7423 100644 --- a/libs/accounts/src/lib/accounts-manager.tsx +++ b/libs/accounts/src/lib/accounts-manager.tsx @@ -10,7 +10,6 @@ import type { AccountFields } from './accounts-data-provider'; import { aggregatedAccountsDataProvider } from './accounts-data-provider'; import type { PinnedAsset } from './accounts-table'; import { AccountTable } from './accounts-table'; -import type { RowHeightParams } from 'ag-grid-community'; interface AccountManagerProps { partyId: string; @@ -50,10 +49,6 @@ export const AccountManager = ({ disabled: noBottomPlaceholder, }); - const getRowHeight = useCallback( - (params: RowHeightParams) => (params.node.rowPinned ? 32 : 22), - [] - ); return (
diff --git a/libs/accounts/src/lib/accounts-table.tsx b/libs/accounts/src/lib/accounts-table.tsx index 5735ed1e3..dfd80d8a3 100644 --- a/libs/accounts/src/lib/accounts-table.tsx +++ b/libs/accounts/src/lib/accounts-table.tsx @@ -1,4 +1,4 @@ -import { forwardRef, useMemo, useState } from 'react'; +import { forwardRef, useCallback, useMemo, useState } from 'react'; import { addDecimalsFormatNumber, isNumeric, @@ -16,7 +16,12 @@ import { CenteredGridCellWrapper, } from '@vegaprotocol/datagrid'; import { AgGridColumn } from 'ag-grid-react'; -import type { IDatasource, IGetRowsParams, RowNode } from 'ag-grid-community'; +import type { + IDatasource, + IGetRowsParams, + RowHeightParams, + RowNode, +} from 'ag-grid-community'; import type { AgGridReact, AgGridReactProps } from 'ag-grid-react'; import BreakdownTable from './breakdown-table'; import type { AccountFields } from './accounts-data-provider'; @@ -108,17 +113,31 @@ export const AccountTable = forwardRef( }; } } - return undefined; + return currentPinnedAssetRow; }, [pinnedAssetId, props.pinnedAsset, props.rowData]); + const getRowHeight = useCallback( + (params: RowHeightParams) => + params.node.rowPinned && + params.data.asset.id === pinnedAssetId && + new BigNumber(params.data.total).isLessThanOrEqualTo(0) + ? 32 + : 22, + [pinnedAssetId] + ); + return ( <> data.asset.id} ref={ref} tooltipShowDelay={500} + rowData={props.rowData?.filter( + (data) => data.asset.id !== pinnedAssetId + )} defaultColDef={{ flex: 1, resizable: true, @@ -126,7 +145,7 @@ export const AccountTable = forwardRef( sortable: true, comparator: accountValuesComparator, }} - {...props} + getRowHeight={getRowHeight} pinnedTopRowData={pinnedAssetRow ? [pinnedAssetRow] : undefined} >