Skip to content

Commit 96331b5

Browse files
authored
Fix table toolbar and scrolling (#465)
* fix table toolbar and scrolling * add node port in node details page * add DNS, IP, port in leaderboard table * change IP field
1 parent 28995e3 commit 96331b5

4 files changed

Lines changed: 95 additions & 56 deletions

File tree

src/components/node-details/node-info.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,15 @@ const NodeInfo: React.FC<NodeInfoProps> = ({ envs, node, nodeOnline }) => {
190190

191191
const renderNodeIpAndDns = () => {
192192
const location: string[] = [];
193-
if (node.location?.ip) {
194-
location.push(node.location.ip);
193+
if (node.ipAndDns?.ip) {
194+
location.push(node.ipAndDns.ip);
195195
}
196196
if (node.ipAndDns?.dns) {
197197
location.push(node.ipAndDns.dns);
198198
}
199+
if (node.ipAndDns?.port || node.ipAndDns?.port === 0) {
200+
location.push(`Port ${node.ipAndDns.port}`);
201+
}
199202
if (location.length > 0) {
200203
return location.join(' / ');
201204
}
@@ -244,7 +247,6 @@ const NodeInfo: React.FC<NodeInfoProps> = ({ envs, node, nodeOnline }) => {
244247
{node.platform?.osType ? <div>{node.platform?.osType}</div> : <div>Unknown</div>}
245248
</>
246249
}
247-
248250
<LocationPinIcon className={styles.icon} />
249251
<div>{renderNodeLocation()}</div>
250252
</div>

src/components/table/columns.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,31 @@ export const nodesLeaderboardColumns: GridColDef<Node>[] = [
163163
),
164164
renderCell: (params) => params.value || <span className="textSecondary">Unknown</span>,
165165
},
166+
167+
{
168+
field: 'ipAndDns.dns',
169+
filterable: false,
170+
flex: 1,
171+
headerName: 'DNS',
172+
sortable: false,
173+
valueGetter: (_value, row) => row.ipAndDns?.dns,
174+
},
175+
{
176+
field: 'ipAndDns.ip',
177+
filterable: false,
178+
flex: 1,
179+
headerName: 'IP',
180+
sortable: true,
181+
valueGetter: (_value, row) => row.ipAndDns?.ip,
182+
},
183+
{
184+
field: 'ipAndDns.port',
185+
filterable: false,
186+
flex: 1,
187+
headerName: 'Port',
188+
sortable: true,
189+
valueGetter: (_value, row) => row.ipAndDns?.port,
190+
},
166191
{
167192
align: 'right',
168193
field: 'actions',
@@ -176,6 +201,12 @@ export const nodesLeaderboardColumns: GridColDef<Node>[] = [
176201
},
177202
];
178203

204+
export const NodesLeaderboardColumnsVisibility = {
205+
'ipAndDns.dns': false,
206+
'ipAndDns.ip': false,
207+
'ipAndDns.port': false,
208+
};
209+
179210
export const nodesLeaderboardHomeColumns: GridColDef<Node>[] = [
180211
{
181212
field: 'friendlyName',

src/components/table/table.tsx

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
benchmarkJobsColumns,
33
jobsColumns,
44
nodesLeaderboardColumns,
5+
NodesLeaderboardColumnsVisibility,
56
nodesLeaderboardHomeColumns,
67
nodesTopByJobCountColumns,
78
nodesTopByRevenueColumns,
@@ -11,7 +12,7 @@ import {
1112
} from '@/components/table/columns';
1213
import { TableContextType } from '@/components/table/context-type';
1314
import CustomPagination from '@/components/table/custom-pagination';
14-
import CustomToolbar from '@/components/table/custom-toolbar';
15+
import CustomToolbar, { CustomToolbarProps } from '@/components/table/custom-toolbar';
1516
import { TableTypeEnum } from '@/components/table/table-type';
1617
import styled from '@emotion/styled';
1718
import {
@@ -25,8 +26,8 @@ import {
2526
GridValidRowModel,
2627
useGridApiRef,
2728
} from '@mui/x-data-grid';
28-
import { GridSlotsComponentsProps } from '@mui/x-data-grid/internals';
29-
import { useCallback, useMemo, useRef, useState } from 'react';
29+
import { GridSlotsComponentsProps, GridToolbarProps } from '@mui/x-data-grid/internals';
30+
import { JSXElementConstructor, useCallback, useMemo, useRef, useState } from 'react';
3031

3132
const StyledRoot = styled('div')({
3233
display: 'flex',
@@ -44,16 +45,9 @@ const StyledDataGridWrapper = styled('div')<{ autoHeight?: boolean }>(({ autoHei
4445
},
4546
}));
4647

47-
const StyledScrollWrapper = styled('div')({
48-
overflowX: 'auto',
49-
WebkitOverflowScrolling: 'touch',
50-
width: '100%',
51-
});
52-
5348
const StyledDataGrid = styled(DataGrid)<{ clickable?: boolean }>(({ clickable }) => ({
5449
background: 'none',
5550
border: 'none',
56-
minWidth: 600,
5751
borderBottom: '1px solid var(--border)',
5852
borderRadius: 0,
5953
color: 'var(--text-primary)',
@@ -209,6 +203,17 @@ export const Table = <T extends GridValidRowModel>({
209203
}
210204
}, [tableType]);
211205

206+
const columnVisibilityModel = useMemo(() => {
207+
switch (tableType) {
208+
case TableTypeEnum.NODES_LEADERBOARD: {
209+
return NodesLeaderboardColumnsVisibility;
210+
}
211+
default: {
212+
return undefined;
213+
}
214+
}
215+
}, [tableType]);
216+
212217
const handlePaginationChange = useCallback(
213218
(model: { page: number; pageSize: number }) => {
214219
if (paginationType === 'context' && context) {
@@ -292,7 +297,7 @@ export const Table = <T extends GridValidRowModel>({
292297
}, []);
293298

294299
const initialState = useMemo(() => {
295-
const coreState: GridInitialState = { density: 'standard' };
300+
const coreState: GridInitialState = { density: 'standard', columns: { columnVisibilityModel } };
296301
return paginationType === 'none'
297302
? coreState
298303
: {
@@ -304,7 +309,7 @@ export const Table = <T extends GridValidRowModel>({
304309
},
305310
},
306311
};
307-
}, [currentPage, pageSize, paginationType]);
312+
}, [columnVisibilityModel, currentPage, pageSize, paginationType]);
308313

309314
const paginationModel =
310315
paginationType === 'none'
@@ -314,7 +319,7 @@ export const Table = <T extends GridValidRowModel>({
314319
pageSize: pageSize,
315320
};
316321

317-
const slotProps: GridSlotsComponentsProps = {
322+
const slotProps: GridSlotsComponentsProps & { toolbar: Partial<CustomToolbarProps> } = {
318323
basePopper: {
319324
style: {
320325
color: '#000000',
@@ -324,53 +329,52 @@ export const Table = <T extends GridValidRowModel>({
324329
variant: 'skeleton',
325330
noRowsVariant: 'skeleton',
326331
},
332+
toolbar: {
333+
searchTerm,
334+
onSearchChange: handleSearchChange,
335+
onReset: handleResetFilters,
336+
tableType: tableType,
337+
apiRef: apiRef.current ?? undefined,
338+
// totalUptime: totalUptime,
339+
},
327340
};
328341

329342
const defaultGetRowId: GridRowIdGetter<GridValidRowModel> = (row) => row.id;
330343

331344
return (
332345
<StyledRoot>
333-
{showToolbar && (
334-
<CustomToolbar
335-
searchTerm={searchTerm}
336-
onSearchChange={handleSearchChange}
337-
onSearch={() => {}}
338-
onReset={handleResetFilters}
339-
tableType={tableType}
340-
apiRef={apiRef.current ?? undefined}
341-
totalUptime={null}
346+
<StyledDataGridWrapper autoHeight={autoHeight}>
347+
<StyledDataGrid
348+
apiRef={apiRef}
349+
clickable={!!onRowClick}
350+
columns={(columns as GridColDef<GridValidRowModel>[]).map((col) => ({
351+
minWidth: col.width ?? 120,
352+
...col,
353+
}))}
354+
disableColumnMenu
355+
disableRowSelectionOnClick
356+
filterMode={paginationType === 'none' ? 'client' : 'server'}
357+
getRowId={getRowId ?? defaultGetRowId}
358+
hideFooter
359+
initialState={initialState}
360+
loading={loading ?? context?.loading}
361+
onFilterModelChange={handleFilterModelChange}
362+
onPaginationModelChange={handlePaginationChange}
363+
onRowClick={onRowClick}
364+
onSortModelChange={handleSortModelChange}
365+
pageSizeOptions={[10, 25, 50, 100]}
366+
// pagination
367+
paginationMode={paginationType === 'none' ? undefined : 'server'}
368+
paginationModel={paginationModel}
369+
processRowUpdate={processRowUpdate}
370+
rowCount={totalItems}
371+
rows={data}
372+
showToolbar={showToolbar}
373+
slots={{ toolbar: CustomToolbar as JSXElementConstructor<GridToolbarProps> }}
374+
slotProps={slotProps}
375+
sortingMode={paginationType === 'none' ? 'client' : 'server'}
342376
/>
343-
)}
344-
<StyledScrollWrapper>
345-
<StyledDataGridWrapper autoHeight={autoHeight}>
346-
<StyledDataGrid
347-
apiRef={apiRef}
348-
clickable={!!onRowClick}
349-
columns={columns as GridColDef<GridValidRowModel>[]}
350-
disableColumnMenu
351-
disableRowSelectionOnClick
352-
filterMode={paginationType === 'none' ? 'client' : 'server'}
353-
getRowId={getRowId ?? defaultGetRowId}
354-
hideFooter
355-
initialState={initialState}
356-
loading={loading ?? context?.loading}
357-
onFilterModelChange={handleFilterModelChange}
358-
onPaginationModelChange={handlePaginationChange}
359-
onRowClick={onRowClick}
360-
onSortModelChange={handleSortModelChange}
361-
pageSizeOptions={[10, 25, 50, 100]}
362-
// pagination
363-
paginationMode={paginationType === 'none' ? undefined : 'server'}
364-
paginationModel={paginationModel}
365-
processRowUpdate={processRowUpdate}
366-
rowCount={totalItems}
367-
rows={data}
368-
slots={{}}
369-
slotProps={slotProps}
370-
sortingMode={paginationType === 'none' ? 'client' : 'server'}
371-
/>
372-
</StyledDataGridWrapper>
373-
</StyledScrollWrapper>
377+
</StyledDataGridWrapper>
374378
{paginationType === 'none' ? null : (
375379
<CustomPagination
376380
page={currentPage}

src/types/nodes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export type Node = {
3434
id?: string;
3535
indexer?: Array<{ network: string }>;
3636
ipAndDns?: {
37+
ip: string;
3738
dns: string;
39+
port: number;
3840
};
3941
latestBenchmarkResults: {
4042
gpuScore: number;

0 commit comments

Comments
 (0)