fix(orders): re-render last column of orders table on data change (#3927)

This commit is contained in:
Bartłomiej Głownia 2023-05-25 11:37:53 +02:00 committed by GitHub
parent f5e67a0c2d
commit 6b50816234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 31 deletions

View File

@ -145,8 +145,8 @@ export const OrderListManager = ({
ref={gridRef} ref={gridRef}
filter={filter} filter={filter}
onGridReady={onGridReady} onGridReady={onGridReady}
cancel={cancel} onCancel={cancel}
setEditOrder={setEditOrder} onEdit={setEditOrder}
onMarketClick={onMarketClick} onMarketClick={onMarketClick}
onOrderTypeClick={onOrderTypeClick} onOrderTypeClick={onOrderTypeClick}
onFilterChanged={onFilterChanged} onFilterChanged={onFilterChanged}

View File

@ -25,8 +25,8 @@ jest.mock('@vegaprotocol/react-helpers', () => ({
const defaultProps: OrderListTableProps = { const defaultProps: OrderListTableProps = {
rowData: [], rowData: [],
setEditOrder: jest.fn(), onEdit: jest.fn(),
cancel: jest.fn(), onCancel: jest.fn(),
isReadOnly: false, isReadOnly: false,
}; };
@ -154,8 +154,8 @@ describe('OrderListTable', () => {
render( render(
generateJsx({ generateJsx({
rowData: [order], rowData: [order],
setEditOrder: mockEdit, onEdit: mockEdit,
cancel: mockCancel, onCancel: mockCancel,
}) })
); );
}); });
@ -179,8 +179,8 @@ describe('OrderListTable', () => {
render( render(
generateJsx({ generateJsx({
rowData: [order], rowData: [order],
setEditOrder: mockEdit, onEdit: mockEdit,
cancel: mockCancel, onCancel: mockCancel,
isReadOnly: true, isReadOnly: true,
}) })
); );

View File

@ -18,8 +18,8 @@ const Template: Story = (args) => {
<div style={{ height: 1000 }}> <div style={{ height: 1000 }}>
<OrderListTable <OrderListTable
rowData={args.data} rowData={args.data}
cancel={cancel} onCancel={cancel}
setEditOrder={() => { onEdit={() => {
return; return;
}} }}
isReadOnly={false} isReadOnly={false}
@ -47,8 +47,8 @@ const Template2: Story = (args) => {
<div style={{ height: 1000 }}> <div style={{ height: 1000 }}>
<OrderListTable <OrderListTable
rowData={args.data} rowData={args.data}
cancel={cancel} onCancel={cancel}
setEditOrder={setEditOrder} onEdit={setEditOrder}
isReadOnly={false} isReadOnly={false}
/> />
</div> </div>

View File

@ -32,8 +32,8 @@ import { Filter } from '../order-list-manager';
export type OrderListTableProps = TypedDataAgGrid<Order> & { export type OrderListTableProps = TypedDataAgGrid<Order> & {
marketId?: string; marketId?: string;
cancel: (order: Order) => void; onCancel: (order: Order) => void;
setEditOrder: (order: Order) => void; onEdit: (order: Order) => void;
onMarketClick?: (marketId: string, metaKey?: boolean) => void; onMarketClick?: (marketId: string, metaKey?: boolean) => void;
onOrderTypeClick?: (marketId: string, metaKey?: boolean) => void; onOrderTypeClick?: (marketId: string, metaKey?: boolean) => void;
filter?: Filter; filter?: Filter;
@ -46,14 +46,7 @@ export const OrderListTable = memo<
>( >(
forwardRef<AgGridReact, OrderListTableProps>( forwardRef<AgGridReact, OrderListTableProps>(
( (
{ { onCancel, onEdit, onMarketClick, onOrderTypeClick, filter, ...props },
cancel,
setEditOrder,
onMarketClick,
onOrderTypeClick,
filter,
...props
},
ref ref
) => { ) => {
const showAllActions = const showAllActions =
@ -275,15 +268,11 @@ export const OrderListTable = memo<
/> />
<AgGridColumn <AgGridColumn
colId="amend" colId="amend"
field="id"
{...COL_DEFS.actions} {...COL_DEFS.actions}
minWidth={showAllActions ? 120 : COL_DEFS.actions.minWidth} minWidth={showAllActions ? 120 : COL_DEFS.actions.minWidth}
maxWidth={showAllActions ? 120 : COL_DEFS.actions.minWidth} maxWidth={showAllActions ? 120 : COL_DEFS.actions.minWidth}
cellRenderer={({ cellRenderer={({ data }: { data?: Order }) => {
data, if (!data) return null;
value,
}: VegaICellRendererParams<Order, 'id'>) => {
if (!value || !data) return null;
return ( return (
<div className="flex gap-2 items-center justify-end"> <div className="flex gap-2 items-center justify-end">
@ -291,19 +280,19 @@ export const OrderListTable = memo<
<> <>
<ButtonLink <ButtonLink
data-testid="edit" data-testid="edit"
onClick={() => setEditOrder(data)} onClick={() => onEdit(data)}
> >
{t('Edit')} {t('Edit')}
</ButtonLink> </ButtonLink>
<ButtonLink <ButtonLink
data-testid="cancel" data-testid="cancel"
onClick={() => cancel(data)} onClick={() => onCancel(data)}
> >
{t('Cancel')} {t('Cancel')}
</ButtonLink> </ButtonLink>
</> </>
)} )}
<OrderActionsDropdown id={value} /> <OrderActionsDropdown id={data?.id} />
</div> </div>
); );
}} }}