From cca77e61b9a03b8b37e2ac347d04419fec2c7353 Mon Sep 17 00:00:00 2001 From: "@linhf2023" <32009993+linhf123@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:22:31 +0800 Subject: [PATCH 1/7] fix(form): legacy `hideRequiredMark` props priority (#46299) * fix(form): Reduce global requireMark priority * chore: add test --------- Co-authored-by: linhf123 --- components/form/Form.tsx | 8 ++--- components/form/__tests__/index.test.tsx | 46 +++++++++++++++++++----- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/components/form/Form.tsx b/components/form/Form.tsx index b81d7e2559..9e74f5f88d 100644 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -88,13 +88,13 @@ const InternalForm: React.ForwardRefRenderFunction = (p return requiredMark; } - if (contextForm && contextForm.requiredMark !== undefined) { - return contextForm.requiredMark; - } - if (hideRequiredMark) { return false; } + + if (contextForm && contextForm.requiredMark !== undefined) { + return contextForm.requiredMark; + } return true; }, [hideRequiredMark, requiredMark, contextForm]); diff --git a/components/form/__tests__/index.test.tsx b/components/form/__tests__/index.test.tsx index e359c98cdf..4075f5cd9c 100644 --- a/components/form/__tests__/index.test.tsx +++ b/components/form/__tests__/index.test.tsx @@ -1089,16 +1089,44 @@ describe('Form', () => { }); }); - it('legacy hideRequiredMark', () => { - const { container } = render( -
- - - -
, - ); + describe('legacy hideRequiredMark', () => { + it('should work', () => { + const { container } = render( +
+ + + +
, + ); - expect(container.querySelector('form')!).toHaveClass('ant-form-hide-required-mark'); + expect(container.querySelector('form')!).toHaveClass('ant-form-hide-required-mark'); + }); + + it('priority should be higher than CP', () => { + const { container, rerender } = render( + +
+ + + +
+
, + ); + + expect(container.querySelector('form')!).toHaveClass('ant-form-hide-required-mark'); + + rerender( + +
+ + + +
+
, + ); + + expect(container.querySelector('form')!).toHaveClass('ant-form-hide-required-mark'); + }); }); it('form should support disabled', () => { From 4030bb3d05aed78aca74f894e4532e29315d1ad9 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Thu, 7 Dec 2023 14:27:15 +0800 Subject: [PATCH 2/7] fix: rm pointer-events when Spin fullscreen (#46303) --- components/spin/style/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/components/spin/style/index.ts b/components/spin/style/index.ts index 08ffd2c8f9..bc5dfc85ff 100644 --- a/components/spin/style/index.ts +++ b/components/spin/style/index.ts @@ -75,7 +75,6 @@ const genSpinStyle: GenerateStyle = (token: SpinToken): CSSObject => alignItems: 'center', flexDirection: 'column', justifyContent: 'center', - pointerEvents: 'none', opacity: 0, visibility: 'hidden', transition: `all ${token.motionDurationMid}`, From f6084990b7547ebf6d9016f40a42051df595dce9 Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Thu, 7 Dec 2023 15:09:24 +0800 Subject: [PATCH 3/7] docs: fix out-dated text (#46309) Signed-off-by: Guo Yunhe --- docs/react/i18n.en-US.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/react/i18n.en-US.md b/docs/react/i18n.en-US.md index 13d90bc22d..6176169dd3 100644 --- a/docs/react/i18n.en-US.md +++ b/docs/react/i18n.en-US.md @@ -5,7 +5,7 @@ order: 5 title: Internationalization --- -The default language of `antd@2.x` is currently English. If you wish to use other languages, follow the instructions below. +The default language of `antd` is currently English. If you wish to use other languages, follow the instructions below. ## ConfigProvider From c4ad37991e0365b0384b067173690565aa0a197d Mon Sep 17 00:00:00 2001 From: vagusX Date: Thu, 7 Dec 2023 16:35:16 +0800 Subject: [PATCH 4/7] ci: persist image snapshots (#46311) Co-authored-by: Amumu --- .../visual-regression-persist-finish.yml | 43 +++---- .../visual-regression-persist-start.yml | 2 +- package.json | 2 + scripts/visual-regression-report.md | 5 - scripts/visual-regression-upload.js | 121 ++++++++++++++++++ 5 files changed, 139 insertions(+), 34 deletions(-) delete mode 100644 scripts/visual-regression-report.md create mode 100644 scripts/visual-regression-upload.js diff --git a/.github/workflows/visual-regression-persist-finish.yml b/.github/workflows/visual-regression-persist-finish.yml index 45539c11c0..7af7be256b 100644 --- a/.github/workflows/visual-regression-persist-finish.yml +++ b/.github/workflows/visual-regression-persist-finish.yml @@ -54,15 +54,18 @@ jobs: permissions: actions: read # for dawidd6/action-download-artifact to query and download artifacts runs-on: ubuntu-latest - needs: upstream-workflow-summary + needs: [upstream-workflow-summary] steps: + - name: checkout + uses: actions/checkout@v4 + # We need get persist key first - name: Download Visual Regression Ref uses: dawidd6/action-download-artifact@v2 with: workflow: ${{ github.event.workflow_run.workflow_id }} run_id: ${{ github.event.workflow_run.id }} - name: visual-regression-persist-ref + name: visual-regression-master-ref # Save visual-regression ref to output - name: Extra Visual Regression Ref @@ -78,36 +81,20 @@ jobs: name: image-snapshots path: ./ - - name: Persist to Snapshot Repo + - name: Persist Image Snapshot to OSS if: github.ref_name == 'master' id: persist continue-on-error: true env: - GITHUB_TOKEN: ${{ secrets.ANTD_IMAGE_SNAP_REPO_TOKEN }} - # should push to snapshot repo firstly - # push the single folder to the repo + ALI_OSS_AK_ID: ${{ secrets.ALI_OSS_AK_ID }} + ALI_OSS_AK_SECRET: ${{ secrets.ALI_OSS_AK_SECRET }} + ALI_OSS_BUCKET: ${{ secrets.ALI_OSS_BUCKET }} run: | - git clone https://$GITHUB_TOKEN@github.com/ant-design/antd-image-snapshots.git + rm package.json + npm i ali-oss --no-save - echo "✅ Clone Finished" + echo "🤖 Uploading" + node scripts/visual-regression-upload.js ./imageSnapshots.tar.gz --ref=${{ github.sha }} + node scripts/visual-regression-upload.js ./visual-regression-ref.txt --ref=${{ github.ref_name }} - rm antd-image-snapshots/*.txt - mv visual-regression-ref.txt antd-image-snapshots/ - - rm -rf antd-image-snapshots/imageSnapshots/* - tar -xzvf imageSnapshots.tar.gz -C antd-image-snapshots/imageSnapshots - - echo "✅ Changes Finished" - - cd antd-image-snapshots - - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - - git commit -a -m 'feat: update snapshot from ${{steps.visuall-regression.outputs.id}}' - - echo "✅ Commit Finished" - - git push --prune https://vaugsX:$GITHUB_TOKEN@github.com/ant-design/antd-image-snapshots.git +refs/remotes/origin/*:refs/heads/* - - echo "✅ Push Finished" + echo "✅ Uploaded" diff --git a/.github/workflows/visual-regression-persist-start.yml b/.github/workflows/visual-regression-persist-start.yml index 82e0f6c54e..ade387ee67 100644 --- a/.github/workflows/visual-regression-persist-start.yml +++ b/.github/workflows/visual-regression-persist-start.yml @@ -90,5 +90,5 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v3 with: - name: visual-regression-persist-ref + name: visual-regression-master-ref path: ./visual-regression-ref.txt diff --git a/package.json b/package.json index 244aa67edc..f7573d22b8 100644 --- a/package.json +++ b/package.json @@ -183,6 +183,7 @@ "@testing-library/jest-dom": "^6.1.4", "@testing-library/react": "^14.1.2", "@testing-library/user-event": "^14.5.1", + "@types/ali-oss": "^6.16.11", "@types/fs-extra": "^11.0.4", "@types/gtag.js": "^0.0.18", "@types/http-server": "^0.12.4", @@ -209,6 +210,7 @@ "@types/warning": "^3.0.3", "@typescript-eslint/eslint-plugin": "^6.12.0", "@typescript-eslint/parser": "^6.12.0", + "ali-oss": "^6.18.1", "antd-img-crop": "^4.17.0", "antd-style": "^3.5.2", "antd-token-previewer": "^2.0.5", diff --git a/scripts/visual-regression-report.md b/scripts/visual-regression-report.md deleted file mode 100644 index 4688e1c662..0000000000 --- a/scripts/visual-regression-report.md +++ /dev/null @@ -1,5 +0,0 @@ -| expected | actual | diff | -| --- | --- | --- | -| ![master image name](test/fixtures/4a.png) | ![pr image name](test/fixtures/4b.png) | ![diff](test/fixtures/4diff.png) | -| ![master image name](test/fixtures/3a.png) | ![pr image name](test/fixtures/3b.png) | ![diff](test/fixtures/3diff.png) | -| ![master image name](test/fixtures/6a.png) | ![pr image name](test/fixtures/6b.png) | ![diff](test/fixtures/6diff.png) | diff --git a/scripts/visual-regression-upload.js b/scripts/visual-regression-upload.js new file mode 100644 index 0000000000..18500d41b1 --- /dev/null +++ b/scripts/visual-regression-upload.js @@ -0,0 +1,121 @@ +/* eslint-disable no-restricted-syntax, no-console */ +// Attention: use all node builtin modules except `ali-oss` +// Must keep our ak/sk safe + +// eslint-disable-next-line import/no-extraneous-dependencies +const OSS = require('ali-oss'); +const path = require('path'); +const fs = require('fs'); +const { assert } = require('console'); + +// node scripts/visual-regression-upload.js ./visualRegressionReport.tar.gz --ref=pr-id +// node scripts/visual-regression-upload.js ./imageSnapshots.tar.gz --ref=master-commitId + +const args = process.argv.slice(2); +if (args.length < 2) { + console.error('Usage: node scripts/visual-regression-upload.js --ref='); + process.exit(1); +} + +/** + * Extract the tar file path and ref value from the cli arguments + * @param {string[]} cliArgs + */ +function parseArgs(cliArgs) { + const filepath = cliArgs[0]; + let refValue = ''; + + for (let i = 1; i < cliArgs.length; i++) { + if (cliArgs[i].startsWith('--ref=')) { + refValue = cliArgs[i].substring(6); + break; + } + } + + return [filepath, refValue]; +} + +async function walkDir(dirPath) { + const fileList = []; + + const files = await fs.promises.readdir(dirPath); + + for (const file of files) { + const filePath = path.join(dirPath, file); + const fileStat = fs.statSync(filePath); + + if (fileStat.isDirectory()) { + // Recursively call this func for subdirs + // eslint-disable-next-line no-await-in-loop + fileList.push(...(await walkDir(filePath))); + } else { + fileList.push(filePath); + } + } + + return fileList; +} + +/** + * + * @param {import('ali-oss')} client + * @param {*} filePath + * @param {*} refValue + */ +async function uploadFile(client, filePath, refValue) { + const headers = { + // https://help.aliyun.com/zh/oss/user-guide/object-acl + 'x-oss-object-acl': 'public-read', + // https://help.aliyun.com/zh/oss/developer-reference/prevent-objects-from-being-overwritten-by-objects-that-have-the-same-names-3 + 'x-oss-forbid-overwrite': 'false', + }; + + console.log('Uploading file: %s', filePath); + try { + const targetFilePath = path.relative(process.cwd(), filePath); + const r1 = await client.put(`${refValue}/${targetFilePath}`, filePath, { headers }); + console.log('Uploading file successfully: %s', r1.name); + } catch (err) { + console.error('Uploading file failed: %s', err); + process.exit(1); + } +} + +async function boot() { + const [filepath, refValue] = parseArgs(args); + assert(filepath, 'filepath is required'); + assert(refValue, 'refValue is required'); + + const fileOrFolderName = filepath; + // check if exists + const filePath = path.resolve(process.cwd(), fileOrFolderName); + + if (!fs.existsSync(filePath)) { + console.error('File not exists: %s', filePath); + process.exit(1); + } + + const client = new OSS({ + endpoint: 'oss-cn-shanghai.aliyuncs.com', + accessKeyId: process.env.ALI_OSS_AK_ID, + accessKeySecret: process.env.ALI_OSS_AK_SECRET, + bucket: process.env.ALI_OSS_BUCKET, + }); + + // if is a file then upload it directly + const stat = fs.statSync(filePath); + if (stat.isFile()) { + await uploadFile(client, filePath, refValue); + return; + } + + if (stat.isDirectory()) { + const fileList = await walkDir(filePath); + for (const file of fileList) { + // eslint-disable-next-line no-await-in-loop + await uploadFile(client, file, refValue); + } + } +} + +boot(); From 379a7692f9faf4e2f2409460be6e7662e04323a1 Mon Sep 17 00:00:00 2001 From: vagusX Date: Thu, 7 Dec 2023 17:19:47 +0800 Subject: [PATCH 5/7] ci: shorten image-test snapshot name (#46313) --- tests/shared/imageTest.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/shared/imageTest.tsx b/tests/shared/imageTest.tsx index 5329e07a57..000045dfa3 100644 --- a/tests/shared/imageTest.tsx +++ b/tests/shared/imageTest.tsx @@ -3,6 +3,7 @@ import React from 'react'; // eslint-disable-next-line import/no-unresolved import { createCache, extractStyle, StyleProvider } from '@ant-design/cssinjs'; import dayjs from 'dayjs'; +import path from 'path'; import { globSync } from 'glob'; import { configureToMatchImageSnapshot } from 'jest-image-snapshot'; import MockDate from 'mockdate'; @@ -29,7 +30,11 @@ interface ImageTestOptions { } // eslint-disable-next-line jest/no-export -export default function imageTest(component: React.ReactElement, options: ImageTestOptions) { +export default function imageTest( + component: React.ReactElement, + identifier: string, + options: ImageTestOptions, +) { function test(name: string, themedComponent: React.ReactElement) { it(name, async () => { await jestPuppeteer.resetPage(); @@ -80,7 +85,9 @@ export default function imageTest(component: React.ReactElement, options: ImageT fullPage: !options.onlyViewport, }); - expect(image).toMatchImageSnapshot(); + expect(image).toMatchImageSnapshot({ + customSnapshotIdentifier: `${identifier}-${name.replace(/\s/g, '-')}`, + }); MockDate.reset(); page.off('request', onRequestHandle); @@ -96,7 +103,7 @@ export default function imageTest(component: React.ReactElement, options: ImageT , ); test( - `[CSS Var] component image screenshot should correct ${key}`, + `component image screenshot should correct ${key}.css-var`,
CSS Var
{component} @@ -115,7 +122,7 @@ export default function imageTest(component: React.ReactElement, options: ImageT , ); test( - `[CSS Var] component image screenshot should correct`, + `component image screenshot should correct.css-var`, <>
CSS Var
{Object.entries(themes).map(([key, algorithm]) => ( @@ -151,7 +158,7 @@ export function imageDemoTest(component: string, options: Options = {}) { if (typeof Demo === 'function') { Demo = ; } - imageTest(Demo, { + imageTest(Demo, `${component}-${path.basename(file, '.tsx')}`, { onlyViewport: options.onlyViewport === true || (Array.isArray(options.onlyViewport) && From fbe3a393892629a9b250f0d0e65327225d9c08cd Mon Sep 17 00:00:00 2001 From: MadCcc Date: Thu, 7 Dec 2023 19:21:43 +0800 Subject: [PATCH 6/7] fix: table filterDropdown should accept cssvar (#46314) --- components/table/InternalTable.tsx | 9 +++++---- components/table/hooks/useFilter/FilterDropdown.tsx | 3 +++ components/table/hooks/useFilter/index.tsx | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/components/table/InternalTable.tsx b/components/table/InternalTable.tsx index d66e793c52..eb8a0eec14 100644 --- a/components/table/InternalTable.tsx +++ b/components/table/InternalTable.tsx @@ -202,6 +202,10 @@ const InternalTable = ( const prefixCls = getPrefixCls('table', customizePrefixCls); const dropdownPrefixCls = getPrefixCls('dropdown', customizeDropdownPrefixCls); + const [, token] = useToken(); + const rootCls = useCSSVarCls(prefixCls); + const [wrapCSSVar, hashId] = useStyle(prefixCls, rootCls); + const mergedExpandable: ExpandableConfig = { childrenColumnName: legacyChildrenColumnName, expandIconColumnIndex, @@ -349,6 +353,7 @@ const InternalTable = ( mergedColumns, onFilterChange, getPopupContainer: getPopupContainer || getContextPopupContainer, + rootClassName: classNames(rootClassName, rootCls), }); const mergedData = getFilterData(sortedData, filterStates); @@ -538,10 +543,6 @@ const InternalTable = ( }; } - const [, token] = useToken(); - const rootCls = useCSSVarCls(prefixCls); - const [wrapCSSVar, hashId] = useStyle(prefixCls, rootCls); - const wrapperClassNames = classNames( rootCls, `${prefixCls}-wrapper`, diff --git a/components/table/hooks/useFilter/FilterDropdown.tsx b/components/table/hooks/useFilter/FilterDropdown.tsx index 5f2805325d..9cc7b09068 100644 --- a/components/table/hooks/useFilter/FilterDropdown.tsx +++ b/components/table/hooks/useFilter/FilterDropdown.tsx @@ -133,6 +133,7 @@ export interface FilterDropdownProps { locale: TableLocale; getPopupContainer?: GetPopupContainer; filterResetToDefaultFilteredValue?: boolean; + rootClassName?: string; } function wrapStringListType(keys?: FilterKey) { @@ -154,6 +155,7 @@ function FilterDropdown(props: FilterDropdownProps) { locale, children, getPopupContainer, + rootClassName, } = props; const { @@ -524,6 +526,7 @@ function FilterDropdown(props: FilterDropdownProps) { onOpenChange={onVisibleChange} getPopupContainer={getPopupContainer} placement={direction === 'rtl' ? 'bottomLeft' : 'bottomRight'} + rootClassName={rootClassName} > ( triggerFilter: (filterState: FilterState) => void, getPopupContainer?: GetPopupContainer, pos?: string, + rootClassName?: string, ): ColumnsType { return columns.map((column, index) => { const columnPos = getColumnPos(index, pos); @@ -103,6 +104,7 @@ function injectFilter( triggerFilter={triggerFilter} locale={locale} getPopupContainer={getPopupContainer} + rootClassName={rootClassName} > {renderColumnTitle(column.title, renderProps)} @@ -122,6 +124,7 @@ function injectFilter( triggerFilter, getPopupContainer, columnPos, + rootClassName, ), }; } @@ -184,6 +187,7 @@ interface FilterConfig { filterStates: FilterState[], ) => void; getPopupContainer?: GetPopupContainer; + rootClassName?: string; } const getMergedColumns = ( @@ -203,6 +207,7 @@ function useFilter({ onFilterChange, getPopupContainer, locale: tableLocale, + rootClassName, }: FilterConfig): [ TransformColumns, FilterState[], @@ -282,6 +287,8 @@ function useFilter({ tableLocale, triggerFilter, getPopupContainer, + undefined, + rootClassName, ); return [transformColumns, mergedFilterStates, filters]; From 792a0a4a0daf8e2206b4e0edad7085a2d70eef10 Mon Sep 17 00:00:00 2001 From: MadCcc Date: Fri, 8 Dec 2023 17:56:33 +0800 Subject: [PATCH 7/7] ci: codesandbox install with npm (#46341) * ci: codesandbox install with npm * chore: use npm ci * Revert "chore: use npm ci" This reverts commit d24e2acafc2765a00e4e443e6f764ac9de9d1db6. --- .codesandbox/ci.json | 1 + package.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.codesandbox/ci.json b/.codesandbox/ci.json index 96c2526e4c..16798ee955 100644 --- a/.codesandbox/ci.json +++ b/.codesandbox/ci.json @@ -1,4 +1,5 @@ { + "installCommand": "npm-install", "sandboxes": ["antd-reproduction-template-forked-jyh2k9"], "node": "18" } diff --git a/package.json b/package.json index f7573d22b8..cd6901afd5 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,8 @@ "test:update": "jest --config .jest.js --no-cache -u", "token-meta": "tsx scripts/generate-token-meta.ts", "tsc": "tsc --noEmit", - "version": "tsx scripts/generate-version.ts" + "version": "tsx scripts/generate-version.ts", + "npm-install": "npm install" }, "lint-staged": { "*.{ts,tsx,js,jsx}": "biome format --write",