Skip to content
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
2 changes: 1 addition & 1 deletion ui/src/workflow/nodes/knowledge-base-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const nodeFields = computed(() => {
const fields = props.nodeModel.properties.user_input_field_list.map((item: any) => ({
label: typeof item.label == 'string' ? item.label : item.label.label,
value: item.field,
globeLabel: `{{global.${typeof item.label == 'string' ? item.label : item.label.label}}}`,
globeLabel: `{{global.${item.field}}}`,
globeValue: `{{context['global'].${item.field}}}`,
}))
set(props.nodeModel.properties.config, 'globalFields', fields)
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 appears to be setting up fields based on user input, and there are a few points that could improve clarity or functionality:

  1. Type Checking: Use strict type checking where possible. For example:

    type Field = {
      label?: string;
      field: string;
      globeLabel?: string;
    };
    
    const nodeFields = computed(() => {
      return props.nodeModel.properties.user_input_field_list.map((item: any): Field => ({
        label: typeof item.label === 'string' ? item.label : (item.label && item.label.label),
        value: item.field,
        globeLabel: global[item.label]?.label || '',
        globeValue: context.global[item.field] || '',
      }));
    });
  2. Conditional Handling for Globe Label:
    If you want to handle cases where global might not have the field (undefined, etc.), consider using optional chaining.

  3. String Interpolation: The use of mustache syntax {} can sometimes lead to confusion with other interpolation methods if used within template literals. Avoid mixing different formatting styles unless necessary.

  4. Set Function: Ensure this is being called properly and correctly applies changes.

By implementing these improvements, the code becomes more robust, easier to understand, and less prone to runtime errors related to missing properties.

Expand Down
Loading