From 24c25600022366add30bc54818cf07daa8df7cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Mon, 26 Jun 2023 16:42:19 +0200 Subject: [PATCH] chore: use columnDefs in explorer MarketsTable --- .../app/components/assets/assets-table.tsx | 3 +- .../app/components/markets/markets-table.tsx | 130 +++++++++--------- 2 files changed, 69 insertions(+), 64 deletions(-) diff --git a/apps/explorer/src/app/components/assets/assets-table.tsx b/apps/explorer/src/app/components/assets/assets-table.tsx index 458fb1c9e..fb245be95 100644 --- a/apps/explorer/src/app/components/assets/assets-table.tsx +++ b/apps/explorer/src/app/components/assets/assets-table.tsx @@ -4,13 +4,12 @@ import { AssetTypeMapping, AssetStatusMapping } from '@vegaprotocol/assets'; import { t } from '@vegaprotocol/i18n'; import { ButtonLink } from '@vegaprotocol/ui-toolkit'; import type { AgGridReact } from 'ag-grid-react'; -import type { ColDef } from 'ag-grid-community'; import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid'; import type { VegaICellRendererParams } from '@vegaprotocol/datagrid'; import { useRef, useLayoutEffect } from 'react'; import { BREAKPOINT_MD } from '../../config/breakpoints'; import { useNavigate } from 'react-router-dom'; -import type { RowClickedEvent } from 'ag-grid-community'; +import type { RowClickedEvent, ColDef } from 'ag-grid-community'; type AssetsTableProps = { data: AssetFieldsFragment[] | null; diff --git a/apps/explorer/src/app/components/markets/markets-table.tsx b/apps/explorer/src/app/components/markets/markets-table.tsx index a28a36161..32665f6d2 100644 --- a/apps/explorer/src/app/components/markets/markets-table.tsx +++ b/apps/explorer/src/app/components/markets/markets-table.tsx @@ -1,8 +1,9 @@ +import { useMemo } from 'react'; import type { MarketFieldsFragment } from '@vegaprotocol/markets'; import { t } from '@vegaprotocol/i18n'; import { ButtonLink } from '@vegaprotocol/ui-toolkit'; import type { AgGridReact } from 'ag-grid-react'; -import { AgGridColumn } from 'ag-grid-react'; +import type { ColDef } from 'ag-grid-community'; import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid'; import type { VegaICellRendererParams, @@ -39,54 +40,34 @@ export const MarketsTable = ({ data }: MarketsTableProps) => { }; }, []); - return ( - data.id} - overlayNoRowsTemplate={t('This chain has no markets')} - domLayout="autoHeight" - defaultColDef={{ - flex: 1, - resizable: true, - sortable: true, - filter: true, - filterParams: { buttons: ['reset'] }, - autoHeight: true, - }} - suppressCellFocus={true} - onRowClicked={({ data, event }: RowClickedEvent) => { - if ((event?.target as HTMLElement).tagName.toUpperCase() !== 'BUTTON') { - navigate(data.id); - } - }} - > - - - ( + () => [ + { + colId: 'code', + headerName: t('Code'), + field: 'tradableInstrument.instrument.code', + }, + { + colId: 'name', + headerName: t('Name'), + field: 'tradableInstrument.instrument.name', + }, + { + headerName: t('Status'), + field: 'state', + hide: window.innerWidth <= BREAKPOINT_MD, + valueGetter: ({ data, }: VegaValueGetterParams) => { return data?.state ? MarketStateMapping[data?.state] : '-'; - }} - /> - { ) : ( '' ); - }} - /> - - ) => value ? ( @@ -126,9 +107,34 @@ export const MarketsTable = ({ data }: MarketsTableProps) => { ) : ( '' - ) + ), + }, + ], + [openAssetDetailsDialog] + ); + + return ( + data.id} + overlayNoRowsTemplate={t('This chain has no markets')} + domLayout="autoHeight" + defaultColDef={{ + flex: 1, + resizable: true, + sortable: true, + filter: true, + filterParams: { buttons: ['reset'] }, + autoHeight: true, + }} + columnDefs={columnDefs} + suppressCellFocus={true} + onRowClicked={({ data, event }: RowClickedEvent) => { + if ((event?.target as HTMLElement).tagName.toUpperCase() !== 'BUTTON') { + navigate(data.id); } - /> - + }} + /> ); };