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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions ui/src/workflow/nodes/form-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@
<span :title="row.field" class="ellipsis-1">{{ row.field }}</span>
</template>
</el-table-column>
<el-table-column
prop="label"
:label="$t('dynamicsForm.paramForm.name.label')"
>
<el-table-column prop="label" :label="$t('dynamicsForm.paramForm.name.label')">
<template #default="{ row }">
<span v-if="row.label && row.label.input_type === 'TooltipLabel'">
<span :title="row.label.label" class="ellipsis-1">
Expand All @@ -97,28 +94,22 @@
</template>
</el-table-column>

<el-table-column
:label="$t('dynamicsForm.paramForm.input_type.label')"
width="110px"
>
<el-table-column :label="$t('dynamicsForm.paramForm.input_type.label')" width="110px">
<template #default="{ row }">
<el-tag type="info" class="info-tag">{{
input_type_list.find((item) => item.value === row.input_type)?.label
}}</el-tag>
</template>
</el-table-column>

<el-table-column
prop="default_value"
:label="$t('dynamicsForm.default.label')"
>
<el-table-column prop="default_value" :label="$t('dynamicsForm.default.label')">
<template #default="{ row }">
<span :title="row.default_value" class="ellipsis-1">{{
getDefaultValue(row)
}}</span>
</template>
</el-table-column>
<el-table-column :label="$t('common.required')" width="85">
<el-table-column :label="$t('common.required')" width="85">
<template #default="{ row }">
<div @click.stop>
<el-switch disabled size="small" v-model="row.required" />
Expand Down Expand Up @@ -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.

Expand Down