fix(Table): fix invalid pagination (#3821)
* fix(Table): fix invalid pagination * test: add test * fix: unit test bug --------- Co-authored-by: dream2023 <1098626505@qq.com>
This commit is contained in:
parent
c4aa8b78c2
commit
ac5a82fde3
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { SchemaComponent, SchemaComponentProvider } from '../../../schema-component';
|
||||
import { render, screen, sleep, userEvent, waitFor } from '@nocobase/test/client';
|
||||
import { render } from '@nocobase/test/client';
|
||||
import { withDynamicSchemaProps } from '../../hoc';
|
||||
|
||||
const HelloComponent = withDynamicSchemaProps((props: any) => (
|
||||
@ -66,7 +66,7 @@ describe('withDynamicSchemaProps', () => {
|
||||
|
||||
const Demo = withTestDemo(schema, scopes);
|
||||
const { getByTestId } = render(<Demo />);
|
||||
expect(getByTestId('component')).toHaveTextContent(JSON.stringify({ a: 'a', b: 'b' }));
|
||||
expect(getByTestId('component')).toHaveTextContent(JSON.stringify({ b: 'b', a: 'a' }));
|
||||
});
|
||||
|
||||
test('x-use-decorator-props', () => {
|
||||
@ -101,7 +101,7 @@ describe('withDynamicSchemaProps', () => {
|
||||
|
||||
const Demo = withTestDemo(schema, scopes);
|
||||
const { getByTestId } = render(<Demo />);
|
||||
expect(getByTestId('decorator')).toHaveTextContent(JSON.stringify({ a: 'a', b: 'b' }));
|
||||
expect(getByTestId('decorator')).toHaveTextContent(JSON.stringify({ b: 'b', a: 'a' }));
|
||||
});
|
||||
|
||||
test('x-use-component-props and x-use-decorator-props exist simultaneously', () => {
|
||||
@ -130,8 +130,8 @@ describe('withDynamicSchemaProps', () => {
|
||||
|
||||
const Demo = withTestDemo(schema, scopes);
|
||||
const { getByTestId } = render(<Demo />);
|
||||
expect(getByTestId('decorator')).toHaveTextContent(JSON.stringify({ a: 'a', b: 'b' }));
|
||||
expect(getByTestId('component')).toHaveTextContent(JSON.stringify({ c: 'c', d: 'd' }));
|
||||
expect(getByTestId('decorator')).toHaveTextContent(JSON.stringify({ b: 'b', a: 'a' }));
|
||||
expect(getByTestId('component')).toHaveTextContent(JSON.stringify({ d: 'd', c: 'c' }));
|
||||
});
|
||||
|
||||
test('no register scope', () => {
|
||||
@ -142,4 +142,23 @@ describe('withDynamicSchemaProps', () => {
|
||||
const { getByTestId } = render(<Demo />);
|
||||
expect(getByTestId('component')).toHaveTextContent(JSON.stringify({}));
|
||||
});
|
||||
|
||||
test('x-use-component-props should override x-component-props', () => {
|
||||
function useComponentProps() {
|
||||
return {
|
||||
a: 'a',
|
||||
};
|
||||
}
|
||||
const schema = {
|
||||
'x-use-component-props': 'useComponentProps',
|
||||
'x-component-props': {
|
||||
a: 'b',
|
||||
},
|
||||
};
|
||||
const scopes = { useComponentProps };
|
||||
|
||||
const Demo = withTestDemo(schema, scopes);
|
||||
const { getByTestId } = render(<Demo />);
|
||||
expect(getByTestId('component')).toHaveTextContent(JSON.stringify({ a: 'a' }));
|
||||
});
|
||||
});
|
||||
|
@ -9,7 +9,7 @@ interface WithSchemaHookOptions {
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
export function withDynamicSchemaProps<T = any>(Component: ComponentType<T>, options: WithSchemaHookOptions = {}) {
|
||||
export function withDynamicSchemaProps<T = any>(Component: any, options: WithSchemaHookOptions = {}) {
|
||||
const displayName = options.displayName || Component.displayName || Component.name;
|
||||
const ComponentWithProps: ComponentType<T> = (props) => {
|
||||
const { dn, findComponent } = useDesignable();
|
||||
@ -41,7 +41,7 @@ export function withDynamicSchemaProps<T = any>(Component: ComponentType<T>, opt
|
||||
const schemaProps = useSchemaProps(props);
|
||||
|
||||
const memoProps = useMemo(() => {
|
||||
return merge(omit(schemaProps, 'children'), omit(props, 'children'));
|
||||
return merge(omit(props, 'children'), omit(schemaProps, 'children'));
|
||||
}, [schemaProps, props]);
|
||||
|
||||
return <Component {...memoProps}>{props.children}</Component>;
|
||||
|
@ -230,7 +230,7 @@ export const Table: any = withDynamicSchemaProps(
|
||||
isSubTable?: boolean;
|
||||
}) => {
|
||||
const { token } = useToken();
|
||||
const { pagination: pagination1, useProps, onChange, ...others1 } = props;
|
||||
const { pagination: pagination1, useProps, ...others1 } = props;
|
||||
|
||||
// 新版 UISchema(1.0 之后)中已经废弃了 useProps,这里之所以继续保留是为了兼容旧版的 UISchema
|
||||
const { pagination: pagination2, ...others2 } = useProps?.() || {};
|
||||
|
Loading…
Reference in New Issue
Block a user