Skip to content

fix: Fix default_value not show when image model changed#2464

Merged
liuruibin merged 1 commit intomainfrom
pr@main@fix_show_default
Mar 3, 2025
Merged

fix: Fix default_value not show when image model changed#2464
liuruibin merged 1 commit intomainfrom
pr@main@fix_show_default

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

fix: Fix default_value not show when image model changed --bug=1052695 --user=刘瑞斌 【应用】高级编排-设置-图片生成组件-切换模型后图片尺寸为空-未同步切换到当前模型的首个尺寸 https://www.tapd.cn/57709429/s/1661346

--bug=1052695 --user=刘瑞斌 【应用】高级编排-设置-图片生成组件-切换模型后图片尺寸为空-未同步切换到当前模型的首个尺寸 https://www.tapd.cn/57709429/s/1661346
@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Mar 3, 2025

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.

Details

Instructions 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.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Mar 3, 2025

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

}
}
if (item.show_default_value === true || item.show_default_value === undefined) {
return { [item.field]: item.default_value }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code has a few issues that can be addressed:

  1. Type Safety: The type assertion const v: any is unnecessary and could lead to runtime errors.
  2. 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:

  1. Removed Type Assertion: Removed any type assertion; typescript will infer the correct type based on conditions.
  2. Simplified Logic: Used .some() to check if there is at least one option with a matching value_field, rather than .filter(), which would require handling multiple matches separately.

This should make the code cleaner and more efficient while maintaining correctness.

@liuruibin liuruibin merged commit 5e56305 into main Mar 3, 2025
4 of 5 checks passed
@liuruibin liuruibin deleted the pr@main@fix_show_default branch March 3, 2025 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants