import type { ChecklistItem } from '../hooks/use-checklist' import type { BlockEnum, CommonEdgeType, } from '../types' import { RiCloseLine, RiListCheck3, } from '@remixicon/react' import { memo, useState, } from 'react' import { useTranslation } from 'react-i18next' import { useEdges, } from 'reactflow' import { Warning } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback' import { IconR } from '@/app/components/base/icons/src/vender/line/arrows' import { ChecklistSquare, } from '@/app/components/base/icons/src/vender/line/general' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import useNodes from '@/app/components/workflow/store/workflow/use-nodes' import { cn } from '@/utils/classnames' import BlockIcon from '../block-icon' import { useChecklist, useNodesInteractions, } from '../hooks' type WorkflowChecklistProps = { disabled: boolean showGoTo?: boolean onItemClick?: (item: ChecklistItem) => void } const WorkflowChecklist = ({ disabled, showGoTo = true, onItemClick, }: WorkflowChecklistProps) => { const { t } = useTranslation() const [open, setOpen] = useState(false) const edges = useEdges() const nodes = useNodes() const needWarningNodes = useChecklist(nodes, edges) const { handleNodeSelect } = useNodesInteractions() const handleChecklistItemClick = (item: ChecklistItem) => { const goToEnabled = showGoTo && item.canNavigate && !item.disableGoTo if (!goToEnabled) return if (onItemClick) onItemClick(item) else handleNodeSelect(item.id) setOpen(false) } return ( !disabled && setOpen(v => !v)}>
{ !!needWarningNodes.length && (
{needWarningNodes.length}
) }
{t('workflow.panel.checklist')} {needWarningNodes.length ? `(${needWarningNodes.length})` : ''}
setOpen(false)} >
{ !!needWarningNodes.length && ( <>
{t('workflow.panel.checklistTip')}
{ needWarningNodes.map(node => (
handleChecklistItemClick(node)} >
{node.title} { (showGoTo && node.canNavigate && !node.disableGoTo) && (
{t('workflow.panel.goTo')}
) }
{ node.unConnected && (
{t('workflow.common.needConnectTip')}
) } { node.errorMessage && (
{node.errorMessage}
) }
)) }
) } { !needWarningNodes.length && (
{t('workflow.panel.checklistResolved')}
) }
) } export default memo(WorkflowChecklist)