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

fix: The switch node does not display default values #1957

Merged
merged 1 commit into from
Dec 31, 2024

Conversation

shaohuzhang1
Copy link
Contributor

fix: The switch node does not display default values

Copy link

f2c-ci-robot bot commented Dec 31, 2024

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.

Copy link

f2c-ci-robot bot commented Dec 31, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -208,6 +214,9 @@ const getDefaultValue = (row: any) => {
}
return row.default_value
}
if (row.default_value !== undefined) {
return row.default_value
}
}

const validate = () => {
Copy link
Contributor Author

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.

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

  2. 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).
  3. 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) {
Copy link
Contributor Author

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:

  1. Type Checking: Added type checks to ensure default_value is a string and option_list is an object.
  2. Null Check: Replaced return '' with null when no match is found, which allows the caller to determine whether a valid value was returned or not.
  3. Simplified Filtering Logic: Used find instead of filter 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!

@shaohuzhang1 shaohuzhang1 merged commit efa5c19 into main Dec 31, 2024
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_switch_default branch December 31, 2024 08:45
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.

1 participant