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
46 changes: 43 additions & 3 deletions ui/src/views/function-lib/component/FunctionFormDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<el-icon class="mr-4"><Plus /></el-icon> {{ $t('common.add') }}
</el-button>
</div>
<el-table :data="form.init_field_list" class="mb-16">
<el-table ref="initFieldTableRef" :data="form.init_field_list" class="mb-16">
<el-table-column prop="field" :label="$t('dynamicsForm.paramForm.field.label')">
<template #default="{ row }">
<span :title="row.field" class="ellipsis-1">{{ row.field }}</span>
Expand Down Expand Up @@ -188,7 +188,7 @@
</el-button>
</div>

<el-table :data="form.input_field_list" class="mb-16">
<el-table ref="inputFieldTableRef" :data="form.input_field_list" class="mb-16">
<el-table-column
prop="name"
:label="$t('views.functionLib.functionForm.form.paramName.label')"
Expand Down Expand Up @@ -280,7 +280,7 @@
</template>

<script setup lang="ts">
import { ref, reactive, watch } from 'vue'
import { ref, reactive, watch, nextTick } from 'vue'
import FieldFormDialog from './FieldFormDialog.vue'
import FunctionDebugDrawer from './FunctionDebugDrawer.vue'
import type { functionLibData } from '@/api/type/function-lib'
Expand All @@ -293,6 +293,7 @@ import { t } from '@/locales'
import UserFieldFormDialog from '@/workflow/nodes/base-node/component/UserFieldFormDialog.vue'
import { isAppIcon } from '@/utils/application'
import EditAvatarDialog from './EditAvatarDialog.vue'
import Sortable from 'sortablejs'

const props = defineProps({
title: String
Expand All @@ -303,6 +304,8 @@ const FieldFormDialogRef = ref()
const FunctionDebugDrawerRef = ref()
const UserFieldFormDialogRef = ref()
const EditAvatarDialogRef = ref()
const initFieldTableRef = ref()
const inputFieldTableRef = ref()

const FormRef = ref()

Expand Down Expand Up @@ -358,6 +361,40 @@ const rules = reactive({
]
})

function onDragHandle() {
// For init_field_list table
if (initFieldTableRef.value) {
const el = initFieldTableRef.value.$el.querySelector('.el-table__body-wrapper tbody')
Sortable.create(el, {
animation: 150,
ghostClass: 'sortable-ghost',
onEnd: ({ newIndex, oldIndex }) => {
if (newIndex === undefined || oldIndex === undefined) return
if (newIndex !== oldIndex) {
const item = form.value.init_field_list?.splice(oldIndex, 1)[0]
form.value.init_field_list?.splice(newIndex, 0, item)
}
}
})
}

// For input_field_list table
if (inputFieldTableRef.value) {
const el = inputFieldTableRef.value.$el.querySelector('.el-table__body-wrapper tbody')
Sortable.create(el, {
animation: 150,
ghostClass: 'sortable-ghost',
onEnd: ({ newIndex, oldIndex }) => {
if (newIndex === undefined || oldIndex === undefined) return
if (newIndex !== oldIndex) {
const item = form.value.input_field_list?.splice(oldIndex, 1)[0]
form.value.input_field_list?.splice(newIndex, 0, item)
}
}
})
}
}

function submitCodemirrorEditor(val: string) {
form.value.code = val
}
Expand Down Expand Up @@ -471,6 +508,9 @@ const open = (data: any) => {
visible.value = true
setTimeout(() => {
showEditor.value = true
nextTick(() => {
onDragHandle()
})
}, 100)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The provided code has some improvements and corrections that can be made:

  1. Import Statement:

    • Remove redundant import statement for Plus component as it's already imported before.
  2. Template Ref Usage:

    • The two reference variables (initFieldTableRef and inputFieldTableRef) are used but not referenced anywhere else in the template. This can be cleaned up by either using them to call methods like .value.scrollTo({ top ... }), or remove unused references if they're no longer needed.
  3. Sortable.js Initialization:

    • The initialization of Sortable should only happen when the table is rendered, which is done by adding a check inside the onLoad() lifecycle hook or an appropriate event listener to ensure all DOM elements are fully available.
    import { onMounted } from 'vue'
    
    onMounted(() => {
      onDragHandle()
    })
  4. Unused Imports/Variables:

    • There might be unused imports/variables such as UserFieldFormDialogRef or properties that are set elsewhere in the component logic.
  5. Performance Considerations:

    • If sorting becomes expensive due to large data sets, consider optimizing rendering performance or implementing batch updates in cases where changes are frequent.

Overall, addressing these points will help improve maintainability, usability, and potentially performance of the dynamic table interactions within your Vue application.

Expand Down