alibaba / alibaba/lowcode-engine
支持控制MixedSetter默认选中setter
Aperta
@hzd822 ci sta già lavorando.
Dal 1/8/2023.
- Lingua principale
- TypeScript
- Stelle
- 15.9k
- Fork
- 2.7k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
背景
我在给antd table配置shouldUpdate属性, 这个属性支持boolean 和 函数, 但大部分情况下用户会使用函数类型的props.
所以我希望优先使用FunctionSetter, 物料meta.js:
{
name: 'shouldUpdate',
title: {
label: '自定义更新',
tip: 'shouldUpdate | 自定义更新函数',
},
setter: {
componentName: 'MixedSetter',
props: {
setters: [
{
componentName: 'FunctionSetter',
props: {},
},
{
componentName: 'BoolSetter',
},
],
},
},
},
但结果是, 在属性面板首次渲染时展示的是 BoolSetter
原因是, getCurrentSetter (在lowcode-engine-ext/src/setter/mixed-setter/index.tsx)
private getCurrentSetter() {
const { field } = this.props;
let firstMatched: SetterItem | undefined;
let firstDefault: SetterItem | undefined;
for (const setter of this.setters) {
if (setter.name === this.used) {
return setter;
}
if (!setter.condition) {
if (!firstDefault) {
firstDefault = setter;
}
continue;
}
if (!firstMatched && setter.condition(field)) {
firstMatched = setter;
}
}
return firstMatched || firstDefault || this.setters[0];
}
FunctionSetter是带有condition的, 但是首次渲染时候,field没有值,所以上面的这段代码if (!firstMatched && setter.condition(field))就返回false。而BoolSetter由于没condition 被设为firstDefault
const FunctionBindSetter = {
component: FunctionSetter,
title: '函数绑定',
condition: (field: any) => {
const v = field.getValue();
return isJSFunction(v);
},
valueType: ['JSFunction'],
};
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.