Skip to content

Commit

Permalink
fix: optimize getAriaRowIndexMap performance (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
astandrik authored Feb 4, 2025
1 parent fefd3b0 commit 80212a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: gravity-ui/preview-build-action@v1
- uses: gravity-ui/preview-build-action@v2
with:
node-version: 20
16 changes: 8 additions & 8 deletions src/utils/getAriaRowIndexMap.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type {Row} from '@tanstack/react-table';

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

return rows.reduce<Record<string, number>>((acc, row, index, arr) => {
const newMap = {
...acc,
[row.id]: rowIndex,
};
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const nextRow = rows[i + 1];

map[row.id] = rowIndex;

const nextRow = arr[index + 1];
if (nextRow?.parentId !== row.id) {
rowIndex += row.getLeafRows().length;
}
rowIndex++;
}

return newMap;
}, {});
return map;
};

0 comments on commit 80212a1

Please sign in to comment.