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
2 changes: 1 addition & 1 deletion ui/src/components/dynamics-form/items/tree/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import type Node from 'element-plus/es/components/tree/src/model/node'
import { get, post, put, del } from '@/request/index'
import { cloneDeep } from 'lodash'
import { formItemContextKey } from 'element-plus'
const get_extra = inject('get_extra') as any
const elFormItem = inject(formItemContextKey, void 0)
const request = {
get,
Expand Down Expand Up @@ -168,7 +169,6 @@ function renderTemplate(template: string, data: any) {
}

const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => {
const get_extra = inject('get_extra') as any
request_call(request, {
url: renderTemplate(
'/workspace/${current_workspace_id}/knowledge/${current_knowledge_id}/datasource/tool/${current_tool_id}/' +
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 code looks clean overall, but there are a few suggestions for improvement:

  1. Variable Duplicates: The variable get_extra is declared twice with different aliases (const get_extra = ... and const { get_extra } = extractFields(...)). This redundancy can be removed.

  2. Type Annotations: Consider adding type annotations to the variables and functions where applicable to improve readability and maintainability.

  3. Avoid Assignments Inside Conditions: Direct assignments inside conditional statements should be used judiciously to avoid unexpected behavior.

  4. Optimize Object Access: If you often access properties on objects using dynamic keys like ${current_workspace_id}, consider creating separate constants for these properties if they're not frequently changed.

  5. Commenting: Add comments explaining complex logic or parts of the code that might not be immediately obvious.

Here's an updated version of the code incorporating some of these suggestions:

import type Node from 'element-plus/es/components/tree/src/model/node';
import { get, post, put, del } from '@/request/index';
import cloneDeep from 'lodash';
import { formItemContextKey } from 'element-plus';

// Remove redundant assignement
const context = inject(contextKey);

function renderTemplate(template: string, data: any) {
}

const loadNode = (node: Node, resolve: (nodeData: Tree[]) => void) => {
  // Create a constant for common template parameters
  const workspaceId = currentWorkspaceID;
  const knowledgeId = currentKnowledgeID;
  const toolId = currentToolID;

  request_call(request, {
    url: renderTemplate(
      `/workspace/${workspaceId}/knowledge/${knowledgeId}/datasource/tool/${toolId}/${toolId}`,
    ),
    method: fetchMethod,
    headers: authHeaders,
    params: searchParameters,
    timeoutMs: connectionTimeoutMs,
    retryLimit: maxRetryCount,
    retriesDelayMs: delayBetweenRetriesInMs,
  }).then((response) => {

    const result = response.data;  
    node.loadData(result ? [...result] : []); 

    return Promise.resolve();
  });
};

These changes aim to make the code cleaner, more readable, and potentially safer by minimizing direct property lookups and ensuring type safety through explicit declarations.

Expand Down
Loading