Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

feat: Knowledge workflow save interface

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 2, 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 2, 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

publish,
putKnowledgeWorkflow,
workflowUpload,
}
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 appears to be well-formed and correctly implements REST API functions related to managing knowledge and its workflows. However, there are a few minor improvements and considerations:

  1. The putKnowledgeWorkflow function should specify the HTTP method as "PUT" instead of "POST". This is because it's updating an existing resource with new data.
  2. Consider adding type annotations for the parameters and return values in all functions defined within this file, especially those that use promises like Result. Using type definitions can help catch errors during development and make the code easier to read and maintain.

Overall, the function names follow conventional naming conventions and seem self-explanatory based on their purpose. There doesn't appear to be any significant issues or optimizations needed at this time.

putKnowledgeWorkflow,
listKnowledgeVersion
} as {
[key: string]: 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 code provided is a TypeScript module with three functions related to working with knowledge workflows in an enterprise system. There are no significant irregularities or problems with the code itself, but here are some suggestions for improvements:

  1. Type Declarations: The getWorkflowAction and publish functions accept optional parameters for loading, which is good practice to avoid errors when passing arguments incorrectly.

  2. Function Name Descriptions:

    • For simplicity, you could rename the putKnowledgeWorkflow function call from post to updateWorkflows. This change might make the intention clearer.
    • Similarly, renaming getResultDataFromResponse to something like retrieveUpdateResult would improve readability.
  3. Code Clarity:

    • In the listKnowledgeVersion documentation, describe what it does. It's not clear if this function fetches all versions of knowledge items or just active ones.
    • Consider adding comments to explain why certain values, such as undefined passed to the post method in putKnowledgeWorkflow, are being used.

Here’s an improved version of the code with these suggestions applied:

// ... other imports ...

// Save Knowledge Workflow
const putKnowledgeWorkflow: (
  knowledgeId: string,
  data: any,
  loading?: Ref<boolean>,
) => Promise<Result<any>> = async (knowledgeId, data, loading?) => {
  try {
    return await post(`${prefix}/${knowledgeId}/workflow`, data, { loading })
  } catch (error) {
    throw new Error('Error saving knowledge flow.')
  }
}

export default {
  // ... other functions ...

  /**
   * Update Workflows
   * @param knowledgeId The unique identifier for the knowledge item.
   * @param data The updated workflow information.
   * @param loading A ref object indicating whether the component is currently in loading state.
   * @returns A Promise that resolves to the response data resulting from the update request.
   */
  updateWorkflows: putKnowledgeWorkflow,

  // ... other functions ...
} as {
  [key: string]: ((...args: any) => Promise<any>) | Record<string, any>
} satisfies Module<ReturnType<typeof import('@/modules/base').default>>;

Key Changes:

  • Renamed putKnowledgeWorkflow to updateWorkflows.
  • Simplified the function name descriptions where possible.
  • Added comments to clarify the usage of data and { loading } in putKnowledgeWorkflow.

These changes should help enhance clarity and maintainability of the codebase.

putKnowledgeWorkflow,
listKnowledgeVersion,
} as {
[key: string]: 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 code provided looks mostly correct, but there are a few areas for improvement:

  1. Type Annotations: There are no type annotations on the input parameters and return types of putKnowledgeWorkflow. TypeScript would benefit by adding them to improve code clarity and static typing.

  2. Loading Hook: The loading parameter is defined twice in the signature (loadin? and loading) which should be consistent either with hooks or without.

Here's an improved version of the function with added type annotations and ensuring consistency in the loading paramter definition:

/**
 * 保存知识库工作流
 * @param knowledge_id 
 * @param data 
 * @param loading - Loading state reference
 * @returns 
 */
const putKnowledgeWorkflow: (
  knowledge_id: string,
  data: any,
  loading: Ref<boolean>,
) => Promise<Result<any>> = (knowledge_id, data, loading) => {
  return put(`${prefix}/${knowledge_id}/workflow`, data, undefined, loading);
};

export default {
  getKnowledgeWorkflowDatasourceDetails,
  workflowAction,
  publish,

  // Improved signature for putKnowledgeWorkflow
  putKnowledgeWorkflow,
  listKnowledgeVersion,
} as {
  [key: string]: (...args: any[]) => void | Promise<void>;
};

Key Changes:

  • Added type annotation Ref<boolean> for the loading parameter.
  • Removed the redundant loading? declaration.
  • Ensured consistency by aligning the parameter definitions.

@zhanweizhang7 zhanweizhang7 merged commit 953fc5f into v2 Dec 2, 2025
4 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@feat_knowledge_workflow_save branch December 2, 2025 08:43
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.

3 participants