Repository navigation
feat(ui-core): forward refs on Button (+ vitest bootstrap) - #30664
Conversation
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]>
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
| // `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. |
There was a problem hiding this comment.
💡 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 👍 / 👎
✅ Playwright Results — workflow succeededValidated commit ✅ 65 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 3 skipped · 🧰 0 lifecycle flaky PerformanceBlocking 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:
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
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]>
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsAdds 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 🤖 Prompt for agentsOptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar | Powered by Gitar — free for open source |
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]>
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]>
Summary
Part of the AntD → ui-core-components migration (Wave 1 prep, epic #30570). Two commits, deliberately separated:
chore(ui-core): add vitest unit-test infrastructure— theopenmetadata-ui-core-componentspackage 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.feat(ui-core): forward refs on Button— coreButtonwas 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 nowforwardRef-wrapped, forwarding to the underlying react-ariaAriaButton/AriaLink(button vshreflink mode).Tests
HTMLButtonElement(button mode); ref receivesHTMLAnchorElement(hrefmode); children render +onClickfires (behavior smoke). 4/4 green; the ref tests were verified failing pre-fix (React's "function components cannot be given refs" warning).AriaButton | AriaLinkbranch needs a documentedref as nevercast — TS cannot reconcile a union ref against the intersection JSX infers; flagged inline.Out of scope
ButtonUtilityhas the identical non-forwardRef limitation — left untouched to keep this minimal; follow-up candidate.Fixes #30662
🤖 Generated with Claude Code
Summary by Gitar
colorprop toTypographysupporting semantic variants likesecondary,success,warning, anddangerTypographysemantic color variantsThis will update automatically on new commits.
Greptile Summary
This PR introduces unit-test infrastructure for the UI core-components package and extends shared components.
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
Reviews (2): Last reviewed commit: "feat(ui-core): add semantic color prop t..." | Re-trigger Greptile