From 5525f630323445983866806265d65db83d064966 Mon Sep 17 00:00:00 2001 From: zhsama Date: Thu, 15 Jan 2026 16:12:39 +0800 Subject: [PATCH] refactor: sub-graph panel use shared Panel component --- .../components/sub-graph-children.tsx | 88 ++++++------------- .../components/workflow/operator/index.tsx | 10 +-- web/app/components/workflow/panel/index.tsx | 3 + 3 files changed, 32 insertions(+), 69 deletions(-) diff --git a/web/app/components/sub-graph/components/sub-graph-children.tsx b/web/app/components/sub-graph/components/sub-graph-children.tsx index 749a571efb..7da4f15664 100644 --- a/web/app/components/sub-graph/components/sub-graph-children.tsx +++ b/web/app/components/sub-graph/components/sub-graph-children.tsx @@ -1,11 +1,11 @@ import type { FC } from 'react' import type { MentionConfig } from '@/app/components/workflow/nodes/_base/types' import type { NodeOutPutVar } from '@/app/components/workflow/types' -import { memo, useEffect, useMemo, useRef } from 'react' +import { memo, useMemo } from 'react' import { useStore as useReactFlowStore } from 'reactflow' import { useShallow } from 'zustand/react/shallow' import { useIsChatMode, useWorkflowVariables } from '@/app/components/workflow/hooks' -import { Panel as NodePanel } from '@/app/components/workflow/nodes' +import Panel from '@/app/components/workflow/panel' import { useStore } from '@/app/components/workflow/store' import { BlockEnum } from '@/app/components/workflow/types' import ConfigPanel from './config-panel' @@ -26,37 +26,6 @@ const SubGraphChildren: FC = ({ const { getNodeAvailableVars } = useWorkflowVariables() const isChatMode = useIsChatMode() const nodePanelWidth = useStore(s => s.nodePanelWidth) - const setRightPanelWidth = useStore(s => s.setRightPanelWidth) - const panelRef = useRef(null) - - useEffect(() => { - const element = panelRef.current - if (!element) - return - - const updateWidth = (width: number) => { - if (width > 0) - setRightPanelWidth(width) - } - - const resizeObserver = new ResizeObserver((entries) => { - for (const entry of entries) { - if (entry.borderBoxSize?.length) - updateWidth(entry.borderBoxSize[0].inlineSize) - else if (entry.contentRect.width > 0) - updateWidth(entry.contentRect.width) - else - updateWidth(element.getBoundingClientRect().width) - } - }) - - resizeObserver.observe(element) - updateWidth(element.getBoundingClientRect().width) - - return () => { - resizeObserver.disconnect() - } - }, [setRightPanelWidth]) const selectedNode = useReactFlowStore(useShallow((s) => { return s.getNodes().find(node => node.data.selected) @@ -82,41 +51,36 @@ const SubGraphChildren: FC = ({ return vars.filter(item => item.nodeId === extractorNode.id) }, [extractorNode, getNodeAvailableVars, isChatMode]) - const nodePanel = useMemo(() => { - if (!selectedNode) + const panelRight = useMemo(() => { + if (selectedNode) return null return ( - +
+
+ +
+
) - }, [selectedNode]) + }, [agentName, availableNodes, availableVars, extractorNodeId, mentionConfig, nodePanelWidth, onMentionConfigChange, selectedNode]) return ( -
-
- {nodePanel || ( -
-
- -
-
- )} -
-
+ ) } diff --git a/web/app/components/workflow/operator/index.tsx b/web/app/components/workflow/operator/index.tsx index a52d7fc409..519eb1fdb7 100644 --- a/web/app/components/workflow/operator/index.tsx +++ b/web/app/components/workflow/operator/index.tsx @@ -2,7 +2,6 @@ import type { Node } from 'reactflow' import { memo, useCallback, useEffect, useMemo, useRef } from 'react' import { MiniMap } from 'reactflow' import UndoRedo from '../header/undo-redo' -import { useHooksStore } from '../hooks-store' import { useStore } from '../store' import VariableInspectPanel from '../variable-inspect' import VariableTrigger from '../variable-inspect/trigger' @@ -15,19 +14,16 @@ export type OperatorProps = { const Operator = ({ handleUndo, handleRedo }: OperatorProps) => { const bottomPanelRef = useRef(null) - const interactionMode = useHooksStore(s => s.interactionMode) const workflowCanvasWidth = useStore(s => s.workflowCanvasWidth) const rightPanelWidth = useStore(s => s.rightPanelWidth) - const nodePanelWidth = useStore(s => s.nodePanelWidth) const setBottomPanelWidth = useStore(s => s.setBottomPanelWidth) const setBottomPanelHeight = useStore(s => s.setBottomPanelHeight) const bottomPanelWidth = useMemo(() => { - const panelWidth = rightPanelWidth || nodePanelWidth - if (!workflowCanvasWidth || !panelWidth) + if (!workflowCanvasWidth || !rightPanelWidth) return 'auto' - return Math.max((workflowCanvasWidth - panelWidth), 400) - }, [interactionMode, nodePanelWidth, rightPanelWidth, workflowCanvasWidth]) + return Math.max((workflowCanvasWidth - rightPanelWidth), 400) + }, [workflowCanvasWidth, rightPanelWidth]) const getMiniMapNodeClassName = useCallback((node: Node) => { return node.data?.selected diff --git a/web/app/components/workflow/panel/index.tsx b/web/app/components/workflow/panel/index.tsx index 88ada8b11e..6fbafb1817 100644 --- a/web/app/components/workflow/panel/index.tsx +++ b/web/app/components/workflow/panel/index.tsx @@ -19,6 +19,7 @@ export type PanelProps = { right?: React.ReactNode } versionHistoryPanelProps?: VersionHistoryPanelProps + topOffset?: number } /** @@ -69,6 +70,7 @@ const useResizeObserver = ( const Panel: FC = ({ components, versionHistoryPanelProps, + topOffset, }) => { const selectedNode = useReactflow(useShallow((s) => { const nodes = s.getNodes() @@ -128,6 +130,7 @@ const Panel: FC = ({ ref={rightPanelRef} tabIndex={-1} className={cn('absolute bottom-1 right-0 top-14 z-10 flex outline-none')} + style={topOffset === undefined ? undefined : { top: `${topOffset}px` }} key={`${isRestoring}`} > {components?.left}