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
6 changes: 4 additions & 2 deletions ui/src/workflow/nodes/mcp-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
<template #label>
<div class="flex-between">
<div>
<TooltipLabel :label="item.label.label" :tooltip="item.label.attrs.tooltip" />
<TooltipLabel v-if="item.label.attrs.tooltip" :label="item.label.label" :tooltip="item.label.attrs.tooltip" />
<span v-else>{{ item.label.label }}</span>
<span v-if="item.required" class="color-danger">*</span>
</div>
<el-select
Expand Down Expand Up @@ -199,7 +200,8 @@
<template #label>
<div class="flex-between">
<div>
<TooltipLabel :label="item.label.label" :tooltip="item.label.attrs.tooltip" />
<TooltipLabel v-if="item.label.attrs.tooltip" :label="item.label.label" :tooltip="item.label.attrs.tooltip" />
<span v-else>{{ item.label.label }}</span>
<span v-if="item.required" class="color-danger">*</span>
</div>
<el-select
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 provided code snippet has some small improvements but can be optimized further:

  1. Simplify Tooltip Rendering: The conditional rendering of TooltipLabel and <span> can be simplified using Vue's ternary operator for better readability.
<template #label>
  <div class="flex-between">
    <div>
      {{ item.label.attrs.tooltip ? 
          <TooltipLabel label={item.label.label} tooltip={item.label.attrs.tooltip} /> :
          <span>{item.label.label}</span> }}
      <span v-if="item.required" class="color-danger">*</span>
    </div>
    <el-select
  1. Avoid Duplicated Code: There is repetition in the template for handling tooltips across different elements. If you have multiple similar components with labels that might contain tooltips, consider creating a reusable component.
<div class="tooltip-container">
  <TooltipLabel v-if="hasTooltip(label)" :label="$t('common.field_label')" :tooltip="label.attrs.tooltip"/>
</div>

<script>
export default {
  data() {
    return { /* Your other data */ };
  },
  methods: {
    hasTooltip(item) {
      return Object.keys(item.label.attrs).includes('tooltip');
    }
  },
};
</script>
  1. Update Documentation Comments: It would help improve maintainability to add more documentation comments explaining specific parts of the code (e.g., why certain conditions are checked).

  2. Potential Bug: Ensure that the required attribute is correctly used with HTML attributes; it seems like a typo (class="color-danger" instead of aria-required). Adjust this if necessary.

These optimizations make the code cleaner and potentially enhance performance by reducing repetitive logic.

Expand Down
Loading