INTERNAL: add shortcuts to pro-components
backgroubd: https://github.com/ant-design/ant-design/issues/51829#issuecomment-2521895129
给 pro-components 使用的内部口子,加一个 _internalItemRender.prepare 允许 pro 那边重新处理 item 几个参数,然后再由 antd 组装一遍使用。
原来的 _internalItemRender.render 则继续保留,防止 pro 那边的开发者没有升级前置依赖 antd 导致 break change。
注意:后面 pro-components 升级 major 或者 antd 升级 major 可以考虑移除这部分兼容代码
// It is just for `pro-components`
if (formItemRender?.mark === 'pro_table_render') {
if (typeof formItemRender?.prepare === 'function') {
const _clonedInnerRender = innerRender;
innerRender = (...args) => _clonedInnerRender(args[0], formItemRender.prepare(...args));
} else if (typeof formItemRender?.render === 'function') {
innerRender = formItemRender.render;
}
}
这个 PR 合并了。pro 那边还要写一部分兼容性代码... PR: https://github.com/ant-design/pro-components/pull/8935
因为要写测试用例断言 prepare 的执行入参数,jest 的断言 expect.anything() 无法断言 null 和 undefined 。根据这篇文章 添加 jest-extended 依赖作为拓展,支持如下断言
expect(mockPrepare).toHaveBeenCalledWith(
expect.objectContaining({
errors: expect.any(Array),
warnings: expect.any(Array),
}),
// https://zirkelc.dev/posts/use-expectobjectcontaining-with-null-and-undefined
expect.objectContaining({
input: expect.anything(),
errorList: expect.toBeOneOf([expect.anything(), null]),
extra: expect.toBeOneOf([expect.anything(), null]),
}),
);
| Language | Changelog |
|---|---|
| 🇺🇸 English | -- |
| 🇨🇳 Chinese | 给 pro-comonents 内部 API 用 |
Run & review this pull request in StackBlitz Codeflow.
Walkthrough
This pull request introduces an internal feature to the pro-components by adding a _internalItemRender.prepare function. This allows for the reprocessing of item parameters in pro-components before they are reassembled and used in ant-design. This change is intended for internal API use and may be removed in future major updates.
Changes
| File | Summary |
|---|---|
| components/form/FormItemInput.tsx | Introduced a new type InternalItemRender with prepare and render functions for internal use, and refactored the rendering logic to accommodate these changes. |
👁 Visual Regression Report for PR #52068 Passed ✅
🎯 Target branch: master (55b5aa6e48a9ae92a3490e674118397a09032c5e) 📖 View Full Report ↗︎
🎊 Congrats! No visual-regression diff found.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 100.00%. Comparing base (d56dbd9) to head (054a61e).
:warning: Report is 952 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #52068 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 763 763
Lines 13638 13643 +5
Branches 3558 3558
=========================================
+ Hits 13638 13643 +5
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
Bundle Report
Changes will increase total bundle size by 506 bytes (0.01%) :arrow_up:. This is within the configured threshold :white_check_mark:
Detailed changes
| Bundle name | Size | Change |
|---|---|---|
| antd.min-array-push | 3.38MB | 506 bytes (0.01%) :arrow_up: |
ready~
为啥关了 @Wxh16144
为啥关了 @Wxh16144
当前实现是一个内部方法,并且 PR 也是在内部方法做了调整,antd 侧其实是希望改成生产对外可用方法。 我一时半会儿也没好怎么搞。这个 PR 就先关闭了,后面新开一个进行补充。
