2022-10-30 11:54:14 +08:00
|
|
|
import React, { useEffect } from 'react';
|
2022-11-13 18:12:56 +08:00
|
|
|
import { Tag, Breadcrumb } from 'antd';
|
2022-10-30 11:54:14 +08:00
|
|
|
import { cx } from '@emotion/css';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
2023-04-25 13:12:14 +08:00
|
|
|
import { useCompile, useDocumentTitle, useResourceActionContext } from '@nocobase/client';
|
2022-10-30 11:54:14 +08:00
|
|
|
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';
|
2022-11-11 23:37:41 +08:00
|
|
|
import { lang } from './locale';
|
2023-02-20 11:52:06 +08:00
|
|
|
import { linkNodes } from './utils';
|
2022-10-30 11:54:14 +08:00
|
|
|
|
2023-02-20 11:52:06 +08:00
|
|
|
function attachJobs(nodes, jobs: any[] = []): void {
|
2022-10-30 11:54:14 +08:00
|
|
|
const nodesMap = new Map();
|
2023-04-25 13:12:14 +08:00
|
|
|
nodes.forEach((item) => nodesMap.set(item.id, item));
|
2022-10-30 11:54:14 +08:00
|
|
|
const jobsMap = new Map();
|
2023-04-25 13:12:14 +08:00
|
|
|
jobs.forEach((item) => jobsMap.set(item.nodeId, item));
|
|
|
|
for (const node of nodesMap.values()) {
|
2022-10-30 11:54:14 +08:00
|
|
|
if (jobsMap.has(node.id)) {
|
|
|
|
node.job = jobsMap.get(node.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ExecutionCanvas() {
|
|
|
|
const compile = useCompile();
|
2022-11-11 23:37:41 +08:00
|
|
|
const { data, loading } = useResourceActionContext();
|
2022-10-30 11:54:14 +08:00
|
|
|
const { setTitle } = useDocumentTitle();
|
|
|
|
useEffect(() => {
|
|
|
|
const { workflow } = data?.data ?? {};
|
2022-11-13 18:12:56 +08:00
|
|
|
setTitle?.(`${workflow?.title ? `${workflow.title} - ` : ''}${lang('Execution history')}`);
|
2022-10-30 11:54:14 +08:00
|
|
|
}, [data?.data]);
|
|
|
|
|
|
|
|
if (!data?.data) {
|
|
|
|
if (loading) {
|
2023-04-25 13:12:14 +08:00
|
|
|
return <div>{lang('Loading')}</div>;
|
2022-10-30 11:54:14 +08:00
|
|
|
} else {
|
2022-11-11 23:37:41 +08:00
|
|
|
return <div>{lang('Load failed')}</div>;
|
2022-10-30 11:54:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 13:12:14 +08:00
|
|
|
const { jobs = [], workflow: { nodes = [], revisions = [], ...workflow } = {}, ...execution } = data?.data ?? {};
|
2022-10-30 11:54:14 +08:00
|
|
|
|
2023-02-20 11:52:06 +08:00
|
|
|
linkNodes(nodes);
|
|
|
|
attachJobs(nodes, jobs);
|
2022-10-30 11:54:14 +08:00
|
|
|
|
2023-04-25 13:12:14 +08:00
|
|
|
const entry = nodes.find((item) => !item.upstream);
|
2022-10-30 11:54:14 +08:00
|
|
|
|
|
|
|
const statusOption = ExecutionStatusOptionsMap[execution.status];
|
|
|
|
|
|
|
|
return (
|
2023-04-25 13:12:14 +08:00
|
|
|
<FlowContext.Provider
|
|
|
|
value={{
|
|
|
|
workflow: workflow.type ? workflow : null,
|
|
|
|
nodes,
|
|
|
|
execution,
|
|
|
|
}}
|
|
|
|
>
|
2022-10-30 11:54:14 +08:00
|
|
|
<div className="workflow-toolbar">
|
|
|
|
<header>
|
2022-11-13 18:12:56 +08:00
|
|
|
<Breadcrumb>
|
|
|
|
<Breadcrumb.Item>
|
|
|
|
<Link to={`/admin/settings/workflow/workflows`}>{lang('Workflow')}</Link>
|
|
|
|
</Breadcrumb.Item>
|
|
|
|
<Breadcrumb.Item>
|
|
|
|
<Link to={`/admin/settings/workflow/workflows/${workflow.id}`}>{workflow.title}</Link>
|
|
|
|
</Breadcrumb.Item>
|
|
|
|
<Breadcrumb.Item>
|
|
|
|
<strong>{`#${execution.id}`}</strong>
|
|
|
|
</Breadcrumb.Item>
|
|
|
|
</Breadcrumb>
|
2022-10-30 11:54:14 +08:00
|
|
|
</header>
|
|
|
|
<aside>
|
|
|
|
<Tag color={statusOption.color}>{compile(statusOption.label)}</Tag>
|
|
|
|
<time>{str2moment(execution.updatedAt).format('YYYY-MM-DD HH:mm:ss')}</time>
|
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
<div className="workflow-canvas">
|
2022-11-01 10:00:24 +08:00
|
|
|
<TriggerConfig />
|
2022-10-30 11:54:14 +08:00
|
|
|
<div className={branchBlockClass}>
|
|
|
|
<Branch entry={entry} />
|
|
|
|
</div>
|
|
|
|
<div className={cx(nodeCardClass)}>
|
|
|
|
<div className={cx(nodeMetaClass)}>
|
2022-11-11 23:37:41 +08:00
|
|
|
<Tag color="#333">{lang('End')}</Tag>
|
2022-10-30 11:54:14 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</FlowContext.Provider>
|
|
|
|
);
|
|
|
|
}
|