feat(trading): pin collateral row (#3218)
This commit is contained in:
parent
74a3aa8566
commit
6c1c5bf2a9
@ -10,7 +10,7 @@ beforeEach(() => {
|
|||||||
|
|
||||||
describe('accounts', { tags: '@smoke' }, () => {
|
describe('accounts', { tags: '@smoke' }, () => {
|
||||||
it('renders accounts', () => {
|
it('renders accounts', () => {
|
||||||
const tradingAccountRowId = '[row-id="asset-0"]';
|
const tradingAccountRowId = '[row-id="t-0"]';
|
||||||
cy.getByTestId('Collateral').click();
|
cy.getByTestId('Collateral').click();
|
||||||
|
|
||||||
cy.getByTestId('tab-accounts').should('be.visible');
|
cy.getByTestId('tab-accounts').should('be.visible');
|
||||||
@ -44,9 +44,9 @@ describe('accounts', { tags: '@smoke' }, () => {
|
|||||||
describe('sorting by ag-grid columns should work well', () => {
|
describe('sorting by ag-grid columns should work well', () => {
|
||||||
it('sorting by asset', () => {
|
it('sorting by asset', () => {
|
||||||
cy.getByTestId('Collateral').click();
|
cy.getByTestId('Collateral').click();
|
||||||
const marketsSortedDefault = ['tBTC', 'AST0', 'tEURO', 'tDAI', 'tBTC'];
|
const marketsSortedDefault = ['tBTC', 'tEURO', 'tDAI', 'tBTC'];
|
||||||
const marketsSortedAsc = ['AST0', 'tBTC', 'tBTC', 'tDAI', 'tEURO'];
|
const marketsSortedAsc = ['tBTC', 'tBTC', 'tDAI', 'tEURO'];
|
||||||
const marketsSortedDesc = ['tEURO', 'tDAI', 'tBTC', 'tBTC', 'AST0'];
|
const marketsSortedDesc = ['tEURO', 'tDAI', 'tBTC', 'tBTC'];
|
||||||
checkSorting(
|
checkSorting(
|
||||||
'asset.symbol',
|
'asset.symbol',
|
||||||
marketsSortedDefault,
|
marketsSortedDefault,
|
||||||
@ -59,7 +59,6 @@ describe('accounts', { tags: '@smoke' }, () => {
|
|||||||
cy.getByTestId('Collateral').click();
|
cy.getByTestId('Collateral').click();
|
||||||
const marketsSortedDefault = [
|
const marketsSortedDefault = [
|
||||||
'1,000.00002',
|
'1,000.00002',
|
||||||
'100,001.01',
|
|
||||||
'1,000.01',
|
'1,000.01',
|
||||||
'1,000.00',
|
'1,000.00',
|
||||||
'1,000.00001',
|
'1,000.00001',
|
||||||
@ -69,10 +68,8 @@ describe('accounts', { tags: '@smoke' }, () => {
|
|||||||
'1,000.00001',
|
'1,000.00001',
|
||||||
'1,000.00002',
|
'1,000.00002',
|
||||||
'1,000.01',
|
'1,000.01',
|
||||||
'100,001.01',
|
|
||||||
];
|
];
|
||||||
const marketsSortedDesc = [
|
const marketsSortedDesc = [
|
||||||
'100,001.01',
|
|
||||||
'1,000.01',
|
'1,000.01',
|
||||||
'1,000.00002',
|
'1,000.00002',
|
||||||
'1,000.00001',
|
'1,000.00001',
|
||||||
@ -90,7 +87,6 @@ describe('accounts', { tags: '@smoke' }, () => {
|
|||||||
cy.getByTestId('Collateral').click();
|
cy.getByTestId('Collateral').click();
|
||||||
const marketsSortedDefault = [
|
const marketsSortedDefault = [
|
||||||
'0.000.00%',
|
'0.000.00%',
|
||||||
'1.010.00%',
|
|
||||||
'0.010.00%',
|
'0.010.00%',
|
||||||
'0.000.00%',
|
'0.000.00%',
|
||||||
'0.000.00%',
|
'0.000.00%',
|
||||||
@ -100,10 +96,8 @@ describe('accounts', { tags: '@smoke' }, () => {
|
|||||||
'0.000.00%',
|
'0.000.00%',
|
||||||
'0.000.00%',
|
'0.000.00%',
|
||||||
'0.010.00%',
|
'0.010.00%',
|
||||||
'1.010.00%',
|
|
||||||
];
|
];
|
||||||
const marketsSortedDesc = [
|
const marketsSortedDesc = [
|
||||||
'1.010.00%',
|
|
||||||
'0.010.00%',
|
'0.010.00%',
|
||||||
'0.000.00%',
|
'0.000.00%',
|
||||||
'0.000.00%',
|
'0.000.00%',
|
||||||
@ -121,7 +115,6 @@ describe('accounts', { tags: '@smoke' }, () => {
|
|||||||
cy.getByTestId('Collateral').click();
|
cy.getByTestId('Collateral').click();
|
||||||
const marketsSortedDefault = [
|
const marketsSortedDefault = [
|
||||||
'1,000.00002',
|
'1,000.00002',
|
||||||
'100,001.01',
|
|
||||||
'1,000.01',
|
'1,000.01',
|
||||||
'1,000.00',
|
'1,000.00',
|
||||||
'1,000.00001',
|
'1,000.00001',
|
||||||
@ -131,10 +124,8 @@ describe('accounts', { tags: '@smoke' }, () => {
|
|||||||
'1,000.00001',
|
'1,000.00001',
|
||||||
'1,000.00002',
|
'1,000.00002',
|
||||||
'1,000.01',
|
'1,000.01',
|
||||||
'100,001.01',
|
|
||||||
];
|
];
|
||||||
const marketsSortedDesc = [
|
const marketsSortedDesc = [
|
||||||
'100,001.01',
|
|
||||||
'1,000.01',
|
'1,000.01',
|
||||||
'1,000.00002',
|
'1,000.00002',
|
||||||
'1,000.00001',
|
'1,000.00001',
|
||||||
|
@ -10,7 +10,6 @@ import type { AccountFields } from './accounts-data-provider';
|
|||||||
import { aggregatedAccountsDataProvider } from './accounts-data-provider';
|
import { aggregatedAccountsDataProvider } from './accounts-data-provider';
|
||||||
import type { PinnedAsset } from './accounts-table';
|
import type { PinnedAsset } from './accounts-table';
|
||||||
import { AccountTable } from './accounts-table';
|
import { AccountTable } from './accounts-table';
|
||||||
import type { RowHeightParams } from 'ag-grid-community';
|
|
||||||
|
|
||||||
interface AccountManagerProps {
|
interface AccountManagerProps {
|
||||||
partyId: string;
|
partyId: string;
|
||||||
@ -50,10 +49,6 @@ export const AccountManager = ({
|
|||||||
disabled: noBottomPlaceholder,
|
disabled: noBottomPlaceholder,
|
||||||
});
|
});
|
||||||
|
|
||||||
const getRowHeight = useCallback(
|
|
||||||
(params: RowHeightParams) => (params.node.rowPinned ? 32 : 22),
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<div className="relative h-full">
|
<div className="relative h-full">
|
||||||
<AccountTable
|
<AccountTable
|
||||||
@ -66,7 +61,6 @@ export const AccountManager = ({
|
|||||||
suppressLoadingOverlay
|
suppressLoadingOverlay
|
||||||
suppressNoRowsOverlay
|
suppressNoRowsOverlay
|
||||||
pinnedAsset={pinnedAsset}
|
pinnedAsset={pinnedAsset}
|
||||||
getRowHeight={getRowHeight}
|
|
||||||
{...bottomPlaceholderProps}
|
{...bottomPlaceholderProps}
|
||||||
/>
|
/>
|
||||||
<div className="pointer-events-none absolute inset-0">
|
<div className="pointer-events-none absolute inset-0">
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { forwardRef, useMemo, useState } from 'react';
|
import { forwardRef, useCallback, useMemo, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
addDecimalsFormatNumber,
|
addDecimalsFormatNumber,
|
||||||
isNumeric,
|
isNumeric,
|
||||||
@ -16,7 +16,12 @@ import {
|
|||||||
CenteredGridCellWrapper,
|
CenteredGridCellWrapper,
|
||||||
} from '@vegaprotocol/datagrid';
|
} from '@vegaprotocol/datagrid';
|
||||||
import { AgGridColumn } from 'ag-grid-react';
|
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 type { AgGridReact, AgGridReactProps } from 'ag-grid-react';
|
||||||
import BreakdownTable from './breakdown-table';
|
import BreakdownTable from './breakdown-table';
|
||||||
import type { AccountFields } from './accounts-data-provider';
|
import type { AccountFields } from './accounts-data-provider';
|
||||||
@ -108,17 +113,31 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return currentPinnedAssetRow;
|
||||||
}, [pinnedAssetId, props.pinnedAsset, props.rowData]);
|
}, [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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<AgGrid
|
<AgGrid
|
||||||
|
{...props}
|
||||||
style={{ width: '100%', height: '100%' }}
|
style={{ width: '100%', height: '100%' }}
|
||||||
overlayNoRowsTemplate={t('No accounts')}
|
overlayNoRowsTemplate={t('No accounts')}
|
||||||
getRowId={({ data }: { data: AccountFields }) => data.asset.id}
|
getRowId={({ data }: { data: AccountFields }) => data.asset.id}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
tooltipShowDelay={500}
|
tooltipShowDelay={500}
|
||||||
|
rowData={props.rowData?.filter(
|
||||||
|
(data) => data.asset.id !== pinnedAssetId
|
||||||
|
)}
|
||||||
defaultColDef={{
|
defaultColDef={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
@ -126,7 +145,7 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
|
|||||||
sortable: true,
|
sortable: true,
|
||||||
comparator: accountValuesComparator,
|
comparator: accountValuesComparator,
|
||||||
}}
|
}}
|
||||||
{...props}
|
getRowHeight={getRowHeight}
|
||||||
pinnedTopRowData={pinnedAssetRow ? [pinnedAssetRow] : undefined}
|
pinnedTopRowData={pinnedAssetRow ? [pinnedAssetRow] : undefined}
|
||||||
>
|
>
|
||||||
<AgGridColumn
|
<AgGridColumn
|
||||||
|
Loading…
Reference in New Issue
Block a user