import React, { useEffect } from 'react'; import { Tag, Breadcrumb } from 'antd'; import { cx } from '@emotion/css'; import { Link } from 'react-router-dom'; import { useCompile, useDocumentTitle, useResourceActionContext } from '@nocobase/client'; import { str2moment } from '@nocobase/utils/client'; import { FlowContext } from './FlowContext'; import { branchBlockClass, nodeCardClass, nodeMetaClass } from './style'; import { TriggerConfig } from './triggers'; import { Branch } from './Branch'; import { ExecutionStatusOptionsMap } from './constants'; import { lang } from './locale'; import { linkNodes } from './utils'; function attachJobs(nodes, jobs: any[] = []): void { const nodesMap = new Map(); nodes.forEach((item) => nodesMap.set(item.id, item)); const jobsMap = new Map(); jobs.forEach((item) => jobsMap.set(item.nodeId, item)); for (const node of nodesMap.values()) { if (jobsMap.has(node.id)) { node.job = jobsMap.get(node.id); } } } export function ExecutionCanvas() { const compile = useCompile(); const { data, loading } = useResourceActionContext(); const { setTitle } = useDocumentTitle(); useEffect(() => { const { workflow } = data?.data ?? {}; setTitle?.(`${workflow?.title ? `${workflow.title} - ` : ''}${lang('Execution history')}`); }, [data?.data]); if (!data?.data) { if (loading) { return
{lang('Loading')}
; } else { return
{lang('Load failed')}
; } } const { jobs = [], workflow: { nodes = [], revisions = [], ...workflow } = {}, ...execution } = data?.data ?? {}; linkNodes(nodes); attachJobs(nodes, jobs); const entry = nodes.find((item) => !item.upstream); const statusOption = ExecutionStatusOptionsMap[execution.status]; return (
{lang('Workflow')} {workflow.title} {`#${execution.id}`}
{lang('End')}
); }