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';
|
|
|
|
|
|
|
|
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';
|
2022-11-11 23:37:41 +08:00
|
|
|
import { lang } from './locale';
|
2022-10-30 11:54:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-13 18:12:56 +08:00
|
|
|
function makeNodes(nodes, jobs: any[] = []): void {
|
2022-10-30 11:54:14 +08:00
|
|
|
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 (let node of nodesMap.values()) {
|
|
|
|
if (node.upstreamId) {
|
|
|
|
node.upstream = nodesMap.get(node.upstreamId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.downstreamId) {
|
|
|
|
node.downstream = nodesMap.get(node.downstreamId);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-11-11 23:37:41 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
jobs = [],
|
|
|
|
workflow: { nodes = [], revisions = [], ...workflow } = {},
|
|
|
|
...execution
|
|
|
|
} = data?.data ?? {};
|
|
|
|
|
|
|
|
makeNodes(nodes, jobs);
|
|
|
|
|
|
|
|
const entry = nodes.find(item => !item.upstream);
|
|
|
|
|
|
|
|
const statusOption = ExecutionStatusOptionsMap[execution.status];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FlowContext.Provider value={{
|
|
|
|
workflow: workflow.type ? workflow : null,
|
|
|
|
nodes,
|
|
|
|
execution
|
|
|
|
}}>
|
|
|
|
<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>
|
|
|
|
);
|
|
|
|
}
|