mirror of
https://github.com/langgenius/dify.git
synced 2026-11-13 23:06:40 +08:00
Isolate node data and search subscriptions to avoid unnecessary renders of the workflow root and floating controls during position updates. Reuse unchanged node references and broadcast incremental CRDT updates, with catch-up after session reauthorization. Add regression coverage for node data synchronization, toolbar behavior, and collaborative graph updates.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import type { FC } from 'react'
|
|
import type { CommonNodeType } from '../types'
|
|
import { cn } from '@langgenius/dify-ui/cn'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useStore } from 'reactflow'
|
|
import { scrollToWorkflowNode } from '../utils/node-navigation'
|
|
|
|
const ScrollToSelectedNodeButton: FC = () => {
|
|
const { t } = useTranslation(['workflow'])
|
|
const selectedNodeId = useStore((state) => {
|
|
for (const node of state.nodeInternals.values()) {
|
|
if ((node.data as CommonNodeType).selected) return node.id
|
|
}
|
|
return undefined
|
|
})
|
|
|
|
if (!selectedNodeId) return null
|
|
|
|
return (
|
|
<button
|
|
type="button"
|
|
className={cn(
|
|
'flex h-6 cursor-pointer appearance-none items-center justify-center rounded-md border-[0.5px] border-effects-highlight bg-components-actionbar-bg px-3 system-xs-medium whitespace-nowrap text-text-tertiary shadow-lg backdrop-blur-xs transition-colors duration-200 hover:text-text-accent focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden',
|
|
)}
|
|
onClick={() => scrollToWorkflowNode(selectedNodeId)}
|
|
>
|
|
{t(($) => $['panel.scrollToSelectedNode'], { ns: 'workflow' })}
|
|
</button>
|
|
)
|
|
}
|
|
|
|
export default ScrollToSelectedNodeButton
|