import type { FC, ReactElement, } from 'react' import { cloneElement, memo, useCallback, useMemo, } from 'react' import { useTranslation } from 'react-i18next' import NextStep from './components/next-step' import PanelOperator from './components/panel-operator' import { DescriptionInput, TitleInput, } from './components/title-description-input' import { XClose, } from '@/app/components/base/icons/src/vender/line/general' import BlockIcon from '@/app/components/workflow/block-icon' import { useNodeDataUpdate, useNodesExtraData, useNodesInteractions, useNodesSyncDraft, } from '@/app/components/workflow/hooks' import { useStore } from '@/app/components/workflow/store' import { canRunBySingle } from '@/app/components/workflow/utils' import { GitBranch01 } from '@/app/components/base/icons/src/vender/line/development' import { Play } from '@/app/components/base/icons/src/vender/line/mediaAndDevices' import TooltipPlus from '@/app/components/base/tooltip-plus' import type { Node } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types' type BasePanelProps = { children: ReactElement } & Node const BasePanel: FC = ({ id, data, children, }) => { const { t } = useTranslation() const { handleNodeSelect } = useNodesInteractions() const { handleSyncWorkflowDraft } = useNodesSyncDraft() const nodesExtraData = useNodesExtraData() const availableNextNodes = nodesExtraData[data.type].availableNextNodes const toolsets = useStore(s => s.toolsets) const toolIcon = useMemo(() => { if (data.type === BlockEnum.Tool) return toolsets.find(toolset => toolset.id === data.provider_id)?.icon }, [data, toolsets]) const { handleNodeDataUpdate, handleNodeDataUpdateWithSyncDraft, } = useNodeDataUpdate() const handleTitleBlur = useCallback((title: string) => { handleNodeDataUpdateWithSyncDraft({ id, data: { title } }) }, [handleNodeDataUpdateWithSyncDraft, id]) const handleDescriptionChange = useCallback((desc: string) => { handleNodeDataUpdateWithSyncDraft({ id, data: { desc } }) }, [handleNodeDataUpdateWithSyncDraft, id]) return (
{ canRunBySingle(data.type) && (
{ handleNodeDataUpdate({ id, data: { _isSingleRun: true } }) handleSyncWorkflowDraft(true) }} >
) }
handleNodeSelect(id, true)} >
{cloneElement(children, { id, data })}
{ !!availableNextNodes.length && (
{t('workflow.panel.nextStep').toLocaleUpperCase()}
{t('workflow.panel.addNextStep')}
) }
) } export default memo(BasePanel)