Skip to content

Commit 3c9dfb5

Browse files
authored
Merge pull request #19 from filecoin-saturn/improve-grid-readability
improve grid readability
2 parents 9142a99 + f5b9a55 commit 3c9dfb5

File tree

2 files changed

+60
-63
lines changed

2 files changed

+60
-63
lines changed

src/components/StatsGrid/StatsGrid.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,18 @@ export default function StatsGrid() {
2020
[setGridApi, setColumnApi]
2121
);
2222

23-
const onGridSizeChanged = useCallback(() => {
24-
if (gridApi) {
25-
gridApi.sizeColumnsToFit();
23+
const autoSizeAllColumns = useCallback(() => {
24+
if (columnApi) {
25+
columnApi.autoSizeAllColumns();
2626
}
27-
}, [gridApi]);
27+
}, [columnApi]);
2828

2929
useEffect(() => {
30-
if (gridApi && columnApi) {
30+
if (columnApi) {
3131
columnApi.setColumnsVisible(["operator"], Boolean(state.authorizationToken));
32-
gridApi.sizeColumnsToFit();
32+
columnApi.autoSizeAllColumns();
3333
}
34-
}, [columnApi, gridApi, state.authorizationToken]);
35-
36-
useEffect(() => {
37-
if (gridApi && state.nodes) {
38-
gridApi.sizeColumnsToFit();
39-
}
40-
}, [gridApi, state.nodes]);
34+
}, [columnApi, state.authorizationToken]);
4135

4236
useEffect(() => {
4337
if (gridApi && columnApi && location.state) {
@@ -63,7 +57,9 @@ export default function StatsGrid() {
6357
enableCellTextSelection={true}
6458
ensureDomOrder={true}
6559
suppressColumnVirtualisation={true}
66-
onGridSizeChanged={onGridSizeChanged}
60+
onModelUpdated={autoSizeAllColumns}
61+
onGridSizeChanged={autoSizeAllColumns}
62+
onFirstDataRendered={autoSizeAllColumns}
6763
getRowId={(params) => params.data.id}
6864
onGridReady={onGridReady}
6965
tooltipShowDelay={0}

src/components/StatsGrid/StatsGridConfig.tsx

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,56 @@ export const columnDefs = [
171171
];
172172
},
173173
},
174+
{
175+
field: "bias",
176+
headerName: "Weight",
177+
sortable: true,
178+
filter: "agNumberColumnFilter",
179+
floatingFilter: true,
180+
minWidth: 100,
181+
cellRenderer: (params: any) => {
182+
return (
183+
<>
184+
<div
185+
className={classNames("overflow-clip text-ellipsis", {
186+
"font-bold text-red-500": params.data.bias < -90,
187+
"text-red-500": params.data.bias >= -90 && params.data.bias < -60,
188+
"text-orange-500": params.data.bias >= -60 && params.data.bias < -30,
189+
"text-yellow-500": params.data.bias >= -30 && params.data.bias < 0,
190+
})}
191+
>
192+
{params.data.bias}
193+
</div>
194+
{params.data.HealthCheckFailures.length > 0 && (
195+
<div
196+
className={classNames("overflow-clip text-ellipsis", {
197+
"text-red-500": params.data.HealthCheckFailures.length >= 4,
198+
"text-orange-500": params.data.HealthCheckFailures.length < 4,
199+
})}
200+
>
201+
{params.data.HealthCheckFailures.length} fail{params.data.HealthCheckFailures.length > 1 && "s"} / last
202+
24h
203+
</div>
204+
)}
205+
</>
206+
);
207+
},
208+
tooltipComponent: HTMLTooltip,
209+
tooltipComponentParams: { className: "capitalize" },
210+
tooltipValueGetter: ({ data }: any) => {
211+
const biases = asStrings(data.biases, (key: string, value: any) => value);
212+
213+
if (data.HealthCheckFailures.length) {
214+
const fails = `${data.HealthCheckFailures.length} fail${
215+
data.HealthCheckFailures.length > 1 ? "s" : ""
216+
} in last 24 hours`;
217+
218+
return [...biases, "<hr />", fails];
219+
}
220+
221+
return biases;
222+
},
223+
},
174224
{
175225
field: "diskStats.usedDisk",
176226
headerName: "Disk Usage",
@@ -433,55 +483,6 @@ export const columnDefs = [
433483
);
434484
},
435485
},
436-
{
437-
field: "bias",
438-
headerName: "Weight",
439-
sortable: true,
440-
filter: "agNumberColumnFilter",
441-
floatingFilter: true,
442-
cellRenderer: (params: any) => {
443-
return (
444-
<>
445-
<div
446-
className={classNames("overflow-clip text-ellipsis", {
447-
"font-bold text-red-500": params.data.bias < -90,
448-
"text-red-500": params.data.bias >= -90 && params.data.bias < -60,
449-
"text-orange-500": params.data.bias >= -60 && params.data.bias < -30,
450-
"text-yellow-500": params.data.bias >= -30 && params.data.bias < 0,
451-
})}
452-
>
453-
{params.data.bias}
454-
</div>
455-
{params.data.HealthCheckFailures.length > 0 && (
456-
<div
457-
className={classNames("overflow-clip text-ellipsis", {
458-
"text-red-500": params.data.HealthCheckFailures.length >= 4,
459-
"text-orange-500": params.data.HealthCheckFailures.length < 4,
460-
})}
461-
>
462-
{params.data.HealthCheckFailures.length} fail{params.data.HealthCheckFailures.length > 1 && "s"} / last
463-
24h
464-
</div>
465-
)}
466-
</>
467-
);
468-
},
469-
tooltipComponent: HTMLTooltip,
470-
tooltipComponentParams: { className: "capitalize" },
471-
tooltipValueGetter: ({ data }: any) => {
472-
const biases = asStrings(data.biases, (key: string, value: any) => value);
473-
474-
if (data.HealthCheckFailures.length) {
475-
const fails = `${data.HealthCheckFailures.length} fail${
476-
data.HealthCheckFailures.length > 1 ? "s" : ""
477-
} in last 24 hours`;
478-
479-
return [...biases, "<hr />", fails];
480-
}
481-
482-
return biases;
483-
},
484-
},
485486
{
486487
field: "operator",
487488
headerName: "Operator",

0 commit comments

Comments
 (0)