-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: After selecting the knowledge base for the knowledge base retrieval node, copy the node, but the new node does not have the control for selecting the knowledge base #4170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,7 @@ function addKnowledge(val: Array<any>) { | |
| 'knowledge_id_list', | ||
| val.map((item) => item.id), | ||
| ) | ||
| set(props.nodeModel.properties.node_data, 'knowledge_list', val) | ||
| knowledgeList.value = val | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code seems mostly correct for what it appears to be doing. However, there are a few suggestions and improvements:
Here's an updated version with these considerations: function addKnowledge(val: Array<any>, props): void {
try {
// Map over the value array to get ids and store them in the state
const knowledgeIdList = val.map((item) => item.id);
// Set the property for knowledge IDs on node data
set(props.nodeModel.properties.node_data, 'knowledge_id_list', knowledgeIdList);
// Store the updated values in local variable
set(props.nodeModel.properties.node_data, 'knowledge_list', val[0] ? [...props.nodeModel.properties.node_data.knowledge_list || [], ...val] : []);
// Update the local state with the new values
knowledgeList.value = [props?.nodes?.values?.map(v=>v.data)[0],...val];
} catch (error) {
console.error("An error occurred while adding knowledge:", error);
}
}Key Changes:
These changes make the function more robust and easier to maintain. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code looks mostly clean and efficient. However, there are a few things you can consider to improve:
Import Statement: The
cloneDeepimport is necessary if you're using it later in your code. It's good practice to only import what's needed.Translation Functions: Ensure that
translationNodeData,translationEdgeData,t(assuming this is a message translation function), andTRANSLATION_DISTANCEare correctly defined elsewhere in your project.Here’s a slightly optimized version of the code with minor improvements:
Optimizations Made:
Conditional Selection Type Checking:
This checks whether each element found in
baseNodesis an instance ofIGraphItem.Using CloneDeep Only When Necessary:
Ensures that
cloneDeepis only called when truly necessary based on the context.Type Annotations:
Added a simple type annotation for clarity, assuming
IGraphItemrepresents the structure of items retrieved from Logic Flow.These changes are aimed at making the code more readable and maintainable while ensuring correctness. If you have access to the rest of your codebase, further optimizations may be possible depending on other dependencies and use cases.