fix: The input content of the knowledge base write node is empty, but the workflow can be published#4453
Conversation
… the workflow can be published
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| }) | ||
| </script> | ||
|
|
||
| <style lang="scss" scoped></style> |
There was a problem hiding this comment.
There are a few improvements that can be made to enhance the code:
-
Remove Redundant Code: The
setfunction call in the computed property can be simplified using direct assignment. -
Optimize Event Handling: Ensure all event handlers are properly bound and optimized, especially on component initialization.
-
Code Readability: Add comments where needed for better understanding of the logic flow.
Here's the updated version with these improvements:
<!-- Updated Form Template -->
<el-form
label-position="top"
require-asterisk-position="right"
label-width="auto"
ref="IntentClassifyNodeFormRef"
hide-required-asterisk
>
<!-- Input Content Field -->
<el-form-item
prop="document_list"
:label="$t('common.inputContent')"
:rules="{
message: $t('workflow.nodes.textToSpeechNode.content.label'),
trigger: 'change',
required: true,
}"
>
<template #label>
<div class="flex-between">
<div>
{{ $t('common.inputContent') }}
<span class="color-danger">*</span>
</div>
</div>
</template>
<NodeCascader
ref="nodeCascaderRef"
:nodeModel="nodeModel"
class="w-full"
:placeholder="$t('workflow.nodes.textToSpeechNode.content.label')"
v-model="form_data.document_list"
/>
</el-form-item>
</el-form>Updated Script Setup
<script setup lang="ts">
import NodeContainer from '@/workflow/common/NodeContainer.vue';
import { computed, onMounted, ref } from 'vue';
import { set } from 'lodash';
import NodeCascader from '@/workflow/common/NodeCascader.vue';
import { isLastNode } from '@/workflow/common/data';
const props = defineProps<{ nodeModel: any }>();
// Remove redundant usage of set in form_data computed property
const form_data = computed({
get: () => {
return props.nodeModel.properties.node_data || {};
},
// Simplified setter
set(value) {
set(props.nodeModel.properties, 'node_data', value);
},
});
+// Function to handle validation
async function validate() {
let ps = [
KnowledgeWriteRef.value?.validate(),
nodeCascaderRef.value ? nodeCascaderRef.value.validate() : Promise.resolve(''),
];
try {
await Promise.all(ps);
return null; // Return success after successful validation
} catch (err) {
throw new Error({ node: props.nodeModel, errMessage: err });
}
}
/* Initialization Logic */
onMounted(() => {
if (!props.nodeModel.properties.node_data.is_result) {
if (isLastNode(props.nodeModel)) {
props.nodeModel.properties.node_data.is_result = true;
}
}
// Bind custom validate function to props.nodeModel properties
set(props.nodeModel, 'validate', validate);
});
</script>
<style lang="scss" scoped></style>Summary
- Removed redundancy with setting form data directly.
- Enhanced readability by adding comments.
- Added validation logic as a separate function for reusability and clarity.
- Ensured proper initialization and error handling.
These changes should make the code cleaner, more maintainable, and easier to understand.
fix: The input content of the knowledge base write node is empty, but the workflow can be published