Skip to content

feat: [Intelligent Agent] Workflow intelligent agent adds workflow component search/location function#4822

Merged
shaohuzhang1 merged 1 commit intov2from
pr@v2@feat_workflow_search
Feb 26, 2026
Merged

feat: [Intelligent Agent] Workflow intelligent agent adds workflow component search/location function#4822
shaohuzhang1 merged 1 commit intov2from
pr@v2@feat_workflow_search

Conversation

@shaohuzhang1
Copy link
Contributor

feat: [Intelligent Agent] Workflow intelligent agent adds workflow component search/location function

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Feb 26, 2026

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 Feb 26, 2026

[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

transform: translateY(0);
}
}
</style>
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 generally clean and well-structured. Here are some minor suggestions for optimization and considerations:

  1. TypeScript Typing: The props interface is defined using TypeScript type annotations for clarity.

  2. Arrow Functions: Arrow functions (()=>{}) can make the code slightly cleaner and more concise, especially when used in callback functions like .addEventListener() and .nextTick(). However, standard function declarations (function(){}) without an arrow might be suitable depending on personal preference or context.

  3. Comments: Comments can sometimes clutter the code and become outdated. Consider updating comments, removing unnecessary ones, or grouping similar comments together.

  4. Avoid Global Event Listeners: Although necessary for this specific functionality, consider encapsulating event handlers within component state management if possible to avoid adding global listeners that could potentially interfere with other components or lead to memory leaks under certain conditions.

  5. Optimize State Management: Ensure that the state variables are properly managed and updated only when necessary. For example, you might want to debounce updates to improve performance.

Overall, the code is straightforward and should work correctly as intended. If performance becomes a concern or additional features are needed, further optimizations can be made based on those requirements.


const renderGraphData = (data?: any) => {
const container: any = document.querySelector('#container')
if (container) {
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 provided code looks mostly correct but there are a few areas where improvements can be made:

  1. Type Annotations: Ensure that all variables have appropriate type annotations to improve readability and maintainability.

  2. Comments and Documentation: Add comments explaining complex logic and consider adding documentation for functions that might not be immediately obvious.

  3. Vue Composition API: Use TypeScript with Vue's composition API correctly to ensure proper typing and function dependencies.

  4. Error Handling: Implement error handling for edge cases, such as when no matching nodes are found during a search.

Here’s an improved version of your code with some suggestions:

<!-- 辅助工具栏 -->
<Control class="workflow-control" v-if="lf" :lf="lf"></Control>
<TeleportContainer :flow-id="flowId" />
<NodeSearch :on-search="onSearch"></NodeSearch>
</template>

<script setup lang="ts">
import LogicFlow from '@logicflow/core'
import { initDefaultShortcut } from '@/workflow/common/shortcut'
import Dagre from '@/workflow/plugins/dagre'
import { disconnectAll, getTeleport } from '@/workflow/common/teleport'
import { WorkflowMode } from '@/enums/application'
import { MsgSuccess, MsgWarning } from '@/utils/message'

// Type definitions
interface Node {
  id: string;
  properties: Record<string, any>;
}

type GraphData = {
  nodes: Node[];
};

// Setup data...
const lf = ref(null);
const flowId = 'your-flow-id';
const workflow_mode = inject('workflowMode') || WorkflowMode.Application;
const loop_workflow_mode = inject('loopWorkflowMode') || WorkflowMode.Application;

// Search-related variables
const searchQueue: Set<string> = new Set();

const selectNode = (node: Node) => {
  lf.value.graphModel.selectNodeById(node.id);
  lf.value.graphModel.transformModel.focusOn(
    node.x,
    node.y,
    lf.value.container?.clientWidth ?? 0,
    lf.value.container?.clientHeight ?? 0,
  );
  searchQueue.add(node.id);
};

const onSearch = async (kw: string) => {
  try {
    const graph_data = await lf.value.getGraphData(); // Assuming this returns Promise<object>
    for (const node of graph_data.nodes) {
      if (
        node.properties &&
        node.properties.stepName.toLowerCase().includes(kw.toLowerCase())
      ) {
        await selectNode(node); // Await here since we change state inside selectNode
        return; // Only show the first match
      }
    }
    searchQueue.clear();
    lf.value.graphModel.clearSelectElements();
    MsgWarning('不存在的节点');
  } catch (error) {
    console.error("Failed to fetch graph data:", error);
    MsgWarning('获取图形数据失败,请重试。');
  }
};

const renderGraphData = (data?: GraphData) => {
  const container: HTMLElement | null = document.getElementById('container');
  if (container) {
    // Your rendering logic here
  }
};
</script>

<style scoped>
/* Your styles here */
</style>

Key Changes:

  • Type Annotations: Added Nodes and GraphData interfaces for better type safety.
  • Set for searchQueue: Used Set to automatically remove duplicates and simplify iteration.
  • Async/Await: Used async/await in selectNode after clearing searchQueue.
  • Error Handling: Caught promise rejections thrown by getGraphData() method call.

@shaohuzhang1 shaohuzhang1 merged commit ca0034a into v2 Feb 26, 2026
3 of 4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@feat_workflow_search branch February 26, 2026 08:25
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.

1 participant