Skip to content
Merged
Show file tree
Hide file tree
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/components/ai-chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ const handleScrollTop = ($event: any) => {
scrollTop.value = $event.scrollTop
if (
dialogScrollbar.value.scrollHeight - (scrollTop.value + scrollDiv.value.wrapRef.offsetHeight) <=
30
40
) {
scorll.value = true
} else {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The code you provided has a minor issue that can be improved for clarity and efficiency. Specifically, there seems to be a typographical error in the line where scorll is set to true. It looks like it should have scroll.value instead.

Additionally, while your changes from 30 to 40 make sense (likely increasing the threshold slightly), this change might need further justification based on context specific to your application. Here's the corrected version of the last three lines:

if (
  dialogScrollbar.value.scrollHeight - (scrollTop.value + scrollDiv.value.wrapRef.offsetHeight) <=
  40 // Increase this value as needed
) {
  scroll.value = true; // Use the correct property name here
} else {

This correction ensures consistent use of scroll.value, which appears to be an attribute used elsewhere in your function. If you intended to increase the sensitivity of when showing more content, consider adjusting the threshold beyond what is shown initially.

Expand Down
15 changes: 10 additions & 5 deletions ui/src/components/dynamics-form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,17 @@ const render = (
const value = formFieldList.value
.map((item) => {
if (form_data[item.field] !== undefined) {
const v: any = item.option_list?.filter(i => i.value_field === form_data[item.field])
if (v?.length > 0) {
return { [item.field]: form_data[item.field] };
if (item.value_field && item.option_list && item.option_list.length > 0) {
const value_field = item.value_field
const find = item.option_list?.find((i) => i[value_field] === form_data[item.field])
if (find) {
return { [item.field]: form_data[item.field] }
}
if (item.show_default_value === true || item.show_default_value === undefined) {
return { [item.field]: item.default_value }
}
} else {
return { [item.field]: item.default_value };
return { [item.field]: form_data[item.field] }
}
}
if (item.show_default_value === true || item.show_default_value === undefined) {
Expand All @@ -192,7 +198,6 @@ const render = (
return {}
})
.reduce((x, y) => ({ ...x, ...y }), {})

formValue.value = _.cloneDeep(value)
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The code you've provided looks mostly clean and well-structured. However, there are a few improvements that can be made:

  1. Variable Naming Consistency: While variable names are generally good, using consistent naming conventions can improve readability.

  2. Nullish Coalescing Operator: Replace || with nullish coalescing operator (??) to handle cases where show_default_value might be undefined.

  3. Avoid Unnecessary Cloning: The function _.cloneDeep(value) can be replaced with simpler deep copying mechanisms depending on your preference or environment.

Here's an optimized version of your code:

const render = (formFieldList: any[]): { [key: string]: any } => {
  const formData = {};
  const value = formFieldList.map((item) => {
    if (!formData[item.field]) formData[item.field] = {};

    // Use nullish coalescing for defaultValue and showDefaultValue
    const defaultVal = item.showDefault ? item.defaultValue : '';
    const defShow = item.showDefault ?? item.showDefaultValue;

    if (defShow || !formData[item.field][item.valueField]) {
      const val =
        formData[item.field]?.[item.valueField] ||
        item.option_list?.find(
          (opt) =>
            opt[item.valueField]
              ?.toLowerCase()
              .trim() ===
            form_data[item.field].toLowerCase().trim()
        )?.value_field ||
        defaultVal;
      
      formData[item.field][item.valueField] = val;
    }

    return formData[item.field];
  });

  return Object.values(formData).reduce((acc, curr) => ({ ...acc, ...curr }), {});
};

Key Improvements:

  • Consistent Variable Names: Renamed form_data to formData for better clarity.
  • Use of Nullish Coalescing: Used ?? instead of || when dealing with showDefault.
  • Simplified Conditional Logic: Combined similar conditions to reduce redundancy and make the logic more readable.
  • Improved Error Handling: If no matching option is found, it uses the default value specified in defaultValue, ensuring robustness against missing options.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
v-model="dialogVisible"
style="width: 550px"
append-to-body
destroy-on-close
:close-on-click-modal="false"
:close-on-press-escape="false"
>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The destroy-on-close attribute is not necessary for this context since it will cause the modal to be destroyed when closed, which may impact its performance if used frequently. Consider removing this line for better performance and clarity. The other attributes look correctly configured for a dialog component.

Expand Down