Skip to content

feat(cli): codemod to migrate tree-mode useTableRowExpansion to the tree plugin (#4142) - #4884

Merged
humbertovirtudes merged 1 commit into
meta:mainfrom
humbertovirtudes:feat/table-row-expansion-codemod
Aug 11, 2026
Merged

humbertovirtudes merged 1 commit into
meta:mainfrom
humbertovirtudes:feat/table-row-expansion-codemod

Conversation

@humbertovirtudes

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #4609: an automated migration codemod so consumers of the old tree-mode useTableRowExpansion can move to the tree plugin via astryx upgrade, not by hand.

#4609 turned useTableRowExpansion into a detail-panel plugin (renderExpanded) and removed useTableRowExpansionState. That PR shipped a migration guide; this adds the migration script.

What it does

A v0.3.0 codemod, migrate-table-rowexpansion-to-tree, that rewrites the standard tree pattern:

const {data, expansionConfig} = useTableRowExpansionState({
  baseData: tree,
  getChildren: item => item.children ?? [],
  getRowKey: item => item.id,
  getIsItemExpandable: item => item.type === 'folder',
  expandedKeys,
  setExpandedKeys,
});
const expansion = useTableRowExpansion(expansionConfig);

into:

// astryx-migration: verify tree expansion state. useTableTreeState
// is uncontrolled by default; pass defaultExpandedIds, or
// expandedIds + onExpandedIdsChange for the old controlled set.
const {visibleData: data, treeConfig} = useTableTreeState({
  data: tree,
  childrenKey: 'children',
  idKey: item => item.id,
  isItemExpandable: item => item.type === 'folder',
});
const expansion = useTableTreeData(treeConfig);

It:

  • Rewrites the useTableRowExpansionState call to useTableTreeState and remaps the config (baseData -> data, getChildren -> childrenKey: 'children', getRowKey -> idKey, getIsItemExpandable -> isItemExpandable).
  • Renames the destructured result (data -> visibleData: data, expansionConfig -> treeConfig) and swaps the plugin call to useTableTreeData.
  • Fixes the imports (drops the removed hooks, adds the tree hooks).
  • Leaves a guidance comment, because the controlled expandedKeys/setExpandedKeys wiring does not map 1:1 (the tree hook is uncontrolled by default, or takes expandedIds + onExpandedIdsChange). This is the one part a human should confirm.

Safety

  • Detail-panel usage is left untouched (files using renderExpanded with no useTableRowExpansionState import are the new API, not a migration target).
  • Files that never imported the row-expansion hooks are untouched.
  • Supports both @astryxdesign/core and @xds/core import sources.

Test plan

  • 10 unit tests, RED-verified before implementation (import rewrite, config mapping, accessor preservation, plugin swap, getIsItemExpandable, shorthand output, guidance comment, detail-panel no-op, non-consumer no-op, @xds/core alias).
  • Registered in the v0.3.0 manifest; full v0.3.0 codemod suite green (104), including next-codemods manifest validation.
  • eslint clean; check:changesets valid.

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@humbertovirtudes is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 11, 2026
…he tree plugin (meta#4142)

useTableRowExpansion became a detail-panel plugin (meta#4609) and
useTableRowExpansionState was removed. This adds a v0.3.0 codemod so
`astryx upgrade` migrates the old tree pattern automatically:

  const {data, expansionConfig} = useTableRowExpansionState({
    baseData, getChildren, getRowKey, expandedKeys, setExpandedKeys,
  });
  const expansion = useTableRowExpansion(expansionConfig);

becomes:

  const {visibleData: data, treeConfig} = useTableTreeState({
    data: baseData, childrenKey: 'children', idKey: getRowKey, ...
  });
  const expansion = useTableTreeData(treeConfig);

It remaps the config (baseData -> data, getChildren -> childrenKey,
getRowKey -> idKey, getIsItemExpandable -> isItemExpandable), fixes the
imports, and leaves a guidance comment about expansion state (the
controlled expandedKeys/setExpandedKeys mapping is not mechanical).
Detail-panel usage (renderExpanded, no useTableRowExpansionState import)
is left untouched.

Tests: 10 unit tests (RED-verified first); full v0.3.0 codemod suite
green (104); registered in the v0.3.0 manifest; eslint + changeset clean.
@humbertovirtudes
humbertovirtudes force-pushed the feat/table-row-expansion-codemod branch from a1354f0 to 9354446 Compare August 11, 2026 08:19
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 11, 2026
@humbertovirtudes
humbertovirtudes merged commit ccb5ca9 into meta:main Aug 11, 2026
18 of 19 checks passed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant