fix: Fix default_value not show when image model changed#2464
Conversation
--bug=1052695 --user=刘瑞斌 【应用】高级编排-设置-图片生成组件-切换模型后图片尺寸为空-未同步切换到当前模型的首个尺寸 https://www.tapd.cn/57709429/s/1661346
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| } | ||
| } | ||
| if (item.show_default_value === true || item.show_default_value === undefined) { | ||
| return { [item.field]: item.default_value } |
There was a problem hiding this comment.
The provided code has a few issues that can be addressed:
- Type Safety: The type assertion
const v: anyis unnecessary and could lead to runtime errors. - Logic Simplification: Instead of filtering for an exact match, you might want to consider using strict equality (
===) when comparing values.
Here's the revised version of the code with these improvements:
const render = (...):
// ...
if (form_data[item.field] !== undefined && form_field_list.item.option_list.some(i => i.value_field === form_data[item.field])) {
return { [item.field]: form_data[item.field] };
} else if (item.show_default_value === true || item.show_default_value === undefined) {
return { [item.field]: item.default_value }
}
// ...Key Changes:
- Removed Type Assertion: Removed
anytype assertion; typescript will infer the correct type based on conditions. - Simplified Logic: Used
.some()to check if there is at least one option with a matchingvalue_field, rather than.filter(), which would require handling multiple matches separately.
This should make the code cleaner and more efficient while maintaining correctness.
fix: Fix default_value not show when image model changed --bug=1052695 --user=刘瑞斌 【应用】高级编排-设置-图片生成组件-切换模型后图片尺寸为空-未同步切换到当前模型的首个尺寸 https://www.tapd.cn/57709429/s/1661346