Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: The data source Tree uses fetc_list_function

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 5, 2025

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.

Details

Instructions 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.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 5, 2025

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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.

@shaohuzhang1 shaohuzhang1 merged commit 5bd29f6 into v2 Dec 5, 2025
3 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_workflow branch December 5, 2025 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants