ant-design icon indicating copy to clipboard operation
ant-design copied to clipboard

INTERNAL: add shortcuts to pro-components

Open Wxh16144 opened this issue 1 year ago • 9 comments

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() 无法断言 nullundefined根据这篇文章 添加 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 用

Wxh16144 avatar Dec 20 '24 07:12 Wxh16144

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Preview failed

github-actions[bot] avatar Dec 20 '24 07:12 github-actions[bot]

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.

petercat-assistant[bot] avatar Dec 20 '24 07:12 petercat-assistant[bot]

👁 Visual Regression Report for PR #52068 Passed ✅

🎯 Target branch: master (55b5aa6e48a9ae92a3490e674118397a09032c5e) 📖 View Full Report ↗︎

🎊 Congrats! No visual-regression diff found.

github-actions[bot] avatar Dec 20 '24 07:12 github-actions[bot]

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.

codecov[bot] avatar Dec 20 '24 07:12 codecov[bot]

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@ant-design/[email protected] environment 0 389 kB zombiej
npm/@ant-design/[email protected] None 0 30.9 kB zombiej
npm/@ant-design/[email protected] filesystem 0 65.7 kB madccc
npm/@antfu/[email protected] environment 0 1.6 MB antfu
npm/@antv/[email protected] None 0 7.99 MB iaaron
npm/@biomejs/[email protected] shell 0 210 kB dominionl
npm/@codecov/[email protected] None 0 62.8 kB codecov-devops
npm/@codesandbox/[email protected] network 0 1.21 MB danilowoz
npm/@dnd-kit/[email protected] environment 0 1.07 MB clauderic
npm/@dnd-kit/[email protected] environment 0 49 kB clauderic
npm/@dnd-kit/[email protected] environment 0 234 kB clauderic
npm/@dnd-kit/[email protected] environment 0 88.5 kB clauderic
npm/@emotion/[email protected] None 0 273 kB emotion-release-bot
npm/@emotion/[email protected] None 0 0 B
npm/@emotion/[email protected] environment 0 48.7 kB emotion-release-bot
npm/@eslint-react/[email protected] None 0 306 kB rel1cx
npm/@ianvs/[email protected] environment, unsafe 0 114 kB ianvs
npm/@inquirer/[email protected] None 0 23.2 kB sboudrias
npm/@madccc/[email protected] None 0 19 kB madccc
npm/@microflash/[email protected] None 0 6.71 kB naiyer
npm/@npmcli/[email protected] environment 0 18.3 kB npm-cli-ops
npm/@octokit/[email protected] None 0 8.28 kB octokitbot
npm/@qixian.cs/[email protected] network 0 19.6 kB chenshuai2144
npm/@size-limit/[email protected] None 0 3.43 kB ai
npm/@stackblitz/[email protected] None 0 186 kB tsulkowski
npm/@testing-library/[email protected] environment 0 2.43 MB testing-library-bot
npm/@testing-library/[email protected] None 0 282 kB testing-library-bot
npm/@testing-library/[email protected] environment 0 329 kB testing-library-bot
npm/@testing-library/[email protected] None 0 435 kB testing-library-bot
npm/@types/[email protected] None 0 24.6 kB types
npm/@types/[email protected] None 0 42.2 kB types
npm/@types/[email protected] None 0 13.1 kB types
npm/@types/[email protected] None 0 36.8 kB types
npm/@types/[email protected] None 0 9.1 kB types
npm/@types/[email protected] None 0 4.58 kB types
npm/@types/[email protected] None 0 2.77 kB types
npm/@types/[email protected] None 0 6.62 kB types
npm/@types/[email protected] None 0 6.09 kB types
npm/@types/[email protected] None 0 9.68 kB types
npm/@types/[email protected] None 0 78.8 kB types
npm/@types/[email protected] None 0 1.12 MB types
npm/@types/[email protected] None 0 21.9 kB types
npm/@types/[email protected] None 0 868 kB types
npm/@types/[email protected] None 0 6.27 kB types
npm/@types/[email protected] None 0 2.28 MB types
npm/@types/[email protected] None 0 7.87 kB types
npm/@types/[email protected] None 0 5.47 kB types
npm/@types/[email protected] None 0 19.4 kB types
npm/@types/[email protected] None 0 6.51 kB types
npm/@types/[email protected] None 0 7.46 kB types
npm/@types/[email protected] None 0 4.36 kB types
npm/@types/[email protected] None 0 0 B
npm/@types/[email protected] None 0 5.75 kB types
npm/@types/[email protected] None 0 7.36 kB types
npm/@types/[email protected] None 0 790 kB types
npm/@types/[email protected] None 0 23.3 kB types
npm/@types/[email protected] None 0 8.22 kB types
npm/@types/[email protected] None 0 30.8 kB types
npm/@types/[email protected] None 0 6.48 kB types
npm/@types/[email protected] None 0 2.71 kB types
npm/[email protected] filesystem 0 121 kB cthackers
npm/[email protected] filesystem 0 2.74 MB fengmk2
npm/[email protected] None 0 47.9 kB nanxiaobei
npm/[email protected] environment 0 191 kB arvinxx
npm/[email protected] None 0 1.22 MB madccc
npm/[email protected] network 0 2.13 MB jasonsaayman
npm/[email protected] None +1 42.1 kB sindresorhus
npm/[email protected] None 0 1.25 MB feedic
npm/[email protected] None 0 10.5 kB theron
npm/[email protected] None 0 62.2 kB andidittrich
npm/[email protected] None 0 15.1 kB sudodoki
npm/[email protected] environment 0 29.1 kB kentcdodds
npm/[email protected] network 0 93.3 kB lquixada
npm/[email protected] filesystem 0 8.91 kB benjycui
npm/[email protected] Transitive: environment +1 357 kB wxh16144
npm/[email protected] environment, eval, filesystem 0 2.92 MB yifankakaxi
npm/[email protected] filesystem +1 202 kB amilajack
npm/[email protected] None 0 350 kB aaronabramov, jeysal, jsonp, ...6 more
npm/[email protected] None 0 753 kB ljharb
npm/[email protected] None 0 0 B
npm/[email protected] None 0 18.2 kB arnaud-barre
npm/[email protected] None 0 3.37 MB eslintbot, openjsfoundation
npm/[email protected] filesystem 0 96.7 kB mrmlnc
npm/[email protected] None 0 12.4 kB camsong
npm/[email protected] None +1 59.6 kB ryanzim
npm/[email protected] filesystem, shell 0 39.8 kB tschaub
npm/[email protected] None 0 475 kB isaacs
npm/[email protected] network 0 1.87 MB arvinxx
npm/[email protected] environment, filesystem, network 0 124 kB thornjad
npm/[email protected] None 0 4.04 kB typicode
npm/[email protected] None 0 8.38 kB keyanzhang
npm/[email protected] environment 0 627 kB mweststrate
npm/[email protected] Transitive: environment +1 32.9 kB sibiraj-s
npm/[email protected] Transitive: network +1 169 kB mattandrews
npm/[email protected] None 0 21 kB nickcolley
npm/[email protected] None 0 112 kB atool
npm/[email protected] None 0 9.21 kB simenb
npm/[email protected] unsafe 0 9.37 kB simenb
npm/[email protected] None 0 107 kB simenb
npm/[email protected] environment, filesystem, shell 0 84.9 kB amexopensource
npm/[email protected] None 0 3.72 kB neoziro
npm/[email protected] None 0 5.01 kB simenb
npm/[email protected] None 0 1.25 MB timmywil
npm/[email protected] eval, filesystem, network, shell, unsafe 0 3.11 MB domenic
npm/[email protected] None 0 21.2 kB benjycui
npm/[email protected] None 0 28.3 kB benjycui
npm/[email protected] None 0 123 kB okonet
npm/[email protected] None 0 1.35 MB 6tail
npm/[email protected] None 0 176 kB pieroxy
npm/[email protected] None 0 54.5 kB ljharb
npm/[email protected] None 0 13.8 kB boblauer
npm/[email protected] network 0 107 kB node-fetch-bot
npm/[email protected] environment, filesystem, network, shell +1 5.69 MB mikaelb
npm/[email protected] environment 0 55.2 kB sindresorhus
npm/[email protected] environment 0 27.5 kB sindresorhus
npm/[email protected] None 0 5.42 kB sindresorhus
npm/[email protected] None 0 16 kB mourner
npm/[email protected] None 0 650 kB lukeapage
npm/[email protected] None 0 7.83 MB prettier-bot
npm/[email protected] None 0 60.7 kB simenb
npm/[email protected] None 0 2.05 MB rundevelopment
npm/[email protected] environment 0 359 kB google-wombot, mathias
npm/[email protected] None 0 256 kB ljharb
npm/[email protected] environment 0 180 kB zombiej
npm/[email protected] None 0 20.5 kB zombiej
npm/[email protected] None 0 52.4 kB afc163
npm/[email protected] environment 0 77.4 kB afc163
npm/[email protected] environment 0 59.6 kB zombiej
npm/[email protected] None 0 43.1 kB zombiej
npm/[email protected] environment 0 292 kB zombiej
npm/[email protected] None 0 25.1 kB afc163
npm/[email protected] environment 0 159 kB afc163
npm/[email protected] environment 0 81.5 kB zombiej
npm/[email protected] None 0 73.7 kB afc163
npm/[email protected] environment 0 77.5 kB zombiej
npm/[email protected] environment 0 256 kB zombiej
npm/[email protected] None 0 107 kB 07akioni, afc163, madccc, ...1 more
npm/[email protected] environment 0 88.3 kB madccc
npm/[email protected] environment 0 166 kB zombiej
npm/[email protected] environment 0 905 kB zombiej
npm/[email protected] environment 0 52.3 kB afc163
npm/[email protected] None 0 40.6 kB madccc
npm/[email protected] environment 0 36.5 kB afc163
npm/[email protected] environment 0 45.2 kB afc163
npm/[email protected] environment 0 345 kB zombiej
npm/[email protected] environment 0 172 kB afc163
npm/[email protected] None 0 48.3 kB zombiej
npm/[email protected] None 0 20.5 kB afc163
npm/[email protected] environment 0 402 kB zombiej
npm/[email protected] environment 0 166 kB zombiej
npm/[email protected] environment 0 63.5 kB afc163
npm/[email protected] None 0 52.3 kB afc163
npm/[email protected] environment 0 152 kB zombiej
npm/[email protected] environment 0 373 kB afc163
npm/[email protected] None 0 76.7 kB jljsj33
npm/[email protected] None 0 80.3 kB afc163
npm/[email protected] environment +1 267 kB zombiej
npm/[email protected] environment 0 144 kB zombiej
npm/[email protected] None 0 40.6 kB nkbt
npm/[email protected] None 0 33.5 kB mapkeji
npm/[email protected] None 0 0 B
npm/[email protected] None 0 244 kB strml
npm/[email protected] None 0 49.8 kB justin-chu
npm/[email protected] environment 0 1.6 MB sergei-startsev
npm/[email protected] None 0 177 kB ankeetmaini
npm/[email protected] None 0 130 kB thebuilder
npm/[email protected] None 0 116 kB strml
npm/[email protected] None 0 5.44 kB chancestrickland, mjackson, timdorr
npm/[email protected] None 0 17.8 kB danielberndt
npm/[email protected] None 0 0 B
npm/[email protected] None 0 44.8 kB stipsan
npm/[email protected] None 0 68.6 kB niksy

View full report↗︎

socket-security[bot] avatar Dec 20 '24 10:12 socket-security[bot]

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:

codecov[bot] avatar Dec 20 '24 10:12 codecov[bot]

ready~

Wxh16144 avatar Dec 20 '24 10:12 Wxh16144

为啥关了 @Wxh16144

leshalv avatar Sep 12 '25 17:09 leshalv

为啥关了 @Wxh16144

当前实现是一个内部方法,并且 PR 也是在内部方法做了调整,antd 侧其实是希望改成生产对外可用方法。 我一时半会儿也没好怎么搞。这个 PR 就先关闭了,后面新开一个进行补充。

Wxh16144 avatar Sep 15 '25 02:09 Wxh16144