Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: material spec add ignoreDefaultValue field to component property description #1720

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/specs/material-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ props 数组下对象字段描述:
| defaultValue | 默认值 | Any(视字段类型而定) | type = 'field' 生效 |
| supportVariable | 是否支持配置变量 | Boolean | type = 'field' 生效 |
| condition | 配置当前 prop 是否展示 | (target: IPublicModelSettingField) => boolean; | - |
| ignoreDefaultValue | 配置当前 prop 是否忽略默认值处理逻辑,如果返回值是 true 引擎不会处理默认值 | (target: IPublicModelSettingField) => boolean; | - |
| setter | 单个控件 (setter) 描述,搭建基础协议组件的描述对象,支持 JSExpression / JSFunction / JSSlot | `String\|Object\|Function` | type = 'field' 生效 |
| extraProps | 其他配置属性(不做流通要求) | Object | 其他配置 |
| extraProps.getValue | setter 渲染时被调用,setter 会根据该函数的返回值设置 setter 当前值 | Function | (target: IPublicModelSettingField, value: any) => any; |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
return true;
}

get ignoreDefaultValue(): boolean {
const { extraProps } = this.field;
const { ignoreDefaultValue } = extraProps;
try {
return typeof ignoreDefaultValue === 'function' ? ignoreDefaultValue(this.field.internalToShell()) : false;
} catch (error) {
console.error('exception when ignoreDefaultValue is excuted', error);
}

return false;
}

get setterInfo(): {
setterProps: any;
initialValue: any;
Expand Down Expand Up @@ -171,6 +183,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
const { initialValue } = this.setterInfo;
if (this.state?.fromOnChange ||
!isInitialValueNotEmpty(initialValue) ||
this.ignoreDefaultValue ||
this.value !== undefined
) {
return;
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/shell/type/field-extra-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export interface IPublicTypeFieldExtraProps {
*/
condition?: (target: IPublicModelSettingField) => boolean;

/**
* 配置当前 prop 是否忽略默认值处理逻辑,如果返回值是 true 引擎不会处理默认值
* @returns boolean
*/
ignoreDefaultValue?: (target: IPublicModelSettingField) => boolean;

/**
* autorun when something change
*/
Expand Down