fix: hide close button if openVolume is zero (#2768)

This commit is contained in:
Bartłomiej Głownia 2023-01-27 19:44:20 +01:00 committed by GitHub
parent 1e0e1c7859
commit b1280c8285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 8 deletions

View File

@ -172,3 +172,33 @@ it('displays realised and unrealised PNL', async () => {
expect(cells[9].textContent).toEqual('1.23'); expect(cells[9].textContent).toEqual('1.23');
expect(cells[10].textContent).toEqual('4.56'); expect(cells[10].textContent).toEqual('4.56');
}); });
it('displays close button', async () => {
await act(async () => {
render(
<PositionsTable
rowData={singleRowData}
onClose={() => {
return;
}}
/>
);
});
const cells = screen.getAllByRole('gridcell');
expect(cells[12].textContent).toEqual('Close');
});
it('do not display close button if openVolume is zero', async () => {
await act(async () => {
render(
<PositionsTable
rowData={[{ ...singleRow, openVolume: '0' }]}
onClose={() => {
return;
}}
/>
);
});
const cells = screen.getAllByRole('gridcell');
expect(cells[12].textContent).toEqual('');
});

View File

@ -381,14 +381,16 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
{onClose ? ( {onClose ? (
<AgGridColumn <AgGridColumn
type="rightAligned" type="rightAligned"
cellRenderer={({ data }: VegaICellRendererParams<Position>) => ( cellRenderer={({ data }: VegaICellRendererParams<Position>) =>
<ButtonLink data?.openVolume && data?.openVolume !== '0' ? (
data-testid="close-position" <ButtonLink
onClick={() => data && onClose(data)} data-testid="close-position"
> onClick={() => data && onClose(data)}
{t('Close')} >
</ButtonLink> {t('Close')}
)} </ButtonLink>
) : null
}
/> />
) : null} ) : null}
</AgGrid> </AgGrid>