fix: 修复 defaultData 中配置 schema, 存在数据映射冲突问题 Close: #8972 (#9891)

This commit is contained in:
liaoxuezhi 2024-03-27 17:26:35 +08:00 committed by GitHub
parent cc107fd3fa
commit 919044f4bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 6 deletions

View File

@ -67,7 +67,8 @@ export const RENDERER_TRANSMISSION_OMIT_PROPS = [
'renderLabel',
'trackExpression',
'editorSetting',
'updatePristineAfterStoreDataReInit'
'updatePristineAfterStoreDataReInit',
'source'
];
const componentCache: SimpleMap = new SimpleMap();

View File

@ -20,6 +20,19 @@ import {
import {dataMapping, tokenize} from './utils/tpl-builtin';
import {RootStoreContext} from './WithRootStore';
/**
* schema
*
* https://github.com/baidu/amis/issues/8972 中的用法
*/
function ignoreSchemaProps(key: string, value: any) {
if (['clickAction'].includes(key) && typeof value !== 'string') {
return true;
}
return false;
}
export function HocStoreFactory(renderer: {
storeType: string;
extendsData?: boolean | ((props: any) => boolean);
@ -86,7 +99,11 @@ export function HocStoreFactory(renderer: {
: null,
{
...this.formatData(
dataMapping(this.props.defaultData, this.props.data)
dataMapping(
this.props.defaultData,
this.props.data,
ignoreSchemaProps
)
),
...this.formatData(this.props.data)
}
@ -100,7 +117,11 @@ export function HocStoreFactory(renderer: {
store.initData(
createObject(this.props.store.data, {
...this.formatData(
dataMapping(this.props.defaultData, this.props.data)
dataMapping(
this.props.defaultData,
this.props.data,
ignoreSchemaProps
)
)
})
);
@ -110,7 +131,11 @@ export function HocStoreFactory(renderer: {
(this.props.data as any).__super || this.props.scope,
{
...this.formatData(
dataMapping(this.props.defaultData, this.props.data)
dataMapping(
this.props.defaultData,
this.props.data,
ignoreSchemaProps
)
),
...this.formatData(this.props.data)
}
@ -120,7 +145,11 @@ export function HocStoreFactory(renderer: {
} else {
store.initData({
...this.formatData(
dataMapping(this.props.defaultData, this.props.data)
dataMapping(
this.props.defaultData,
this.props.data,
ignoreSchemaProps
)
),
...this.formatData(this.props.data)
});

View File

@ -154,7 +154,7 @@ export default class List extends React.Component<ListProps, object> {
} else {
action = item.clickAction!;
}
handleAction(e, action as ActionSchema, this.props);
handleAction(e, action as ActionSchema, this.props, item);
};
}