fix(trading): lp table forward ref breaking resize grid (#4447)

This commit is contained in:
Matthew Russell 2023-08-02 13:59:05 +01:00 committed by GitHub
parent 76a6005b77
commit d18a0c7e15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 154 additions and 163 deletions

View File

@ -12,10 +12,9 @@ import {
NetworkParams, NetworkParams,
useNetworkParams, useNetworkParams,
} from '@vegaprotocol/network-parameters'; } from '@vegaprotocol/network-parameters';
import type { AgGridReact } from 'ag-grid-react';
import type { DataGridSlice } from '../../stores/datagrid-store-slice'; import type { DataGridSlice } from '../../stores/datagrid-store-slice';
import { createDataGridSlice } from '../../stores/datagrid-store-slice'; import { createDataGridSlice } from '../../stores/datagrid-store-slice';
import { useEffect, useRef } from 'react'; import { useEffect } from 'react';
import { create } from 'zustand'; import { create } from 'zustand';
import { persist } from 'zustand/middleware'; import { persist } from 'zustand/middleware';
@ -26,8 +25,6 @@ export const LiquidityContainer = ({
marketId: string | undefined; marketId: string | undefined;
filter?: Filter; filter?: Filter;
}) => { }) => {
const gridRef = useRef<AgGridReact | null>(null);
const gridStore = useLiquidityStore((store) => store.gridStore); const gridStore = useLiquidityStore((store) => store.gridStore);
const updateGridStore = useLiquidityStore((store) => store.updateGridStore); const updateGridStore = useLiquidityStore((store) => store.updateGridStore);
@ -60,7 +57,6 @@ export const LiquidityContainer = ({
return ( return (
<div className="h-full relative"> <div className="h-full relative">
<LiquidityTable <LiquidityTable
ref={gridRef}
rowData={data} rowData={data}
symbol={symbol} symbol={symbol}
assetDecimalPlaces={assetDecimalPlaces} assetDecimalPlaces={assetDecimalPlaces}

View File

@ -1,4 +1,4 @@
import { forwardRef, useMemo } from 'react'; import { useMemo } from 'react';
import { import {
addDecimalsFormatNumber, addDecimalsFormatNumber,
addDecimalsFormatNumberQuantum, addDecimalsFormatNumberQuantum,
@ -9,7 +9,6 @@ import { t } from '@vegaprotocol/i18n';
import type { TypedDataAgGrid } from '@vegaprotocol/datagrid'; import type { TypedDataAgGrid } from '@vegaprotocol/datagrid';
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid'; import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
import { TooltipCellComponent } from '@vegaprotocol/ui-toolkit'; import { TooltipCellComponent } from '@vegaprotocol/ui-toolkit';
import type { AgGridReact } from 'ag-grid-react';
import type { import type {
ColDef, ColDef,
ITooltipParams, ITooltipParams,
@ -40,20 +39,20 @@ export interface LiquidityTableProps
quantum?: string | number; quantum?: string | number;
} }
export const LiquidityTable = forwardRef<AgGridReact, LiquidityTableProps>( export const LiquidityTable = ({
( symbol = '',
{ symbol = '', assetDecimalPlaces, stakeToCcyVolume, quantum, ...props }, assetDecimalPlaces,
ref stakeToCcyVolume,
) => { quantum,
...props
}: LiquidityTableProps) => {
const colDefs = useMemo(() => { const colDefs = useMemo(() => {
const assetDecimalsFormatter = ({ value }: ITooltipParams) => { const assetDecimalsFormatter = ({ value }: ITooltipParams) => {
if (!value) return '-'; if (!value) return '-';
return `${addDecimalsFormatNumber(value, assetDecimalPlaces ?? 0)}`; return `${addDecimalsFormatNumber(value, assetDecimalPlaces ?? 0)}`;
}; };
const assetDecimalsQuantumFormatter = ({ const assetDecimalsQuantumFormatter = ({ value }: ValueFormatterParams) => {
value,
}: ValueFormatterParams) => {
if (!value) return '-'; if (!value) return '-';
return `${addDecimalsFormatNumberQuantum( return `${addDecimalsFormatNumberQuantum(
value, value,
@ -88,9 +87,7 @@ export const LiquidityTable = forwardRef<AgGridReact, LiquidityTableProps>(
{ {
headerName: t('Party'), headerName: t('Party'),
field: 'party.id', field: 'party.id',
headerTooltip: t( headerTooltip: t('The public key of the party making this commitment.'),
'The public key of the party making this commitment.'
),
}, },
{ {
headerName: t(`Commitment (${symbol})`), headerName: t(`Commitment (${symbol})`),
@ -189,7 +186,6 @@ export const LiquidityTable = forwardRef<AgGridReact, LiquidityTableProps>(
style={{ width: '100%', height: '100%' }} style={{ width: '100%', height: '100%' }}
overlayNoRowsTemplate={t('No liquidity provisions')} overlayNoRowsTemplate={t('No liquidity provisions')}
getRowId={({ data }: { data: LiquidityProvisionData }) => data.id || ''} getRowId={({ data }: { data: LiquidityProvisionData }) => data.id || ''}
ref={ref}
tooltipShowDelay={500} tooltipShowDelay={500}
defaultColDef={{ defaultColDef={{
resizable: true, resizable: true,
@ -201,7 +197,6 @@ export const LiquidityTable = forwardRef<AgGridReact, LiquidityTableProps>(
columnDefs={colDefs} columnDefs={colDefs}
/> />
); );
} };
);
export default LiquidityTable; export default LiquidityTable;