From 9cec008e1ac2f8116295084f6ff27871873bbd28 Mon Sep 17 00:00:00 2001
From: lijianan <574980606@qq.com>
Date: Fri, 14 Oct 2022 22:07:02 +0800
Subject: [PATCH 1/5] refactor: CC => FC (#37969)
* refactor: CC => FC
* refactor: CC => FC
* refactor: CC => FC
* test: add test
* test: remove test
* test: add test
* fix: fix
* fix: fix
* test: del
* fix: fix debounce
---
components/spin/__tests__/delay.test.tsx | 3 +-
components/spin/__tests__/index.test.tsx | 14 +--
components/spin/index.tsx | 121 +++++++----------------
3 files changed, 45 insertions(+), 93 deletions(-)
diff --git a/components/spin/__tests__/delay.test.tsx b/components/spin/__tests__/delay.test.tsx
index 11a2e3aaf1..f098538016 100644
--- a/components/spin/__tests__/delay.test.tsx
+++ b/components/spin/__tests__/delay.test.tsx
@@ -1,5 +1,4 @@
import React from 'react';
-// eslint-disable-next-line import/no-named-as-default
import { render } from '@testing-library/react';
import debounce from 'lodash/debounce';
import Spin from '..';
@@ -32,7 +31,7 @@ describe('delay spinning', () => {
jest.useRealTimers();
});
- it('should cancel debounce function when unmount', async () => {
+ it('should cancel debounce function when unmount', () => {
const debouncedFn = jest.fn();
const cancel = jest.fn();
(debouncedFn as any).cancel = cancel;
diff --git a/components/spin/__tests__/index.test.tsx b/components/spin/__tests__/index.test.tsx
index ca3a8646c8..19e778b2cc 100644
--- a/components/spin/__tests__/index.test.tsx
+++ b/components/spin/__tests__/index.test.tsx
@@ -1,6 +1,6 @@
import React from 'react';
-// eslint-disable-next-line import/no-named-as-default
import { render } from '@testing-library/react';
+import { waitFakeTimer } from '../../../tests/utils';
import Spin from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
@@ -15,10 +15,8 @@ describe('Spin', () => {
content
,
);
- expect((container.querySelector('.ant-spin-nested-loading')! as HTMLElement).style.length).toBe(
- 0,
- );
- expect((container.querySelector('.ant-spin')! as HTMLElement).style.background).toBe('red');
+ expect(container.querySelector('.ant-spin-nested-loading')?.style.length).toBe(0);
+ expect(container.querySelector('.ant-spin')?.style.background).toBe('red');
});
it("should render custom indicator when it's set", () => {
@@ -27,11 +25,15 @@ describe('Spin', () => {
expect(asFragment().firstChild).toMatchSnapshot();
});
- it('should be controlled by spinning', () => {
+ it('should be controlled by spinning', async () => {
+ jest.useFakeTimers();
const { container, rerender } = render();
expect(container.querySelector('.ant-spin-spinning')).toBeFalsy();
rerender();
+ await waitFakeTimer();
expect(container.querySelector('.ant-spin-spinning')).toBeTruthy();
+ jest.clearAllTimers();
+ jest.useRealTimers();
});
it('if indicator set null should not be render default indicator', () => {
diff --git a/components/spin/index.tsx b/components/spin/index.tsx
index c73ae4cfad..e2b1fdf942 100644
--- a/components/spin/index.tsx
+++ b/components/spin/index.tsx
@@ -32,11 +32,6 @@ export type SpinFCType = React.FC & {
setDefaultIndicator: (indicator: React.ReactNode) => void;
};
-export interface SpinState {
- spinning?: boolean;
- notCssAnimationSupported?: boolean;
-}
-
// Render indicator
let defaultIndicator: React.ReactNode = null;
@@ -56,8 +51,8 @@ function renderIndicator(prefixCls: string, props: SpinClassProps): React.ReactN
}
if (isValidElement(defaultIndicator)) {
- return cloneElement(defaultIndicator as SpinIndicator, {
- className: classNames((defaultIndicator as SpinIndicator).props.className, dotClassName),
+ return cloneElement(defaultIndicator, {
+ className: classNames(defaultIndicator.props.className, dotClassName),
});
}
@@ -75,79 +70,37 @@ function shouldDelay(spinning?: boolean, delay?: number): boolean {
return !!spinning && !!delay && !isNaN(Number(delay));
}
-class Spin extends React.Component {
- static defaultProps = {
- spinning: true,
- size: 'default' as SpinSize,
- wrapperClassName: '',
- };
-
- originalUpdateSpinning: () => void;
-
- constructor(props: SpinClassProps) {
- super(props);
+const Spin: React.FC = props => {
+ const {
+ spinPrefixCls: prefixCls,
+ spinning: customSpinning = true,
+ delay,
+ className,
+ size = 'default',
+ tip,
+ wrapperClassName,
+ style,
+ children,
+ ...restProps
+ } = props;
+
+ const [spinning, setSpinning] = React.useState(
+ () => customSpinning && !shouldDelay(customSpinning, delay),
+ );
- const { spinning, delay } = props;
- const shouldBeDelayed = shouldDelay(spinning, delay);
- this.state = {
- spinning: spinning && !shouldBeDelayed,
+ React.useEffect(() => {
+ const updateSpinning = debounce<() => void>(() => {
+ setSpinning(customSpinning);
+ }, delay);
+ updateSpinning();
+ return () => {
+ updateSpinning?.cancel?.();
};
- this.originalUpdateSpinning = this.updateSpinning;
- this.debouncifyUpdateSpinning(props);
- }
+ }, [delay, customSpinning]);
- componentDidMount() {
- this.updateSpinning();
- }
-
- componentDidUpdate() {
- this.debouncifyUpdateSpinning();
- this.updateSpinning();
- }
-
- componentWillUnmount() {
- this.cancelExistingSpin();
- }
-
- debouncifyUpdateSpinning = (props?: SpinClassProps) => {
- const { delay } = props || this.props;
- if (delay) {
- this.cancelExistingSpin();
- this.updateSpinning = debounce(this.originalUpdateSpinning, delay);
- }
- };
-
- updateSpinning = () => {
- const { spinning } = this.props;
- const { spinning: currentSpinning } = this.state;
- if (currentSpinning !== spinning) {
- this.setState({ spinning });
- }
- };
-
- cancelExistingSpin() {
- const { updateSpinning } = this;
- if (updateSpinning && (updateSpinning as any).cancel) {
- (updateSpinning as any).cancel();
- }
- }
-
- isNestedPattern() {
- return !!(this.props && typeof this.props.children !== 'undefined');
- }
-
- renderSpin = ({ direction }: ConfigConsumerProps) => {
- const {
- spinPrefixCls: prefixCls,
- className,
- size,
- tip,
- wrapperClassName,
- style,
- ...restProps
- } = this.props;
- const { spinning } = this.state;
+ const isNestedPattern = () => typeof children !== 'undefined';
+ const renderSpin = ({ direction }: ConfigConsumerProps) => {
const spinClassName = classNames(
prefixCls,
{
@@ -161,7 +114,7 @@ class Spin extends React.Component {
);
// fix https://fb.me/react-unknown-prop
- const divProps = omit(restProps, ['spinning', 'delay', 'indicator', 'prefixCls']);
+ const divProps = omit(restProps, ['indicator', 'prefixCls']);
const spinElement = (
{
aria-live="polite"
aria-busy={spinning}
>
- {renderIndicator(prefixCls, this.props)}
+ {renderIndicator(prefixCls, props)}
{tip ?
{tip}
: null}
);
- if (this.isNestedPattern()) {
+
+ if (isNestedPattern()) {
const containerClassName = classNames(`${prefixCls}-container`, {
[`${prefixCls}-blur`]: spinning,
});
@@ -183,18 +137,15 @@ class Spin extends React.Component {
{spinning &&
{spinElement}
}
- {this.props.children}
+ {children}
);
}
return spinElement;
};
-
- render() {
- return {this.renderSpin};
- }
-}
+ return {renderSpin};
+};
const SpinFC: SpinFCType = props => {
const { prefixCls: customizePrefixCls } = props;
From 5442fc24122684d4c95c0b168e373c5fc2cf56ac Mon Sep 17 00:00:00 2001
From: liuycy
Date: Mon, 17 Oct 2022 09:47:16 +0800
Subject: [PATCH 2/5] fix: table header shadow issue (#28096) (#38023)
---
components/table/style/index.less | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/table/style/index.less b/components/table/style/index.less
index 5ee121747a..c4ec310336 100644
--- a/components/table/style/index.less
+++ b/components/table/style/index.less
@@ -655,7 +655,7 @@
position: absolute;
top: 0;
bottom: 0;
- z-index: @zindex-table-fixed;
+ z-index: calc(@table-sticky-zindex + 1);
width: 30px;
transition: box-shadow 0.3s;
content: '';
From 3c456c39c24711086c2e84308d956752a3b27206 Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Mon, 17 Oct 2022 12:01:57 +0800
Subject: [PATCH 3/5] chore(deps): update dependency stylelint-config-standard
to v29 (#38044)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index a815fe5cd1..91203fad55 100644
--- a/package.json
+++ b/package.json
@@ -287,7 +287,7 @@
"stylelint": "^14.9.0",
"stylelint-config-prettier": "^9.0.2",
"stylelint-config-rational-order": "^0.1.2",
- "stylelint-config-standard": "^28.0.0",
+ "stylelint-config-standard": "^29.0.0",
"stylelint-declaration-block-no-ignored-properties": "^2.1.0",
"stylelint-order": "^5.0.0",
"theme-switcher": "^1.0.2",
From e246f008999e0fef3670788379ea2fe02b296931 Mon Sep 17 00:00:00 2001
From: Alan Deng
Date: Mon, 17 Oct 2022 13:32:00 +0800
Subject: [PATCH 4/5] docs(Table): fix log value of selected row keys (#38051)
---
components/table/demo/row-selection-and-operation.md | 2 +-
components/table/demo/row-selection-custom.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/components/table/demo/row-selection-and-operation.md b/components/table/demo/row-selection-and-operation.md
index 2af2706106..9d24eef11b 100644
--- a/components/table/demo/row-selection-and-operation.md
+++ b/components/table/demo/row-selection-and-operation.md
@@ -64,7 +64,7 @@ const App: React.FC = () => {
};
const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
- console.log('selectedRowKeys changed: ', selectedRowKeys);
+ console.log('selectedRowKeys changed: ', newSelectedRowKeys);
setSelectedRowKeys(newSelectedRowKeys);
};
diff --git a/components/table/demo/row-selection-custom.md b/components/table/demo/row-selection-custom.md
index ee71f4973e..51812f0f6d 100644
--- a/components/table/demo/row-selection-custom.md
+++ b/components/table/demo/row-selection-custom.md
@@ -55,7 +55,7 @@ const App: React.FC = () => {
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
- console.log('selectedRowKeys changed: ', selectedRowKeys);
+ console.log('selectedRowKeys changed: ', newSelectedRowKeys);
setSelectedRowKeys(newSelectedRowKeys);
};
From 0992341f875ae9a04f3cdbdb411b9d42ceeae80e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?=
=?UTF-8?q?=E5=8D=9C?=
Date: Mon, 17 Oct 2022 15:45:21 +0800
Subject: [PATCH 5/5] chore: docker update (#38053)
* chore: docker update
* chore: clean up
* fix: lock stylelint version
* Update package.json
Co-authored-by: MadCcc <1075746765@qq.com>
Co-authored-by: lijianan <574980606@qq.com>
Co-authored-by: MadCcc <1075746765@qq.com>
---
docker-compose.yml | 2 +-
package.json | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/docker-compose.yml b/docker-compose.yml
index 782dbaf70e..5555fc9112 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -14,4 +14,4 @@ services:
- './jest-puppeteer.config.js:/app/jest-puppeteer.config.js'
- './imageSnapshots:/app/imageSnapshots'
- './imageDiffSnapshots:/app/imageDiffSnapshots'
- entrypoint: "jest --config .jest.image.js --no-cache -i"
+ entrypoint: "npm run test-image:docker"
diff --git a/package.json b/package.json
index 91203fad55..5c9cf2ac7b 100644
--- a/package.json
+++ b/package.json
@@ -99,6 +99,7 @@
"tsc": "tsc --noEmit",
"site:test": "jest --config .jest.site.js --cache=false --force-exit",
"test-image": "npm run dist && docker-compose run tests",
+ "test-image:docker": "node node_modules/puppeteer/install.js && jest --config .jest.image.js --no-cache -i",
"argos": "node ./scripts/argos-upload.js",
"version": "node ./scripts/generate-version",
"install-react-16": "npm i --no-save --legacy-peer-deps react@16 react-dom@16",
@@ -287,7 +288,7 @@
"stylelint": "^14.9.0",
"stylelint-config-prettier": "^9.0.2",
"stylelint-config-rational-order": "^0.1.2",
- "stylelint-config-standard": "^29.0.0",
+ "stylelint-config-standard": "^28.0.0",
"stylelint-declaration-block-no-ignored-properties": "^2.1.0",
"stylelint-order": "^5.0.0",
"theme-switcher": "^1.0.2",