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
3 changes: 3 additions & 0 deletions ui/src/workflow/nodes/reranker-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ const validate = () => {

onMounted(() => {
getSelectModel()
form_data.value.show_knowledge = form_data.value.show_knowledge
? form_data.value.show_knowledge
: false
set(props.nodeModel, 'validate', validate)
})
</script>
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.

There are no irregularities or immediate issues with the provided code beyond minor syntax improvements and readability concerns. Here are some suggestions:

  1. Optional Chaining for Default Value: Consider using optional chaining (?.) to safely access nested properties before setting default values, though it's not necessary here since form_data.value should already be defined.

  2. Simplification of Conditional Logic: The conditional line can be simplified by removing unnecessary parentheses around the ternary operator condition.

Here’s an optimized version:

<template>
  <!-- Template content -->
</template>

<script setup lang="ts">
import { onMounted } from 'vue'

const validate = () => {
  // Validate logic
}

onMounted(() => {
  getSelectModel()

  if (!form_data.value.show_knowledge) {
    form_data.value.show_knowledge = false
  }

  set(props.nodeModel, 'validate', validate)
})
</script>

Key Points:

  • Avoid extra parentheses in ternary expressions for clarity.
  • Ensure that set(props.nodeModel, 'validate', validate) is called only once after initializing other related state.

These changes make the code more readable and slightly cleaner while maintaining its functionality.

Expand Down
3 changes: 3 additions & 0 deletions ui/src/workflow/nodes/search-knowledge-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ const validate = () => {
onMounted(() => {
// console.log(props.nodeModel.properties.node_data)
knowledgeList.value = props.nodeModel.properties.node_data.knowledge_list
form_data.value.show_knowledge = form_data.value.show_knowledge
? form_data.value.show_knowledge
: false
set(props.nodeModel, 'validate', validate)
})
</script>
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 provided code looks mostly clean and performs its intended functions effectively. However, I have a few points for consideration:

  1. The line form_data.value.show_knowledge is being reassigned with itself twice without changing its value, which might be unnecessary. It's fine as it is since the condition would only evaluate to true if show_knowledge was initially truthy.

  2. If you want to ensure that show_knowledge is of type boolean, you could add a validation step using Boolean() or check against specific values like 'true', 'false'. This can help avoid unexpected behavior when interacting with the data later on.

  3. As of current best practices, Vue 3 recommends using refs over directly accessing object properties (this.$refs). For example:

    // Using refs
    let showKnowledgeRef = ref(null);
    const updatedShowKnowledge = computed(() => (showKnowledgeRef.value || false);
    
    watch(showKnowledgeRef, newValue => {
      props.nodeModel.set('show_knowledge', Boolean(newValue));
    });

These changes will make the code more robust and maintainable.

Expand Down
Loading