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
15 changes: 13 additions & 2 deletions ui/src/workflow/nodes/data-source-local-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
label-position="top"
require-asterisk-position="right"
label-width="auto"
ref="NodeFormRef"
>
<el-form-item
:label="$t('workflow.nodes.dataSourceLocalNode.fileFormat.label')"
Expand All @@ -17,6 +18,7 @@
message: $t('workflow.nodes.dataSourceLocalNode.fileFormat.requiredMessage'),
trigger: 'change',
}"
prop="file_type_list"
>
<el-select
v-model="form_data.file_type_list"
Expand Down Expand Up @@ -46,6 +48,7 @@
message: $t('common.inputPlaceholder'),
trigger: 'change',
}"
prop="file_count_limit"
>
<el-input-number
v-model="form_data.file_count_limit"
Expand All @@ -65,6 +68,7 @@
message: $t('common.inputPlaceholder'),
trigger: 'change',
}"
prop="file_size_limit"
>
<el-input-number
v-model="form_data.file_size_limit"
Expand All @@ -84,9 +88,9 @@

<script setup lang="ts">
import NodeContainer from '@/workflow/common/NodeContainer.vue'
import { computed } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { set } from 'lodash'

const NodeFormRef = ref()
const props = defineProps<{ nodeModel: any }>()

const file_type_list_options = ['TXT', 'DOCX', 'PDF', 'HTML', 'XLS', 'XLSX', 'ZIP', 'CSV']
Expand All @@ -109,6 +113,13 @@ const form_data = computed({
set(props.nodeModel.properties, 'node_data', value)
},
})
const validate = () => {
return NodeFormRef.value.validate()
}

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

<style lang="scss" scoped></style>
Copy link
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 noticeable logical errors in the provided code snippet. However, there is one minor issue and an optimization suggestion:

Issues Found:

  1. TypeScript ref Usage: The <template> uses ref, which might not be necessary since you're directly using it in JavaScript without assigning to a template variable.

Optimization Suggestions:

  1. Avoid Assigning Validation Method Directly: In Vue 3 Composition API with TypeScript, it's generally better practice to pass functions through props rather than assigning them directly as instance methods. This makes testing easier and keeps component logic cleaner.

Here's how you can address these points:

Updated Code:

<template>
  <el-form
    :model="form_data"
    label-align="left"
    inline
    label-position="top"
    require-asterisk-position="right"
    label-width="auto"
    ref="NodeFormRef"
  >
    <!-- Form items here -->
  </el-form>
</template>

<script setup lang="ts">
import NodeContainer from '@/workflow/common/NodeContainer.vue'
import { computed } from 'vue'

const file_type_list_options = [
  'TXT',
  'DOCX',
  'PDF',
  'HTML',
  'XLS',
  'XLSX',
  'ZIP',
  'CSV',
]

export default defineComponent({
  components: {
    NodeContainer,
  },
  setup(props) {
    // Refs should only be used when needed
    const NodeFormRef = ref(null)

    const form_data = computed<any>({
      get() {
        return props.nodeModel?.properties || {}
      },
      set(value) {
        set(props.nodeModel?.properties || {}, 'node_data', value)
      },
    })

    const validate = () => {
      return NodeFormRef.value.validate()
    }

    onMounted(() => {
      // Optionally, if needed, assign validation function to properties object
      // But this might be overkill given that we already have a ref-based approach
      //
      // If required outside of this component scope, consider moving into another utility function/module

      // Example usage: `props.nodeModel.validate(file_form_data)`
    })

    return {
      NodeFormRef,
      form_data,
      validate,
    }
  },
})
</script>

<style lang="scss" scoped></style>

Key Changes:

  1. Removed Unused ref Assignment:

    const NodeFormRef = ref()
  2. Encapsulated Validation Logic:
    Moved the validation logic into the setup function where it can be passed down via props or other means as needed.

  3. Consistent Syntax for Computed Properties:
    Changed the way computed is defined inside the setup function to make it more consistent with typical setups.

Loading