-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: Workflow node search #4844
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 |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| <!-- 辅助工具栏 --> | ||
| <Control class="workflow-control" v-if="lf" :lf="lf"></Control> | ||
| <TeleportContainer :flow-id="flowId" /> | ||
| <NodeSearch class="workflow-search" :on-search="onSearch"></NodeSearch> | ||
| <NodeSearch class="workflow-search" :lf="lf"></NodeSearch> | ||
| </template> | ||
| <script setup lang="ts"> | ||
| import LogicFlow from '@logicflow/core' | ||
|
|
@@ -18,7 +18,7 @@ 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' | ||
|
|
||
| import NodeSearch from '@/workflow/common/NodeSearch.vue' | ||
| const nodes: any = import.meta.glob('./nodes/**/index.ts', { eager: true }) | ||
| const workflow_mode = inject('workflowMode') || WorkflowMode.Application | ||
|
|
@@ -52,43 +52,6 @@ onUnmounted(() => { | |
| const render = (data: any) => { | ||
| lf.value.render(data) | ||
| } | ||
| const searchQueue: Array<string> = [] | ||
| const selectNode = (node: any) => { | ||
| lf.value.graphModel.selectNodeById(node.id) | ||
| lf.value.graphModel.transformModel.focusOn( | ||
| node.x, | ||
| node.y, | ||
| lf.value.container.clientWidth, | ||
| lf.value.container.clientHeight, | ||
| ) | ||
| searchQueue.push(node.id) | ||
| } | ||
| const onSearch = (kw: string) => { | ||
| const graph_data = lf.value.getGraphData() | ||
| for (let index = 0; index < graph_data.nodes.length; index++) { | ||
| const node = graph_data.nodes[index] | ||
| let firstNode = null | ||
| if (node.properties.stepName.includes(kw)) { | ||
| if (!firstNode) { | ||
| firstNode = node | ||
| } | ||
|
|
||
| if (!searchQueue.includes(node.id)) { | ||
| selectNode(node) | ||
| break | ||
| } | ||
| } | ||
| if (index === graph_data.nodes.length - 1) { | ||
| searchQueue.length = 0 | ||
| if (firstNode) { | ||
| selectNode(firstNode) | ||
| } else { | ||
| lf.value.graphModel.clearSelectElements() | ||
| MsgWarning('不存在的节点') | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const renderGraphData = (data?: any) => { | ||
| const container: any = document.querySelector('#container') | ||
|
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. Code Review1. Logical Flow Initialization<Control class="workflow-control" v-if="lf" :lf="lf"></Control>There's no initialization of Suggestion: <script setup lang="ts">
import LogicFlow from '@logicflow/core'
const lf = ref(null)
// Rest of the code...
</script>2. Node Search FunctionalityThe existing
Suggestions:
3. Node Importing (glob pattern)const nodes: any = import.meta.glob('./nodes/**/index.ts', { eager: true })This pattern imports all Suggestion: <script setup lang="ts">
import type { NodeComponent } from './types' // Assuming types exist in ./types
import * as nodeComponents from '@/components/nodes' //
const getNodes = async () => {
const loadedNodeComponents: Record<string, NodeComponent> = {}
await Promise.all(
Object.entries(nodeComponents).map(async ([key, module]) => {
try {
const component = await module.default?.default ?? module.default
if (component) {
loadedNodeComponents[key] = component
}
} catch (err) {
console.error(`Failed to load node ${key}`, err)
}
}),
)
return loadedNodeComponents
}
getNodes().then(nodes => {})
</script>4. Template ErrorsReplace deprecated tags: <TeleportContainer :flow-id="flowId" />
<NodeSearch class="workflow-search" :on-search="onSearch"></NodeSearch>with their updated versions: <TeleportContainer :flow-id="flowId" />
<NodeSearch class="workflow-search" :lf="lf" @select-node="handleSelectNode"></NodeSearch>Make sure to define Final Suggested Changes 1. Initialize Logic Flow Instance<template>
<!-- ... -->
<Control class="workflow-control" v-if="lf" :lf="lf"></Control>
<!-- ... -->
</template>
<script setup lang="ts">
import LogicFlow from '@logicflow/core';
import Control from '@/components/Common/Control.vue';
const lf = ref();
...</script>2. Update Node Search Method<template>
<!-- ... -->
<NodeSearch class="workflow-search" :lf="lf" @select-node="handleSelectNode"></NodeSearch>
<!-- ... -->
</template>
<script setup lang="ts">
import logicFlowInstance from '@/path/to/logic-flow-instance'; // Replace with actual path
const handleSelectNode = (selectedNodesIds: string[], selectedNodeData: object[]) => {
// Handle selected node actions here
};
const renderGraphDta = (data?:any) => {
// ...
}
</script>These changes should help make the code more robust, efficient, and maintainable. Always test after making these changes thoroughly to ensure everything functions correctly. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,12 +166,53 @@ const loopLayout = () => { | |
| LoopBodyContainerRef.value?.zoom() | ||
| lf.value?.extension?.dagre.layout() | ||
| } | ||
| const selectOn = (node: any, kw: string) => { | ||
| lf.value?.graphModel.getNodeModelById(node.id).selectOn(kw) | ||
| } | ||
| const focusOn = (node: any, kw: string) => { | ||
| lf.value?.graphModel.transformModel.focusOn( | ||
| node.x, | ||
| node.y, | ||
| lf.value?.container.clientWidth, | ||
| lf.value?.container.clientHeight, | ||
| ) | ||
| lf.value?.graphModel.getNodeModelById(node.id).focusOn(kw) | ||
| } | ||
|
|
||
| const getSelectNodes = (kw: string) => { | ||
| const graph_data = lf.value?.getGraphData() | ||
| return graph_data.nodes.filter((node: any) => node.properties.stepName.includes(kw)) | ||
| } | ||
| const onSearchSelect = (node: any, kw: string) => { | ||
| lf.value?.graphModel.getNodeModelById(node.id).selectOn(kw) | ||
| } | ||
| const onClearSearchSelect = (node: any, kw: string) => { | ||
| lf.value?.graphModel.getNodeModelById(node.id).clearSelectOn(kw) | ||
| } | ||
| const clearSelectElements = () => { | ||
| lf.value.graphModel.clearSelectElements() | ||
| } | ||
| onMounted(() => { | ||
| renderGraphData(cloneDeep(props.nodeModel.properties.workflow)) | ||
| set(props.nodeModel, 'validate', validate) | ||
| set(props.nodeModel, 'set_loop_body', set_loop_body) | ||
| set(props.nodeModel, 'loopLayout', loopLayout) | ||
| set(props.nodeModel, 'getSelectNodes', getSelectNodes) | ||
| set(props.nodeModel, 'focusOn', (event: any) => { | ||
| focusOn(event.node, event.kw) | ||
| }) | ||
| set(props.nodeModel, 'selectOn', (event: any) => { | ||
| selectOn(event.node, event.kw) | ||
| }) | ||
| set(props.nodeModel, 'clearSelectOn', (event: any) => { | ||
| onSearchSelect(event.node, event.kw) | ||
| }) | ||
| set(props.nodeModel, 'clearSelectElements', clearSelectElements) | ||
| set(props.nodeModel, 'onClearSearchSelect', (event: any) => { | ||
| onClearSearchSelect(event.node, event.kw) | ||
| }) | ||
| }) | ||
|
|
||
| onUnmounted(() => { | ||
| disconnectByFlow(lf.value.graphModel.flowId) | ||
| lf.value = null | ||
|
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. Your code appears to be quite complex and includes several functions that seem to manipulate graph data using an unknown library ( Potential Issues and Improvements
Suggestions for Refinement
These suggestions aim to make the code more readable, maintainable, and potentially more efficient by simplifying logic and improving readability while maintaining consistency throughout the codebase. |
||
|
|
||
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.
Here are some corrections and improvements to your Vue.js code:
() => {...}) throughout the template and script setup.selectedCountshould be defined usingcomputed.Revised Code
Changes Made:
showSelectedIndicatoras a computed property for cleaner logic.This revised version should address several issues found in the original code, making it more maintainable and robust. Make sure to update the rest of your components accordingly.