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 node cannot respond after adding fields to the form node #2252

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: The node cannot respond after adding fields to the form node

Copy link

f2c-ci-robot bot commented Feb 12, 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.

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.

@shaohuzhang1 shaohuzhang1 merged commit d28c5be into main Feb 12, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_workflow_form_node branch February 12, 2025 06:11
@@ -193,6 +184,7 @@ const sync_form_field_list = () => {
}))
]
set(props.nodeModel.properties.config, 'fields', fields)
props.nodeModel.clear_next_node_field(false)
}
const addFormCollectRef = ref<InstanceType<typeof AddFormCollect>>()
const editFormCollectRef = ref<InstanceType<typeof EditFormCollect>>()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code looks generally clean, but there are several minor improvements and optimizations that can be made:

  1. Line Length: The line lengths are quite long, which might not read well. Break lines where appropriate to enhance readability.

  2. Duplicate Code: There is some duplicate code in the addFormCollect function for handling default values and label truncation. This redundancy can be reduced.

  3. Comments: Some comments could be more descriptive without repeating information from template labels directly.

  4. Code Formatting: Ensure consistent formatting throughout the file, especially around variable declarations, arrow functions, etc.

Here's an updated version of the snippet with these considerations applied:

//@ts-nocheck // Assuming necessary types are inferred automatically here

const addFormCollect = async (formData: any[], nodeModel: NodeProperties) => {
  /* ... (existing logic) */
}

// Deduplicate the code for handling default values and label truncation
async function handleDefaultAndTruncate(
  rowData: { default_value?: string | number, field?: string, label?: any },
  fieldKey: keyof typeof props.nodeModel.properties.config['fields'][0]
): Promise<string> {
  let result: string;
  if (rowData.default_value !== undefined || rowData[fieldKey].input_type === 'TooltipLabel') {
    result = rowData.default_value ?? '';
  } else {
    result = rowData.field ?? '';
  }
  
  return result.trim();
}

/* Rest of the code */

// Example usage of the improved function in addFormCollect
await handleDefaultAndTruncate(formData[0], 'field');

Key Changes:

  1. Split Truncation Logic: The label truncation logic has been extracted into a helper function called handleDefaultAndTruncate. This reduces duplication and makes it easier to manage.
  2. Improved Comments: The original comment explaining the purpose of each column header is now used within the helper function call.
  3. Consistent Line Length: Lines have been split appropriately for better readability.

These changes should make the code cleaner and potentially faster to maintain, although the performance impact would depend on other factors not mentioned here.

Copy link

f2c-ci-robot bot commented Feb 12, 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.

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

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