feat(workflow): position node in panel

pull/19998/head
wellCh4n 1 year ago
parent a0b87b266a
commit b8e66dc699

@ -4,22 +4,24 @@ import { RiCrosshairLine } from '@remixicon/react'
import type { XYPosition } from 'reactflow' 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'
import { useNodesSyncDraft } from '@/app/components/workflow-app/hooks'
type NodePositionProps = { type NodePositionProps = {
position: XYPosition, nodePosition: XYPosition,
width?: number | null, nodeWidth?: number | null,
height?: number | null, nodeHeight?: number | null,
} }
const NodePosition = ({ const NodePosition = ({
position, nodePosition,
width, nodeWidth,
height, nodeHeight,
}: NodePositionProps) => { }: NodePositionProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const reactflow = useReactFlow() const reactflow = useReactFlow()
const store = useStoreApi() const store = useStoreApi()
const { doSyncWorkflowDraft } = useNodesSyncDraft()
if (!position || !width || !height) return null if (!nodePosition || !nodeWidth || !nodeHeight) return null
const workflowContainer = document.getElementById('workflow-container') const workflowContainer = document.getElementById('workflow-container')
const { transform } = store.getState() const { transform } = store.getState()
@ -36,10 +38,11 @@ const NodePosition = ({
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 - width * zoom) / 2 - position.x * zoom, x: (clientWidth - 400 - nodeWidth * zoom) / 2 - nodePosition.x * zoom,
y: (clientHeight - height * zoom) / 2 - position.y * zoom, y: (clientHeight - nodeHeight * zoom) / 2 - nodePosition.y * zoom,
zoom: transform[2], zoom: transform[2],
}) })
doSyncWorkflowDraft()
}} }}
> >
<RiCrosshairLine className='h-4 w-4 text-text-tertiary' /> <RiCrosshairLine className='h-4 w-4 text-text-tertiary' />

@ -154,7 +154,7 @@ const BasePanel: FC<BasePanelProps> = ({
</Tooltip> </Tooltip>
) )
} }
<NodePosition position={position} width={width} height={height}></NodePosition> <NodePosition nodePosition={position} nodeWidth={width} nodeHeight={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