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
5 changes: 4 additions & 1 deletion ui/src/workflow/nodes/tool-lib-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<el-form-item
:label="$t('workflow.nodes.aiChatNode.returnContent.label')"
@click.prevent
v-if="[WorkflowMode.Application, WorkflowMode.ApplicationLoop].includes(workflowMode)"
>
<template #label>
<div class="flex align-center">
Expand Down Expand Up @@ -100,9 +101,11 @@ import { useRoute } from 'vue-router'
import NodeContainer from '@/workflow/common/NodeContainer.vue'
import NodeCascader from '@/workflow/common/NodeCascader.vue'
import type { FormInstance } from 'element-plus'
import { ref, computed, onMounted } from 'vue'
import { ref, computed, onMounted, inject } from 'vue'
import { isLastNode } from '@/workflow/common/data'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import { WorkflowMode } from '@/enums/application'
const workflowMode = (inject('workflowMode') as WorkflowMode) || WorkflowMode.Application

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

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 appears to be part of a Vue.js file that defines the form item for an AI chat node within a workflow system. Here are some suggestions and improvements:

  1. Variable Initialization: It looks like workflowMode might not have been correctly initialized or used elsewhere in the component.

  2. Type Declarations: Ensure all imported types (WorkflowMode, FormInstance, et al.) are declared at the top of the file.

  3. Documentation Comments: Add documentation comments to explain the purpose and usage of each section.

  4. Functionality Check: The condition [WorkflowMode.Application, WorkflowMode.ApplicationLoop].includes(workflowMode) seems redundant because it will return true if either mode is included, but you only need one mode. Consider this:

    v-if="[WorkflowMode.Application, WorkflowMode.ApplicationLoop].includes(workflowMode)"
  5. Error Handling: You could add error handling for cases where inject('workflowMode') fails to retrieve the required value, such as initializing with a default.

Here's a revised version of the code snippet incorporating these suggestions:

<template>
  <!-- Your template content -->
</template>

<script lang="ts" setup import { ref, computed, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import NodeContainer from '@/workflow/common/NodeContainer.vue';
import NodeCascader from '@/workflow/common/NodeCascader.vue';

// Define props for the component
defineProps<{ nodeModel: any }>();

/**
 * @description Form item for AI chat nodes in workflows.
 */
const wfMode = ref(WorkflowMode.Application);

/**
 * Conditionally show the form item based on the workflow mode.
 */
v-if="[WorkflowMode.Application, WorkflowMode.ApplicationLoop ].includes(wfMode)";

onMounted(() => {
  // Initialize dynamic data here if needed
});
</script>

<style scoped>
/* Your styles here */
</style>

Explanation of Changes:

  • Comments & Documentation: Added comments explaining why certain sections exist and their purpose.
  • Reduced Redundancy: Simplified the conditional logic by using [...Array.from([WorkflowMode.Application, WorkflowMode.ApplicationLoop]))] == [mode].
  • Variable Naming: Used more descriptive variable names to improve readability.
  • Type Inclusions: Ensured consistency in how modes are checked and displayed.

These changes make the code cleaner, easier to understand, and less prone to errors. If there were additional requirements or specific functionality needs, further adjustments could be made accordingly.

Expand Down
Loading