Skip to content

feat(ui-core): forward refs on Button (+ vitest bootstrap) - #30664

Merged
chirag-madlani merged 3 commits into
mainfrom
antd-migration/core-button-forwardref
Jul 30, 2026
Merged

chirag-madlani merged 3 commits into
mainfrom
antd-migration/core-button-forwardref

Conversation

@chirag-madlani

@chirag-madlani chirag-madlani commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Part of the AntD → ui-core-components migration (Wave 1 prep, epic #30570). Two commits, deliberately separated:

  1. chore(ui-core): add vitest unit-test infrastructure — the openmetadata-ui-core-components package had no test runner at all; this adds vitest + testing-library so core-component changes can be unit-gated. Future migration PRs (e.g. the Typography color prop) reuse this.
  2. feat(ui-core): forward refs on Button — core Button was a plain function component, so <Button ref={...}> silently dropped the ref under React 18. The migration gap-check found 5 live call sites in openmetadata-ui/collate-ui using imperative button refs that would break during the antd Button sweep. Button is now forwardRef-wrapped, forwarding to the underlying react-aria AriaButton/AriaLink (button vs href link mode).

Tests

  • New: ref receives HTMLButtonElement (button mode); ref receives HTMLAnchorElement (href mode); children render + onClick fires (behavior smoke). 4/4 green; the ref tests were verified failing pre-fix (React's "function components cannot be given refs" warning).
  • Note for reviewers: the polymorphic AriaButton | AriaLink branch needs a documented ref as never cast — TS cannot reconcile a union ref against the intersection JSX infers; flagged inline.

Out of scope

ButtonUtility has the identical non-forwardRef limitation — left untouched to keep this minimal; follow-up candidate.

Fixes #30662

🤖 Generated with Claude Code


Summary by Gitar

  • New features:
    • Added color prop to Typography supporting semantic variants like secondary, success, warning, and danger
    • Added comprehensive unit tests for Typography semantic color variants

This will update automatically on new commits.

Greptile Summary

This PR introduces unit-test infrastructure for the UI core-components package and extends shared components.

  • Adds Vitest, Testing Library, jsdom configuration, setup, and component tests.
  • Forwards Button refs to the underlying button or anchor element.
  • Adds semantic color variants to Typography.

Confidence Score: 3/5

The PR should not merge until the new core-components test suite is executed by CI.

The package defines and uses Vitest locally, but the workflows covering core-components run only linting and formatting while the existing coverage workflow targets the separate main UI package, leaving the new regression tests non-gating.

Files Needing Attention: openmetadata-ui-core-components/src/main/resources/ui/package.json and the core-components CI workflow configuration

Important Files Changed

Filename Overview
openmetadata-ui-core-components/src/main/resources/ui/package.json Adds the Vitest scripts and dependencies, but the test command remains absent from CI.
openmetadata-ui-core-components/src/main/resources/ui/src/components/base/buttons/button.tsx Wraps Button with forwardRef and passes the ref to its polymorphic React Aria element.
openmetadata-ui-core-components/src/main/resources/ui/src/components/foundations/typography.tsx Adds semantic text-color variants while preserving consumer class overrides.
openmetadata-ui-core-components/src/main/resources/ui/vitest.config.ts Configures component tests to run under jsdom with React and the package alias.

Reviews (2): Last reviewed commit: "feat(ui-core): add semantic color prop t..." | Re-trigger Greptile

chirag-madlani and others added 2 commits July 29, 2026 23:04
The openmetadata-ui-core-components package had no test runner. Adds
vitest + testing-library setup so component-level unit tests can gate the
antd-migration core changes (first consumer: Button forwardRef tests).

Co-Authored-By: Claude Fable 5 <[email protected]>
Button was a plain function component, so consumer refs were silently
dropped under React 18. Wraps it in forwardRef, forwarding to the
underlying AriaButton/AriaLink (button vs href-link mode). Tests cover
ref->HTMLButtonElement, ref->HTMLAnchorElement, and existing behavior.

ButtonUtility has the same limitation; left for a follow-up to keep this
change minimal.

Fixes #30662

Co-Authored-By: Claude Fable 5 <[email protected]>
@chirag-madlani
chirag-madlani requested a review from karanh37 as a code owner July 29, 2026 17:34
Copilot AI review requested due to automatic review settings July 29, 2026 17:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs UI UI specific issues labels Jul 29, 2026
Comment on lines +5 to +7
// `globals: false` in vitest.config.ts means Testing Library's automatic
// cleanup (which detects a global `afterEach`) never registers, so each
// render leaks into the next test's jsdom document. Clean up explicitly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Quality: Setup comment references a globals:false config that isn't set

The comment states cleanup is needed because globals: false is set in vitest.config.ts, but the config never sets globals — the explicit afterEach(cleanup) is only needed because false is vitest's default. A maintainer who later adds globals: true (enabling Testing Library's auto-cleanup) will search for the referenced globals: false setting, not find it, and be confused. Reword the comment to say the manual cleanup is required because globals is left at its default (false) rather than implying it's explicitly configured.

Was this helpful? React with 👍 / 👎

Comment on lines +60 to +61
"test": "vitest run",
"test:watch": "vitest",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test suite is not CI-gated

The new Vitest commands are not invoked by the core-components CI workflow, so broken components or tests can merge while the required checks remain green, leaving the suite effective only when developers run it manually.

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 08e3c8bf50e89a0caf6e2c2129b4f9b253530cba in Playwright run 30519124512, attempt 1.

✅ 65 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 3 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 41m 23s

⏱️ Max setup 1m 30s · max shard execution 7m 24s · max shard-job elapsed before upload 10m 56s · reporting 2s

🌐 147.34 requests/attempt · 1.73 app boots/UI scenario · 0.00% common-shard skew

Optimization targets still in progress:

  • Application boot ratio was 1.73 per UI scenario (116 boots / 67 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 65 0 0 3 0 0

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

karanh37
karanh37 previously approved these changes Jul 30, 2026
antd's Typography.Text/Paragraph exposes a `type` prop ("secondary" | "success" | "warning" | "danger") that sets a semantic text color. The antd->ui-core-components migration gap-check found 20 call sites relying on `type="secondary"` with no core equivalent, forcing a per-site `className="tw:text-tertiary"` workaround. This adds a first-class `color` prop to core Typography mapping each antd type to the existing semantic Tailwind text tokens (tw:text-tertiary, tw:text-success-primary, tw:text-warning-primary, tw:text-error-primary), matching the idiom already used elsewhere in core (tree.tsx, pagination.tsx, form-field, empty-placeholder). Omitting the prop leaves current behavior unchanged, and an explicit consumer className still wins over the color class via twMerge ordering.

Fixes #30663

Co-authored-by: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 30, 2026 06:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chirag-madlani
chirag-madlani added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit e212b9c Jul 30, 2026
67 of 70 checks passed
@chirag-madlani
chirag-madlani deleted the antd-migration/core-button-forwardref branch July 30, 2026 14:19
@gitar-bot

gitar-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Adds Vitest unit-test infrastructure and forwards refs on the core Button component, with comprehensive test coverage. Consider updating the setup comment to accurately reflect the vitest configuration regarding globals.

💡 Quality: Setup comment references a globals:false config that isn't set

📄 openmetadata-ui-core-components/src/main/resources/ui/vitest.setup.ts:5-7 📄 openmetadata-ui-core-components/src/main/resources/ui/vitest.config.ts:12-16

The comment states cleanup is needed because globals: false is set in vitest.config.ts, but the config never sets globals — the explicit afterEach(cleanup) is only needed because false is vitest's default. A maintainer who later adds globals: true (enabling Testing Library's auto-cleanup) will search for the referenced globals: false setting, not find it, and be confused. Reword the comment to say the manual cleanup is required because globals is left at its default (false) rather than implying it's explicitly configured.

🤖 Prompt for agents
Code Review: Adds Vitest unit-test infrastructure and forwards refs on the core Button component, with comprehensive test coverage. Consider updating the setup comment to accurately reflect the vitest configuration regarding globals.

1. 💡 Quality: Setup comment references a globals:false config that isn't set
   Files: openmetadata-ui-core-components/src/main/resources/ui/vitest.setup.ts:5-7, openmetadata-ui-core-components/src/main/resources/ui/vitest.config.ts:12-16

   The comment states cleanup is needed because `globals: false` is set `in vitest.config.ts`, but the config never sets `globals` — the explicit `afterEach(cleanup)` is only needed because `false` is vitest's default. A maintainer who later adds `globals: true` (enabling Testing Library's auto-cleanup) will search for the referenced `globals: false` setting, not find it, and be confused. Reword the comment to say the manual cleanup is required because globals is left at its default (false) rather than implying it's explicitly configured.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar | Powered by Gitar — free for open source

