| } from 'react' | } from 'react' | ||||
| import { useTranslation } from 'react-i18next' | import { useTranslation } from 'react-i18next' | ||||
| import { | import { | ||||
| useNodesExtraData, | |||||
| useAvailableBlocks, | |||||
| useNodesInteractions, | useNodesInteractions, | ||||
| useNodesReadOnly, | useNodesReadOnly, | ||||
| } from '@/app/components/workflow/hooks' | } from '@/app/components/workflow/hooks' | ||||
| import BlockSelector from '@/app/components/workflow/block-selector' | import BlockSelector from '@/app/components/workflow/block-selector' | ||||
| import { Plus } from '@/app/components/base/icons/src/vender/line/general' | import { Plus } from '@/app/components/base/icons/src/vender/line/general' | ||||
| import type { | import type { | ||||
| BlockEnum, | |||||
| CommonNodeType, | |||||
| OnSelectBlock, | OnSelectBlock, | ||||
| } from '@/app/components/workflow/types' | } from '@/app/components/workflow/types' | ||||
| type AddProps = { | type AddProps = { | ||||
| nodeId: string | nodeId: string | ||||
| nodeType: BlockEnum | |||||
| nodeData: CommonNodeType | |||||
| sourceHandle: string | sourceHandle: string | ||||
| branchName?: string | branchName?: string | ||||
| } | } | ||||
| const Add = ({ | const Add = ({ | ||||
| nodeId, | nodeId, | ||||
| nodeType, | |||||
| nodeData, | |||||
| sourceHandle, | sourceHandle, | ||||
| branchName, | branchName, | ||||
| }: AddProps) => { | }: AddProps) => { | ||||
| const { t } = useTranslation() | const { t } = useTranslation() | ||||
| const { handleNodeAdd } = useNodesInteractions() | const { handleNodeAdd } = useNodesInteractions() | ||||
| const nodesExtraData = useNodesExtraData() | |||||
| const { nodesReadOnly } = useNodesReadOnly() | const { nodesReadOnly } = useNodesReadOnly() | ||||
| const availableNextNodes = nodesExtraData[nodeType].availableNextNodes | |||||
| const { availableNextBlocks } = useAvailableBlocks(nodeData.type, nodeData.isInIteration) | |||||
| const handleSelect = useCallback<OnSelectBlock>((type, toolDefaultValue) => { | const handleSelect = useCallback<OnSelectBlock>((type, toolDefaultValue) => { | ||||
| handleNodeAdd( | handleNodeAdd( | ||||
| offset={0} | offset={0} | ||||
| trigger={renderTrigger} | trigger={renderTrigger} | ||||
| popupClassName='!w-[328px]' | popupClassName='!w-[328px]' | ||||
| availableBlocksTypes={availableNextNodes} | |||||
| availableBlocksTypes={availableNextBlocks} | |||||
| /> | /> | ||||
| ) | ) | ||||
| } | } | 
| !nodeWithBranches && !outgoers.length && ( | !nodeWithBranches && !outgoers.length && ( | ||||
| <Add | <Add | ||||
| nodeId={selectedNode!.id} | nodeId={selectedNode!.id} | ||||
| nodeType={selectedNode!.data.type} | |||||
| nodeData={selectedNode!.data} | |||||
| sourceHandle='source' | sourceHandle='source' | ||||
| /> | /> | ||||
| ) | ) | ||||
| <Add | <Add | ||||
| key={branch.id} | key={branch.id} | ||||
| nodeId={selectedNode!.id} | nodeId={selectedNode!.id} | ||||
| nodeType={selectedNode!.data.type} | |||||
| nodeData={selectedNode!.data} | |||||
| sourceHandle={branch.id} | sourceHandle={branch.id} | ||||
| branchName={branch.name} | branchName={branch.name} | ||||
| /> | /> | 
| } from '@/app/components/base/icons/src/vender/line/general' | } from '@/app/components/base/icons/src/vender/line/general' | ||||
| import BlockIcon from '@/app/components/workflow/block-icon' | import BlockIcon from '@/app/components/workflow/block-icon' | ||||
| import { | import { | ||||
| useAvailableBlocks, | |||||
| useNodeDataUpdate, | useNodeDataUpdate, | ||||
| useNodesExtraData, | |||||
| useNodesInteractions, | useNodesInteractions, | ||||
| useNodesReadOnly, | useNodesReadOnly, | ||||
| useNodesSyncDraft, | useNodesSyncDraft, | ||||
| const { handleNodeSelect } = useNodesInteractions() | const { handleNodeSelect } = useNodesInteractions() | ||||
| const { handleSyncWorkflowDraft } = useNodesSyncDraft() | const { handleSyncWorkflowDraft } = useNodesSyncDraft() | ||||
| const { nodesReadOnly } = useNodesReadOnly() | const { nodesReadOnly } = useNodesReadOnly() | ||||
| const nodesExtraData = useNodesExtraData() | |||||
| const availableNextNodes = nodesExtraData[data.type].availableNextNodes | |||||
| const { availableNextBlocks } = useAvailableBlocks(data.type, data.isInIteration) | |||||
| const toolIcon = useToolIcon(data) | const toolIcon = useToolIcon(data) | ||||
| const handleResize = useCallback((width: number) => { | const handleResize = useCallback((width: number) => { | ||||
| {cloneElement(children, { id, data })} | {cloneElement(children, { id, data })} | ||||
| </div> | </div> | ||||
| { | { | ||||
| !!availableNextNodes.length && ( | |||||
| !!availableNextBlocks.length && ( | |||||
| <div className='p-4 border-t-[0.5px] border-t-black/5'> | <div className='p-4 border-t-[0.5px] border-t-black/5'> | ||||
| <div className='flex items-center mb-1 text-gray-700 text-[13px] font-semibold'> | <div className='flex items-center mb-1 text-gray-700 text-[13px] font-semibold'> | ||||
| {t('workflow.panel.nextStep').toLocaleUpperCase()} | {t('workflow.panel.nextStep').toLocaleUpperCase()} | 
| generateNewNode, | generateNewNode, | ||||
| } from '../utils' | } from '../utils' | ||||
| import { | import { | ||||
| useNodesExtraData, | |||||
| useAvailableBlocks, | |||||
| useNodesReadOnly, | useNodesReadOnly, | ||||
| usePanelInteractions, | usePanelInteractions, | ||||
| } from '../hooks' | } from '../hooks' | ||||
| const { t } = useTranslation() | const { t } = useTranslation() | ||||
| const store = useStoreApi() | const store = useStoreApi() | ||||
| const workflowStore = useWorkflowStore() | const workflowStore = useWorkflowStore() | ||||
| const nodesExtraData = useNodesExtraData() | |||||
| const { nodesReadOnly } = useNodesReadOnly() | const { nodesReadOnly } = useNodesReadOnly() | ||||
| const { handlePaneContextmenuCancel } = usePanelInteractions() | const { handlePaneContextmenuCancel } = usePanelInteractions() | ||||
| const [open, setOpen] = useState(false) | const [open, setOpen] = useState(false) | ||||
| const availableNextNodes = nodesExtraData[BlockEnum.Start].availableNextNodes | |||||
| const { availableNextBlocks } = useAvailableBlocks(BlockEnum.Start, false) | |||||
| const handleOpenChange = useCallback((open: boolean) => { | const handleOpenChange = useCallback((open: boolean) => { | ||||
| setOpen(open) | setOpen(open) | ||||
| }} | }} | ||||
| trigger={renderTrigger || renderTriggerElement} | trigger={renderTrigger || renderTriggerElement} | ||||
| popupClassName='!min-w-[256px]' | popupClassName='!min-w-[256px]' | ||||
| availableBlocksTypes={availableNextNodes} | |||||
| availableBlocksTypes={availableNextBlocks} | |||||
| /> | /> | ||||
| ) | ) | ||||
| } | } |