Skip to content

Commit 80212a1

Browse files
authored
fix: optimize getAriaRowIndexMap performance (#98)
1 parent fefd3b0 commit 80212a1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

.github/workflows/pr-preview-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ jobs:
88
name: Build
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: gravity-ui/preview-build-action@v1
11+
- uses: gravity-ui/preview-build-action@v2
1212
with:
1313
node-version: 20

src/utils/getAriaRowIndexMap.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import type {Row} from '@tanstack/react-table';
22

33
export const getAriaRowIndexMap = <TData>(rows: Row<TData>[]) => {
4+
const map: Record<string, number> = {};
45
let rowIndex = 1;
56

6-
return rows.reduce<Record<string, number>>((acc, row, index, arr) => {
7-
const newMap = {
8-
...acc,
9-
[row.id]: rowIndex,
10-
};
7+
for (let i = 0; i < rows.length; i++) {
8+
const row = rows[i];
9+
const nextRow = rows[i + 1];
10+
11+
map[row.id] = rowIndex;
1112

12-
const nextRow = arr[index + 1];
1313
if (nextRow?.parentId !== row.id) {
1414
rowIndex += row.getLeafRows().length;
1515
}
1616
rowIndex++;
17+
}
1718

18-
return newMap;
19-
}, {});
19+
return map;
2020
};

0 commit comments

Comments
 (0)