Skip to content

Commit 601c889

Browse files
authored
simplify table rendering (no more pinned rows nonsense) to fix #2513 (#2561)
1 parent 6c4744b commit 601c889

3 files changed

Lines changed: 17 additions & 33 deletions

File tree

frontend/app/view/preview/preview-directory.tsx

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
import clsx from "clsx";
2626
import { PrimitiveAtom, atom, useAtom, useAtomValue, useSetAtom } from "jotai";
2727
import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overlayscrollbars-react";
28-
import React, { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
28+
import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
2929
import { useDrag, useDrop } from "react-dnd";
3030
import { quote as shellQuote } from "shell-quote";
3131
import { debounce } from "throttle-debounce";
@@ -225,10 +225,6 @@ function DirectoryTable({
225225
columnVisibility: {
226226
path: false,
227227
},
228-
rowPinning: {
229-
top: [],
230-
bottom: [],
231-
},
232228
},
233229
enableMultiSort: false,
234230
enableSortingRemoval: false,
@@ -240,29 +236,10 @@ function DirectoryTable({
240236
});
241237

242238
useEffect(() => {
243-
const topRows = table.getTopRows() || [];
244-
const centerRows = table.getCenterRows() || [];
245-
const allRows = [...topRows, ...centerRows];
239+
const allRows = table.getRowModel()?.flatRows || [];
246240
setSelectedPath((allRows[focusIndex]?.getValue("path") as string) ?? null);
247241
}, [table, focusIndex, data]);
248242

249-
useLayoutEffect(() => {
250-
const rows = table.getRowModel()?.flatRows;
251-
let foundParentDir = false;
252-
253-
for (const row of rows) {
254-
if (row.getValue("name") == "..") {
255-
row.pin("top");
256-
foundParentDir = true;
257-
break;
258-
}
259-
}
260-
261-
// If we didn't find the ".." row, reset the pinning to avoid stale references
262-
if (!foundParentDir) {
263-
table.resetRowPinning();
264-
}
265-
}, [table, data]);
266243
const columnSizeVars = useMemo(() => {
267244
const headers = table.getFlatHeaders();
268245
const colSizes: { [key: string]: number } = {};
@@ -447,6 +424,10 @@ function TableBody({
447424
[setRefreshVersion, conn]
448425
);
449426

427+
const allRows = table.getRowModel().flatRows;
428+
const dotdotRow = allRows.find((row) => row.getValue("name") === "..");
429+
const otherRows = allRows.filter((row) => row.getValue("name") !== "..");
430+
450431
return (
451432
<div className="dir-table-body" ref={bodyRef}>
452433
{(searchActive || search !== "") && (
@@ -473,28 +454,28 @@ function TableBody({
473454
<div className="dummy dir-table-body-row" ref={dummyLineRef}>
474455
<div className="dir-table-body-cell">dummy-data</div>
475456
</div>
476-
{table.getTopRows().map((row, idx) => (
457+
{dotdotRow && (
477458
<TableRow
478459
model={model}
479-
row={row}
460+
row={dotdotRow}
480461
focusIndex={focusIndex}
481462
setFocusIndex={setFocusIndex}
482463
setSearch={setSearch}
483-
idx={idx}
464+
idx={0}
484465
handleFileContextMenu={handleFileContextMenu}
485-
key={"top-" + idx}
466+
key="dotdot"
486467
/>
487-
))}
488-
{table.getCenterRows().map((row, idx) => (
468+
)}
469+
{otherRows.map((row, idx) => (
489470
<TableRow
490471
model={model}
491472
row={row}
492473
focusIndex={focusIndex}
493474
setFocusIndex={setFocusIndex}
494475
setSearch={setSearch}
495-
idx={idx + table.getTopRows().length}
476+
idx={dotdotRow ? idx + 1 : idx}
496477
handleFileContextMenu={handleFileContextMenu}
497-
key={"center" + idx}
478+
key={idx}
498479
/>
499480
))}
500481
</div>

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ require (
8080
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
8181
github.com/mailru/easyjson v0.7.7 // indirect
8282
github.com/mattn/go-isatty v0.0.20 // indirect
83+
github.com/outrigdev/goid v0.3.0 // indirect
8384
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
8485
github.com/rivo/uniseg v0.4.7 // indirect
8586
github.com/sirupsen/logrus v1.9.3 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuE
144144
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
145145
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
146146
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
147+
github.com/outrigdev/goid v0.3.0 h1:t/otQD3EXc45cLtQVPUnNgEyRaTQA4cPeu3qVcrsIws=
148+
github.com/outrigdev/goid v0.3.0/go.mod h1:hEH7f27ypN/GHWt/7gvkRoFYR0LZizfUBIAbak4neVE=
147149
github.com/photostorm/pty v1.1.19-0.20230903182454-31354506054b h1:cLGKfKb1uk0hxI0Q8L83UAJPpeJ+gSpn3cCU/tjd3eg=
148150
github.com/photostorm/pty v1.1.19-0.20230903182454-31354506054b/go.mod h1:KO+FcPtyLAiRC0hJwreJVvfwc7vnNz77UxBTIGHdPVk=
149151
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=

0 commit comments

Comments
 (0)