timothybrush pushed a commit to timothybrush/OpenMetadata that referenced this pull request Aug 1, 2026
Second Wave 1 transform (guide: docs/antd-migration/button.md). Maps
type->color incl. the no-type default inversion (antd default 'default' ->
explicit color=secondary since core defaults to primary), folds danger into
-destructive colors, remaps ghost->tertiary with a per-site review warning,
applies the approved size map (small/middle/large -> xs/sm/md), renames
disabled/loading/icon/htmlType with type-collision ordering handled, moves
block to tw:w-full, passes refs through (forwardRef landed in open-metadata#30664), and
skips-with-warnings the hand-finish punch list (shapes, Button.Group,
dynamic type/size, loading objects). 44 tests; suite 81/81.

Co-authored-by: Claude Fable 5 <[email protected]>
k-anshul pushed a commit to k-anshul/OpenMetadata that referenced this pull request Aug 12, 2026
Second Wave 1 transform (guide: docs/antd-migration/button.md). Maps
type->color incl. the no-type default inversion (antd default 'default' ->
explicit color=secondary since core defaults to primary), folds danger into
-destructive colors, remaps ghost->tertiary with a per-site review warning,
applies the approved size map (small/middle/large -> xs/sm/md), renames
disabled/loading/icon/htmlType with type-collision ordering handled, moves
block to tw:w-full, passes refs through (forwardRef landed in open-metadata#30664), and
skips-with-warnings the hand-finish punch list (shapes, Button.Group,
dynamic type/size, loading objects). 44 tests; suite 81/81.

Co-authored-by: Claude Fable 5 <[email protected]>

This branch was previously deployed

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

Labels

safe to test Add this label to run secure Github workflows on PRs UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-core-components: forwardRef support on Button

3 participants