Skip to content

feat(core): add useTableRowIndex plugin#3756

Merged
humbertovirtudes merged 2 commits into
facebook:mainfrom
humbertovirtudes:navi/feat/table-row-index
Jul 14, 2026
Merged

feat(core): add useTableRowIndex plugin#3756
humbertovirtudes merged 2 commits into
facebook:mainfrom
humbertovirtudes:navi/feat/table-row-index

Conversation

@humbertovirtudes

Copy link
Copy Markdown
Contributor

What

Adds useTableRowIndex — a plugin that prepends a right-aligned, monospaced row-number column.

const rowIndex = useTableRowIndex({data});
<Table data={data} columns={columns} idKey="id" plugins={{rowIndex}} />;

Design

  • Numbering follows the rendered data order, so it reflects the current sort / filter / pagination view. Pass the same array you hand to <Table data> (post sort/page).
  • Astryx renderCell receives only the row item (not its index), so the plugin takes the data array and derives each ordinal — by getRowKey when provided (stable across new object identities), otherwise by reference.
  • label (default #) and startFrom (default 1) customize the header and starting ordinal.
  • Column is fixed-width (48px), align: 'end', resizable: false; number renders in the code font with tabular-nums and secondary text color.

Includes

  • Storybook (Core/TableRowIndex): Default, CustomLabelAndStart, RenumbersWithSort (numbers re-derive as the sort order changes).
  • Docsite: useTableRowIndex hook page + a "Numbered Rows" example block.
  • Table Lab: added as a toggle in the sandbox perf/plugin tool.
  • Unit tests (5): header label, 1..n numbering, startFrom, custom label, keyed lookup in data order.

Validation

  • Build ✅, lint ✅, sandbox typecheck ✅
  • 145 tests pass (rowIndex + full Table suite, no regressions); changeset included.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 10, 2026
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 14, 2026 6:08pm

Request Review

Comment thread packages/core/src/Table/plugins/rowIndex/useTableRowIndex.tsx Outdated
Comment thread packages/core/src/Table/plugins/rowIndex/useTableRowIndex.tsx Outdated
Comment thread packages/core/src/Table/plugins/rowIndex/useTableRowIndex.tsx Outdated
Comment thread packages/core/src/Table/plugins/rowIndex/useTableRowIndex.tsx
@cixzhang cixzhang added area:core needs:code-review High-risk change (new package/component/API) — needs human code review before merge and removed area:core labels Jul 11, 2026
@github-actions github-actions Bot added needs:design-review Affects visuals — Design should review and removed needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 12, 2026
Prepends a right-aligned, monospaced row-number column to the table.

- Numbering follows the rendered `data` order, so it reflects the current
  sort / filter / pagination view (consumer passes the sorted/paged array).
- `getRowKey` for stable keyed lookup across new object identities;
  `label` and `startFrom` customize the header and starting ordinal.
- Storybook stories (default, custom label/start, renumber-with-sort),
  docsite hook doc + example block, unit tests, and Table Lab toggle.
Address review feedback (cixzhang) and self-review findings:

- Collapse the dual Map (indexByKey + indexByRef) into a single-pass
  memoized lookup closure, resolving the "two loops" comment and the
  KISS/readability concern. One Map, built once per [data, getRowKey].
- Stabilize plugin identity: the returned plugin now depends only on the
  memoized lookup + presentational props, not on data directly, so it is
  as stable as its inputs allow (addresses "unstable on data updates").
- Document that getRowKey must return a UNIQUE string per row (duplicate
  keys collapse to one ordinal) and recommend useCallback for stability;
  updated doc.mjs wording "stable" -> "unique".
- Tests: add renumber-on-reorder (reference + keyed paths), keyed-vs-
  fresh-identity, single-row, and empty-data cases. The keyed reorder
  test fails for the right reason if the keyed branch regresses. 9/9 green.

Tags: ai-generated

This diff was generated with AI assistance (Navi). The refactor and tests
were produced by an AI agent; the human author reviewed and approved the
changes.
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants