feat(workflow): position node in panel

pull/19998/head
wellCh4n 1 year ago
parent 08ec2118e5
commit a0b87b266a

@ -1,23 +1,25 @@
import { memo } from 'react' import { memo } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { RiCrosshairLine } from '@remixicon/react' import { RiCrosshairLine } from '@remixicon/react'
import type { XYPosition } from 'reactflow'
import { useReactFlow, useStoreApi } from 'reactflow' import { useReactFlow, useStoreApi } from 'reactflow'
import TooltipPlus from '@/app/components/base/tooltip' import TooltipPlus from '@/app/components/base/tooltip'
type NodePositionProps = { type NodePositionProps = {
nodeId: string position: XYPosition,
width?: number | null,
height?: number | null,
} }
const NodePosition = ({ const NodePosition = ({
nodeId, position,
width,
height,
}: NodePositionProps) => { }: NodePositionProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const reactflow = useReactFlow() const reactflow = useReactFlow()
const store = useStoreApi() const store = useStoreApi()
if (!nodeId) return null if (!position || !width || !height) return null
const node = reactflow.getNode(nodeId)
if (node == null) return null
const workflowContainer = document.getElementById('workflow-container') const workflowContainer = document.getElementById('workflow-container')
const { transform } = store.getState() const { transform } = store.getState()
@ -25,18 +27,17 @@ const NodePosition = ({
const { clientWidth, clientHeight } = workflowContainer! const { clientWidth, clientHeight } = workflowContainer!
const { setViewport } = reactflow const { setViewport } = reactflow
const position = node.position
return ( return (
<TooltipPlus <TooltipPlus
popupContent={t('workflow.panel.moveToThisNode')} popupContent={t('workflow.panel.moveToThisNode')}
> >
<div <div
className='mr-1 flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-state-base-hover' className='mr-1 flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-state-base-hover'
onClick={() => { onClick={() => {
setViewport({ setViewport({
x: (clientWidth - 400 - node.width! * zoom) / 2 - position.x * zoom, x: (clientWidth - 400 - width * zoom) / 2 - position.x * zoom,
y: (clientHeight - node.height! * zoom) / 2 - position.y * zoom, y: (clientHeight - height * zoom) / 2 - position.y * zoom,
zoom: transform[2], zoom: transform[2],
}) })
}} }}

@ -56,6 +56,9 @@ const BasePanel: FC<BasePanelProps> = ({
id, id,
data, data,
children, children,
position,
width,
height,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { showMessageLogModal } = useAppStore(useShallow(state => ({ const { showMessageLogModal } = useAppStore(useShallow(state => ({
@ -151,7 +154,7 @@ const BasePanel: FC<BasePanelProps> = ({
</Tooltip> </Tooltip>
) )
} }
<NodePosition nodeId={id}></NodePosition> <NodePosition position={position} width={width} height={height}></NodePosition>
<HelpLink nodeType={data.type} /> <HelpLink nodeType={data.type} />
<PanelOperator id={id} data={data} showHelpLink={false} /> <PanelOperator id={id} data={data} showHelpLink={false} />
<div className='mx-3 h-3.5 w-[1px] bg-divider-regular' /> <div className='mx-3 h-3.5 w-[1px] bg-divider-regular' />

Loading…
Cancel
Save