-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: The switch node does not display default values #1957
Conversation
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. 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. |
[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.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -208,6 +214,9 @@ const getDefaultValue = (row: any) => { | |||
} | |||
return row.default_value | |||
} | |||
if (row.default_value !== undefined) { | |||
return row.default_value | |||
} | |||
} | |||
|
|||
const validate = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no immediate irregularities, potential issues, or optimization opportunities identified in the provided Vue.js template with an El Table component.
-
Line Length: The line length of the template is slightly too long, which might not be ideal according to some coding guidelines but does not affect functionality.
-
Code Clarity:
- In
validate
function, you have duplicate checks (if (rule.value === '')
). It's unnecessary because checking against an empty string will naturally fall through to the next condition when it doesn't match other conditions (like type validation).
- In
-
Empty Row Handling:
- You may want to consider handling rows where neither a field nor a default value is specified more gracefully. This could involve displaying "N/A" or another placeholder depending on your UI/UX requirements. Currently, these values would default to their native JavaScript behavior.
Overall, the code appears straightforward and functional within the context of generating a table from an array of dynamic fields. Here’s a minor improvement for better clarity:
const validate = () => {
return form_data.form_field_list.every(field => {
if ((field.hasOwnProperty('field') && field.field.trim() === '') ||
(!field.hasOwnProperty('default_value'))) {
errors.push({
dataPath: `/form_field/${index}`,
message: 'Field name or Default value must be filled out.'
});
}
});
}
This adjustment ensures that each field in the list has either a non-empty field name and/or a defined default value before proceeding with validation. Adjustments can always be made based on specific application needs regarding error messages and user interface logic.
} | ||
|
||
|
||
onMounted(() => { | ||
if (!props.nodeModel.properties.user_input_field_list) { | ||
if (props.nodeModel.properties.input_field_list) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can review this code snippet for you. Here are some suggestions:
const getDefaultValue = (row: any): string | null => {
if (typeof row.default_value === 'string' && typeof row.option_list === 'object') {
return row.option_list.find(option => option.value.includes(row.default_value))
? row.option_list.filter(option => option.value.includes(row.default_value)).map(option => option.label).join(', ')
: null;
} else if (typeof row.default_value !== 'undefined') {
return String(row.default_value);
}
return '';
};
Changes and Suggestions:
- Type Checking: Added type checks to ensure
default_value
is a string andoption_list
is an object. - Null Check: Replaced
return ''
withnull
when no match is found, which allows the caller to determine whether a valid value was returned or not. - Simplified Filtering Logic: Used
find
instead offilter
where possible to find only matches without creating unnecessary arrays.
This should help improve the robustness and maintainability of the getDefaultValues
function. Let me know if you have any other questions!
fix: The switch node does not display default values