feat(modeler): 同人确认发布(影响摘要+节点级diff+422校验错误清单)
- diffSummary.ts:DOMParser 命名空间感知的节点级 diff,按 userTask id 对齐比较 办理人(candidateUsers,走 codec 比 items)/指派(assignee)/表单(formKey)/会签(有无· collection·completionCondition)四类,含新增/删除节点;坏 XML 返 []。 - processModeler.ts:deployModel(id)/fetchImpact(id),422 校验清单与通用失败归一进 DeployOutcome(errors 兼容 flowable 对象式与网关字符串式两形态),impact 防御性 found。 - PublishConfirm.tsx:Dialog 展示流程 key/当前版本→新版本/运行中实例数(旧版本不受影响) + 变更节点清单;确认→deployModel 成功 toast「已发布 vN」并关闭,422→节点错误清单不关窗。 - ProcessModelerPage:顶栏发布按钮启用+gating(无 modelId 提示先存草稿),打开时存源 XML 作 diff 基线。 diffSummary 13 + PublishConfirm 9 + 页面 21;全量 223 单测绿,tsc -b + build 干净。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -223,6 +223,146 @@ export async function deleteDraft(id: string): Promise<void> {
|
|||||||
await http.delete(`/api/workflow/models/${encodeURIComponent(id)}`);
|
await http.delete(`/api/workflow/models/${encodeURIComponent(id)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 发布(deploy)+ 影响摘要(impact)(T3.1 后端 + T3.2 网关,超管门) ──────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一条发布校验错误。后端两种来源统一收进本形态(防御性——T3.1/T3.2 并行):
|
||||||
|
* - flowable ProcessValidator(T3.1 flowable-service):`{activityId,problem,defaultDescription}`。
|
||||||
|
* - 网关 EIP4 语义校验(T3.2):可能是字符串(或对象)→ 归一到 {message}。
|
||||||
|
*/
|
||||||
|
export interface DeployValidationError {
|
||||||
|
activityId?: string;
|
||||||
|
problem?: string;
|
||||||
|
defaultDescription?: string;
|
||||||
|
/** 字符串式错误(网关语义校验)或无结构错误的兜底展示文案。 */
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** deployModel 结果:ok=部署成功;否则 validationErrors(422 校验清单)或 message(通用失败)。 */
|
||||||
|
export interface DeployOutcome {
|
||||||
|
ok: boolean;
|
||||||
|
deploymentId?: string;
|
||||||
|
processKey?: string;
|
||||||
|
newVersion?: number;
|
||||||
|
/** 校验未通过(422 且带 errors)时的节点错误清单;发布弹窗按此渲染不关窗。 */
|
||||||
|
validationErrors?: DeployValidationError[];
|
||||||
|
/** 通用失败文案(404/无 errors 的 422/网络异常)。 */
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** GET /api/workflow/models/{id}/impact 归一结果。found=false 表示不可用(404/异常)。 */
|
||||||
|
export interface DeployImpact {
|
||||||
|
found: boolean;
|
||||||
|
processKey?: string;
|
||||||
|
/** 该 key 当前最新已部署版本(无则 0);发布后为 currentVersion+1。 */
|
||||||
|
currentVersion?: number;
|
||||||
|
/** 该 key 运行中实例数(留在旧版本不受影响)。 */
|
||||||
|
runningInstances?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RawDeployError {
|
||||||
|
activityId?: unknown;
|
||||||
|
problem?: unknown;
|
||||||
|
defaultDescription?: unknown;
|
||||||
|
message?: unknown;
|
||||||
|
msg?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** errors 数组归一:元素可为字符串(→{message})或对象(→取标准字段),滤掉全空项。 */
|
||||||
|
function normalizeDeployErrors(raw: unknown): DeployValidationError[] {
|
||||||
|
if (!Array.isArray(raw)) return [];
|
||||||
|
return raw
|
||||||
|
.map((e): DeployValidationError => {
|
||||||
|
if (typeof e === 'string') return { message: e };
|
||||||
|
const o = (e ?? {}) as RawDeployError;
|
||||||
|
const err: DeployValidationError = {};
|
||||||
|
if (o.activityId != null) err.activityId = String(o.activityId);
|
||||||
|
if (o.problem != null) err.problem = String(o.problem);
|
||||||
|
if (o.defaultDescription != null) err.defaultDescription = String(o.defaultDescription);
|
||||||
|
const m = o.message ?? o.msg;
|
||||||
|
if (m != null) err.message = String(m);
|
||||||
|
return err;
|
||||||
|
})
|
||||||
|
.filter((e) => e.activityId || e.problem || e.defaultDescription || e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** axios 错误的响应体结构(防御性访问,不依赖 AxiosError 类型强绑定)。 */
|
||||||
|
interface HttpErrorLike {
|
||||||
|
response?: { status?: number; data?: unknown };
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DeployRespBody {
|
||||||
|
status?: unknown;
|
||||||
|
deploymentId?: unknown;
|
||||||
|
processKey?: unknown;
|
||||||
|
newVersion?: unknown;
|
||||||
|
errors?: unknown;
|
||||||
|
msg?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
function successOutcome(d: DeployRespBody | undefined): DeployOutcome {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
deploymentId: d?.deploymentId != null ? String(d.deploymentId) : undefined,
|
||||||
|
processKey: d?.processKey != null ? String(d.processKey) : undefined,
|
||||||
|
newVersion: d?.newVersion != null ? Number(d.newVersion) : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/workflow/models/{id}/deploy —— 同人确认后发布草稿。
|
||||||
|
*
|
||||||
|
* 不向调用方抛异常:把 422(校验失败带 errors / 其他带 msg)与网络异常都归一进 {ok:false,...},
|
||||||
|
* 供发布弹窗区分「校验清单(不关窗让用户改)」与「通用失败 toast」。成功返 {ok:true,newVersion,...}。
|
||||||
|
*/
|
||||||
|
export async function deployModel(id: string): Promise<DeployOutcome> {
|
||||||
|
try {
|
||||||
|
const { data } = await http.post<DeployRespBody>(
|
||||||
|
`/api/workflow/models/${encodeURIComponent(id)}/deploy`,
|
||||||
|
);
|
||||||
|
// 2xx 但后端标 status:1(防御性——理论上 422 才失败,但双写路径下容错)。
|
||||||
|
if (data && data.status === 1) {
|
||||||
|
const errs = normalizeDeployErrors(data.errors);
|
||||||
|
return errs.length
|
||||||
|
? { ok: false, validationErrors: errs, message: data.msg != null ? String(data.msg) : undefined }
|
||||||
|
: { ok: false, message: data.msg != null ? String(data.msg) : '发布失败' };
|
||||||
|
}
|
||||||
|
return successOutcome(data);
|
||||||
|
} catch (e) {
|
||||||
|
const resp = (e as HttpErrorLike)?.response;
|
||||||
|
const d = resp?.data as DeployRespBody | undefined;
|
||||||
|
if (d) {
|
||||||
|
const errs = normalizeDeployErrors(d.errors);
|
||||||
|
if (errs.length) {
|
||||||
|
return { ok: false, validationErrors: errs, message: d.msg != null ? String(d.msg) : undefined };
|
||||||
|
}
|
||||||
|
return { ok: false, message: d.msg != null ? String(d.msg) : '发布失败' };
|
||||||
|
}
|
||||||
|
return { ok: false, message: '发布失败(服务不可用或网络异常)' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/workflow/models/{id}/impact —— 发布影响摘要(流程 key/当前版本/运行中实例数)。
|
||||||
|
* 防御性:任何失败(404/异常)返 {found:false},弹窗降级提示而不阻断发布。
|
||||||
|
*/
|
||||||
|
export async function fetchImpact(id: string): Promise<DeployImpact> {
|
||||||
|
try {
|
||||||
|
const { data } = await http.get<{ status?: unknown; processKey?: unknown; currentVersion?: unknown; runningInstances?: unknown }>(
|
||||||
|
`/api/workflow/models/${encodeURIComponent(id)}/impact`,
|
||||||
|
);
|
||||||
|
if (!data || data.status === 1) return { found: false };
|
||||||
|
return {
|
||||||
|
found: true,
|
||||||
|
processKey: data.processKey != null ? String(data.processKey) : undefined,
|
||||||
|
currentVersion: data.currentVersion != null ? Number(data.currentVersion) : undefined,
|
||||||
|
runningInstances: data.runningInstances != null ? Number(data.runningInstances) : undefined,
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return { found: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** GET /api/process-select/options —— 取存量流程选项(解 amis 信封,防御性返回数组)。 */
|
/** GET /api/process-select/options —— 取存量流程选项(解 amis 信封,防御性返回数组)。 */
|
||||||
export async function fetchProcessOptions(q?: string): Promise<ProcessOption[]> {
|
export async function fetchProcessOptions(q?: string): Promise<ProcessOption[]> {
|
||||||
const { data } = await http.get<ProcessSelectEnvelope>('/api/process-select/options', {
|
const { data } = await http.get<ProcessSelectEnvelope>('/api/process-select/options', {
|
||||||
|
|||||||
139
src/modeler/PublishConfirm.test.tsx
Normal file
139
src/modeler/PublishConfirm.test.tsx
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
import { render, screen, waitFor, fireEvent, act } from '@testing-library/react';
|
||||||
|
import { SYNTHETIC_BPMN } from './moddle/fixtures/synthetic-full-surface.bpmn';
|
||||||
|
|
||||||
|
vi.mock('../api/processModeler', () => ({
|
||||||
|
deployModel: vi.fn(),
|
||||||
|
fetchImpact: vi.fn(),
|
||||||
|
}));
|
||||||
|
const toastMock = vi.fn();
|
||||||
|
vi.mock('../components/ui', async (importOriginal) => ({
|
||||||
|
...(await importOriginal<typeof import('../components/ui')>()),
|
||||||
|
toast: (...args: unknown[]) => toastMock(...args),
|
||||||
|
}));
|
||||||
|
|
||||||
|
import { PublishConfirm } from './PublishConfirm';
|
||||||
|
import { deployModel, fetchImpact } from '../api/processModeler';
|
||||||
|
|
||||||
|
const mDeploy = vi.mocked(deployModel);
|
||||||
|
const mImpact = vi.mocked(fetchImpact);
|
||||||
|
|
||||||
|
// 办理人改一处 → diff 应识别「接收交底:办理人变更」。
|
||||||
|
const EDITED = SYNTHETIC_BPMN.replace(
|
||||||
|
'"type":"position"',
|
||||||
|
'"type":"user"',
|
||||||
|
);
|
||||||
|
|
||||||
|
function renderConfirm(overrides: Partial<React.ComponentProps<typeof PublishConfirm>> = {}) {
|
||||||
|
const onClose = vi.fn();
|
||||||
|
const onPublished = vi.fn();
|
||||||
|
render(
|
||||||
|
<PublishConfirm
|
||||||
|
modelId="MD-1"
|
||||||
|
openSourceXml={SYNTHETIC_BPMN}
|
||||||
|
currentXml={EDITED}
|
||||||
|
processKeyHint="总包合同交底"
|
||||||
|
onClose={onClose}
|
||||||
|
onPublished={onPublished}
|
||||||
|
{...overrides}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
return { onClose, onPublished };
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
toastMock.mockReset();
|
||||||
|
mDeploy.mockReset().mockResolvedValue({ ok: true, deploymentId: 'D1', processKey: '总包合同交底', newVersion: 4 });
|
||||||
|
mImpact.mockReset().mockResolvedValue({ found: true, processKey: '总包合同交底', currentVersion: 3, runningInstances: 7 });
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('PublishConfirm', () => {
|
||||||
|
it('展示影响摘要:流程 key、当前版本→新版本、运行中实例数', async () => {
|
||||||
|
renderConfirm();
|
||||||
|
await waitFor(() => expect(mImpact).toHaveBeenCalledWith('MD-1'));
|
||||||
|
expect(await screen.findByTestId('publish-impact-key')).toHaveTextContent('总包合同交底');
|
||||||
|
// currentVersion 3 → newVersion 4
|
||||||
|
expect(screen.getByTestId('publish-impact-version')).toHaveTextContent('v3');
|
||||||
|
expect(screen.getByTestId('publish-impact-version')).toHaveTextContent('v4');
|
||||||
|
expect(screen.getByTestId('publish-impact-instances')).toHaveTextContent('7');
|
||||||
|
// 灰字提示旧版本不受影响
|
||||||
|
expect(screen.getByTestId('publish-impact-instances')).toHaveTextContent(/不受.*影响/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('展示节点级 diff(办理人变更)', async () => {
|
||||||
|
renderConfirm();
|
||||||
|
await screen.findByTestId('publish-diff-list');
|
||||||
|
expect(screen.getByTestId('publish-diff-list')).toHaveTextContent('接收交底');
|
||||||
|
expect(screen.getByTestId('publish-diff-list')).toHaveTextContent('办理人变更');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('无变化时提示未检测到关键属性变化', async () => {
|
||||||
|
renderConfirm({ currentXml: SYNTHETIC_BPMN });
|
||||||
|
await screen.findByTestId('publish-diff-empty');
|
||||||
|
expect(screen.getByTestId('publish-diff-empty')).toHaveTextContent(/未检测到|无/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('确认发布成功 → deployModel、toast「已发布 v4」、onPublished(4)、关闭', async () => {
|
||||||
|
const { onClose, onPublished } = renderConfirm();
|
||||||
|
await screen.findByTestId('publish-confirm-btn');
|
||||||
|
fireEvent.click(screen.getByTestId('publish-confirm-btn'));
|
||||||
|
await waitFor(() => expect(mDeploy).toHaveBeenCalledWith('MD-1'));
|
||||||
|
await waitFor(() => expect(toastMock).toHaveBeenCalledWith(expect.stringContaining('已发布 v4'), 'ok'));
|
||||||
|
expect(onPublished).toHaveBeenCalledWith(4);
|
||||||
|
expect(onClose).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('422 校验失败 → 按 errors 渲染节点错误清单,不关弹窗、不 onPublished', async () => {
|
||||||
|
mDeploy.mockResolvedValue({
|
||||||
|
ok: false,
|
||||||
|
validationErrors: [
|
||||||
|
{ activityId: 't_receive', problem: 'activiti-usertask-assignee', defaultDescription: '用户任务缺办理人' },
|
||||||
|
{ message: 'formKey 不存在于 view_wftemplate' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const { onClose, onPublished } = renderConfirm();
|
||||||
|
await screen.findByTestId('publish-confirm-btn');
|
||||||
|
fireEvent.click(screen.getByTestId('publish-confirm-btn'));
|
||||||
|
await waitFor(() => expect(screen.getByTestId('publish-errors')).toBeInTheDocument());
|
||||||
|
expect(screen.getByTestId('publish-error-0')).toHaveTextContent('t_receive');
|
||||||
|
expect(screen.getByTestId('publish-error-0')).toHaveTextContent('用户任务缺办理人');
|
||||||
|
expect(screen.getByTestId('publish-error-1')).toHaveTextContent('formKey 不存在于 view_wftemplate');
|
||||||
|
expect(onClose).not.toHaveBeenCalled();
|
||||||
|
expect(onPublished).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('通用失败(无 errors)→ toast 报错,不关弹窗', async () => {
|
||||||
|
mDeploy.mockResolvedValue({ ok: false, message: '草稿不存在: MD-1' });
|
||||||
|
const { onClose } = renderConfirm();
|
||||||
|
await screen.findByTestId('publish-confirm-btn');
|
||||||
|
fireEvent.click(screen.getByTestId('publish-confirm-btn'));
|
||||||
|
await waitFor(() => expect(toastMock).toHaveBeenCalledWith(expect.stringContaining('草稿不存在'), 'err'));
|
||||||
|
expect(onClose).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('取消 → onClose,不发布', async () => {
|
||||||
|
const { onClose } = renderConfirm();
|
||||||
|
await screen.findByTestId('publish-cancel-btn');
|
||||||
|
fireEvent.click(screen.getByTestId('publish-cancel-btn'));
|
||||||
|
expect(onClose).toHaveBeenCalled();
|
||||||
|
expect(mDeploy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('impact 不可用(found:false)→ 降级用 processKeyHint 显示 key,仍可发布', async () => {
|
||||||
|
mImpact.mockResolvedValue({ found: false });
|
||||||
|
renderConfirm();
|
||||||
|
await waitFor(() => expect(mImpact).toHaveBeenCalled());
|
||||||
|
expect(await screen.findByTestId('publish-impact-key')).toHaveTextContent('总包合同交底');
|
||||||
|
// 版本不可知时显示占位而非崩溃
|
||||||
|
expect(screen.getByTestId('publish-impact-version')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('publish-confirm-btn')).not.toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('首次发布(currentVersion 0)→ 显示「首次发布 → v1」', async () => {
|
||||||
|
mImpact.mockResolvedValue({ found: true, processKey: 'new_proc', currentVersion: 0, runningInstances: 0 });
|
||||||
|
renderConfirm();
|
||||||
|
await waitFor(() => expect(mImpact).toHaveBeenCalled());
|
||||||
|
await waitFor(() => expect(screen.getByTestId('publish-impact-version')).toHaveTextContent(/首次发布/));
|
||||||
|
expect(screen.getByTestId('publish-impact-version')).toHaveTextContent('v1');
|
||||||
|
});
|
||||||
|
});
|
||||||
183
src/modeler/PublishConfirm.tsx
Normal file
183
src/modeler/PublishConfirm.tsx
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
// 同人确认发布弹窗(T3.3)。
|
||||||
|
//
|
||||||
|
// 发布点击后打开本弹窗:并发拉「影响摘要」(fetchImpact) + 本地算「节点级 diff」(diffSummary,
|
||||||
|
// 打开时源 XML vs 当前 saveXML) → 展示流程 key / 当前版本→新版本 / 运行中实例数(灰字提示旧版本
|
||||||
|
// 不受影响)/ 办理人·会签等变更节点清单 → 用户确认 → deployModel。
|
||||||
|
// - 成功:toast「已发布 vN」(用后端返回的真实 newVersion) + onPublished + 关闭。
|
||||||
|
// - 422 校验失败:按 errors 渲染节点错误清单,**不关弹窗**让用户回去改。
|
||||||
|
// - 通用失败:toast 报错,不关弹窗。
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Dialog } from '../components/ui';
|
||||||
|
import { toast } from '../components/ui';
|
||||||
|
import { deployModel, fetchImpact, type DeployImpact, type DeployValidationError } from '../api/processModeler';
|
||||||
|
import { diffSummary, type NodeDiff } from './diffSummary';
|
||||||
|
|
||||||
|
interface PublishConfirmProps {
|
||||||
|
/** 草稿 modelId(必须已存草稿才可发布)。 */
|
||||||
|
modelId: string;
|
||||||
|
/** 打开流程时保存的源 XML(diff 基线)。 */
|
||||||
|
openSourceXml: string;
|
||||||
|
/** 当前编辑器 saveXML 结果(diff 对比方;由父页在打开弹窗前算好)。 */
|
||||||
|
currentXml: string;
|
||||||
|
/** impact 未回来 / 不可用时兜底显示的流程 key(loadedKey)。 */
|
||||||
|
processKeyHint?: string;
|
||||||
|
onClose: () => void;
|
||||||
|
/** 发布成功回调(带后端返回的真实新版本号)。 */
|
||||||
|
onPublished: (newVersion?: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 单条校验错误的展示文案:activityId + 问题描述(defaultDescription 优先,回退 problem/message)。 */
|
||||||
|
function errorText(e: DeployValidationError): string {
|
||||||
|
const desc = e.defaultDescription || e.problem || e.message || '校验未通过';
|
||||||
|
return e.activityId ? `[${e.activityId}] ${desc}` : desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PublishConfirm({
|
||||||
|
modelId,
|
||||||
|
openSourceXml,
|
||||||
|
currentXml,
|
||||||
|
processKeyHint,
|
||||||
|
onClose,
|
||||||
|
onPublished,
|
||||||
|
}: PublishConfirmProps) {
|
||||||
|
// 节点级 diff 是纯本地同步计算,初始化即得。
|
||||||
|
const [diff] = useState<NodeDiff[]>(() => diffSummary(openSourceXml, currentXml));
|
||||||
|
const [impact, setImpact] = useState<DeployImpact | null>(null);
|
||||||
|
const [impactLoaded, setImpactLoaded] = useState(false);
|
||||||
|
const [deploying, setDeploying] = useState(false);
|
||||||
|
const [errors, setErrors] = useState<DeployValidationError[] | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let alive = true;
|
||||||
|
fetchImpact(modelId)
|
||||||
|
.then((r) => {
|
||||||
|
if (!alive) return;
|
||||||
|
setImpact(r);
|
||||||
|
setImpactLoaded(true);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
if (!alive) return;
|
||||||
|
setImpact({ found: false });
|
||||||
|
setImpactLoaded(true);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
alive = false;
|
||||||
|
};
|
||||||
|
}, [modelId]);
|
||||||
|
|
||||||
|
async function handleConfirm() {
|
||||||
|
if (deploying) return;
|
||||||
|
setDeploying(true);
|
||||||
|
setErrors(null);
|
||||||
|
try {
|
||||||
|
const r = await deployModel(modelId);
|
||||||
|
if (r.ok) {
|
||||||
|
toast('已发布 v' + (r.newVersion ?? '?'), 'ok');
|
||||||
|
onPublished(r.newVersion);
|
||||||
|
onClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (r.validationErrors && r.validationErrors.length) {
|
||||||
|
setErrors(r.validationErrors); // 校验清单 → 不关窗,让用户回去改
|
||||||
|
} else {
|
||||||
|
toast(r.message ?? '发布失败', 'err');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setDeploying(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = impact?.processKey || processKeyHint || '(未知)';
|
||||||
|
const cur = impact?.currentVersion ?? 0;
|
||||||
|
const versionText = !impactLoaded
|
||||||
|
? '版本加载中…'
|
||||||
|
: impact?.found
|
||||||
|
? cur > 0
|
||||||
|
? `v${cur} → v${cur + 1}`
|
||||||
|
: `首次发布 → v1`
|
||||||
|
: '(版本信息暂不可用)';
|
||||||
|
const running = impact?.found ? (impact.runningInstances ?? 0) : undefined;
|
||||||
|
|
||||||
|
const foot = (
|
||||||
|
<>
|
||||||
|
<button className="btn" data-testid="publish-cancel-btn" onClick={onClose} disabled={deploying}>
|
||||||
|
取消
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn btn-primary"
|
||||||
|
data-testid="publish-confirm-btn"
|
||||||
|
onClick={handleConfirm}
|
||||||
|
disabled={deploying}
|
||||||
|
>
|
||||||
|
{deploying ? '发布中…' : '确认发布'}
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog title="发布流程" width={520} onClose={onClose} foot={foot}>
|
||||||
|
<div data-testid="process-modeler-publish-confirm" style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||||
|
{/* 影响摘要 */}
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, fontSize: 13 }}>
|
||||||
|
<Row label="流程标识(key)">
|
||||||
|
<code data-testid="publish-impact-key">{key}</code>
|
||||||
|
</Row>
|
||||||
|
<Row label="版本">
|
||||||
|
<span data-testid="publish-impact-version">{versionText}</span>
|
||||||
|
</Row>
|
||||||
|
<Row label="运行中实例">
|
||||||
|
<span data-testid="publish-impact-instances">
|
||||||
|
{running === undefined ? '—' : running}
|
||||||
|
<span style={{ color: 'var(--text-3)', marginLeft: 8, fontSize: 12 }}>
|
||||||
|
(留在旧版本,不受本次发布影响)
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</Row>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 节点级变更清单 */}
|
||||||
|
<div>
|
||||||
|
<div style={{ fontWeight: 600, fontSize: 13, marginBottom: 6 }}>办理人 / 会签等变更节点</div>
|
||||||
|
{diff.length === 0 ? (
|
||||||
|
<div data-testid="publish-diff-empty" style={{ fontSize: 12, color: 'var(--text-3)' }}>
|
||||||
|
未检测到办理人 / 会签 / 表单等关键属性变化(可能仅调整了布局或其他节点)。
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<ul data-testid="publish-diff-list" style={{ margin: 0, paddingLeft: 18, fontSize: 13, lineHeight: 1.7 }}>
|
||||||
|
{diff.map((d, i) => (
|
||||||
|
<li key={i} data-testid={`publish-diff-item-${i}`}>
|
||||||
|
<strong>{d.nodeName}</strong>:{d.changes.join('、')}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 校验错误清单(422,不关窗) */}
|
||||||
|
{errors && errors.length ? (
|
||||||
|
<div data-testid="publish-errors" style={{ border: '1px solid var(--err)', borderRadius: 4, padding: 10 }}>
|
||||||
|
<div style={{ color: 'var(--err)', fontWeight: 600, fontSize: 13, marginBottom: 6 }}>
|
||||||
|
校验未通过,请修正后重试:
|
||||||
|
</div>
|
||||||
|
<ul style={{ margin: 0, paddingLeft: 18, fontSize: 13, lineHeight: 1.7 }}>
|
||||||
|
{errors.map((e, i) => (
|
||||||
|
<li key={i} data-testid={`publish-error-${i}`} style={{ color: 'var(--err)' }}>
|
||||||
|
{errorText(e)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Row({ label, children }: { label: string; children: React.ReactNode }) {
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', gap: 8 }}>
|
||||||
|
<span style={{ flex: '0 0 120px', color: 'var(--text-3)' }}>{label}</span>
|
||||||
|
<span style={{ flex: 1, minWidth: 0 }}>{children}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
129
src/modeler/diffSummary.test.ts
Normal file
129
src/modeler/diffSummary.test.ts
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { SYNTHETIC_BPMN } from './moddle/fixtures/synthetic-full-surface.bpmn';
|
||||||
|
import { diffSummary } from './diffSummary';
|
||||||
|
|
||||||
|
// 节点级 diff(P2):以「总包合同交底」逐字对照的 synthetic fixture 为基线,
|
||||||
|
// 按 userTask id 对齐比较四类属性变化(办理人/指派/formKey/会签)。改动用**定点字符串替换**
|
||||||
|
// 从基线派生,确保只动被测那一处(其余节点无 diff),与真实存储态绑定不手抄表达式。
|
||||||
|
//
|
||||||
|
// fixture 关键锚点(见 synthetic-full-surface.bpmn):
|
||||||
|
// - t_write(编写交底):activiti:assignee=${assignee} + 多实例会签(collection type=projectRoleType,
|
||||||
|
// completionCondition 全票 ==1),无 candidateUsers。
|
||||||
|
// - t_receive(接收交底):activiti:candidateUsers(type=position)+ activiti:formKey=3eee7644-…,无会签。
|
||||||
|
|
||||||
|
/** 从基线移除 t_write 的会签块(多实例 loop)。 */
|
||||||
|
const NO_COSIGN = SYNTHETIC_BPMN.replace(
|
||||||
|
/<multiInstanceLoopCharacteristics[\s\S]*?<\/multiInstanceLoopCharacteristics>/,
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('diffSummary — 节点级四类属性 diff', () => {
|
||||||
|
it('完全相同 → 无变化节点', () => {
|
||||||
|
expect(diffSummary(SYNTHETIC_BPMN, SYNTHETIC_BPMN)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('办理人变更(candidateUsers items type position→user)→ 只标接收交底「办理人变更」', () => {
|
||||||
|
const edited = SYNTHETIC_BPMN.replace(
|
||||||
|
'"type":"position"',
|
||||||
|
'"type":"user"',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, edited);
|
||||||
|
expect(diff).toEqual([{ nodeName: '接收交底', changes: ['办理人变更'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('指派人变更(activiti:assignee ${assignee}→${boss})→ 只标编写交底「指派人变更」', () => {
|
||||||
|
const edited = SYNTHETIC_BPMN.replace(
|
||||||
|
'activiti:assignee="${assignee}"',
|
||||||
|
'activiti:assignee="${boss}"',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, edited);
|
||||||
|
expect(diff).toEqual([{ nodeName: '编写交底', changes: ['指派人变更'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('formKey 变更 → 只标接收交底「表单变更」', () => {
|
||||||
|
const edited = SYNTHETIC_BPMN.replace(
|
||||||
|
'activiti:formKey="3eee7644-f51d-4755-9abb-aca7f4dd8516"',
|
||||||
|
'activiti:formKey="99999999-0000-0000-0000-000000000000"',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, edited);
|
||||||
|
expect(diff).toEqual([{ nodeName: '接收交底', changes: ['表单变更'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('会签开启(源无会签→当前有)→ 编写交底「会签开启」', () => {
|
||||||
|
const diff = diffSummary(NO_COSIGN, SYNTHETIC_BPMN);
|
||||||
|
expect(diff).toEqual([{ nodeName: '编写交底', changes: ['会签开启'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('会签关闭(源有会签→当前无)→ 编写交底「会签关闭」', () => {
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, NO_COSIGN);
|
||||||
|
expect(diff).toEqual([{ nodeName: '编写交底', changes: ['会签关闭'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('会签人员变更(collection items type projectRoleType→scriptUser)→ 编写交底「会签人员变更」', () => {
|
||||||
|
const edited = SYNTHETIC_BPMN.replace(
|
||||||
|
'"type":"projectRoleType"',
|
||||||
|
'"type":"scriptUser"',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, edited);
|
||||||
|
expect(diff).toEqual([{ nodeName: '编写交底', changes: ['会签人员变更'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('会签完成条件变更(全票 ==1 → 过半 >0.5)→ 编写交底「会签完成条件变更」', () => {
|
||||||
|
const edited = SYNTHETIC_BPMN.replace(
|
||||||
|
'/nrOfInstances==1}',
|
||||||
|
'/nrOfInstances>0.5}',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, edited);
|
||||||
|
expect(diff).toEqual([{ nodeName: '编写交底', changes: ['会签完成条件变更'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('一个节点多类同时变更 → changes 汇总多项', () => {
|
||||||
|
let edited = SYNTHETIC_BPMN.replace(
|
||||||
|
'activiti:formKey="3eee7644-f51d-4755-9abb-aca7f4dd8516"',
|
||||||
|
'activiti:formKey="99999999-0000-0000-0000-000000000000"',
|
||||||
|
);
|
||||||
|
edited = edited.replace(
|
||||||
|
'"type":"position"',
|
||||||
|
'"type":"user"',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, edited);
|
||||||
|
expect(diff).toHaveLength(1);
|
||||||
|
expect(diff[0].nodeName).toBe('接收交底');
|
||||||
|
expect(diff[0].changes).toEqual(expect.arrayContaining(['办理人变更', '表单变更']));
|
||||||
|
expect(diff[0].changes).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('新增用户任务 → 标「新增用户任务」', () => {
|
||||||
|
const added = SYNTHETIC_BPMN.replace(
|
||||||
|
'<endEvent id="end_1"></endEvent>',
|
||||||
|
'<userTask id="t_new" name="新审批"></userTask><endEvent id="end_1"></endEvent>',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, added);
|
||||||
|
expect(diff).toEqual([{ nodeName: '新审批', changes: ['新增用户任务'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('删除用户任务 → 标「删除用户任务」', () => {
|
||||||
|
// 从当前移除 t_receive(用其带 boundaryEvent 的完整块不便,改用 name 回退验证:直接删 t_write 块)。
|
||||||
|
const removed = SYNTHETIC_BPMN.replace(
|
||||||
|
/<userTask id="t_write"[\s\S]*?<\/userTask>/,
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, removed);
|
||||||
|
expect(diff).toEqual([{ nodeName: '编写交底', changes: ['删除用户任务'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('无 name 的节点回退用 id 作 nodeName', () => {
|
||||||
|
const added = SYNTHETIC_BPMN.replace(
|
||||||
|
'<endEvent id="end_1"></endEvent>',
|
||||||
|
'<userTask id="t_noname"></userTask><endEvent id="end_1"></endEvent>',
|
||||||
|
);
|
||||||
|
const diff = diffSummary(SYNTHETIC_BPMN, added);
|
||||||
|
expect(diff).toEqual([{ nodeName: 't_noname', changes: ['新增用户任务'] }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('坏 XML(任一侧解析失败)→ 返回空数组不抛', () => {
|
||||||
|
expect(() => diffSummary('<not xml', SYNTHETIC_BPMN)).not.toThrow();
|
||||||
|
expect(diffSummary('<not', SYNTHETIC_BPMN)).toEqual([]);
|
||||||
|
expect(diffSummary(SYNTHETIC_BPMN, '<<<')).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
170
src/modeler/diffSummary.ts
Normal file
170
src/modeler/diffSummary.ts
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
// 发布影响摘要——节点级 diff(计划 §0.5 P2)。
|
||||||
|
//
|
||||||
|
// 纯函数:以打开流程时保存的**源 XML**(openSourceXml)对比当前编辑器 saveXML 的**当前 XML**
|
||||||
|
// (currentXml),按 userTask id 对齐,比较四类会真正影响运行期办理/派任的属性变化:
|
||||||
|
// ① 办理人 activiti:candidateUsers(用 candidateExpression.parse 比 items,忽略仅格式差异)
|
||||||
|
// ② 指派人 activiti:assignee
|
||||||
|
// ③ 表单 activiti:formKey
|
||||||
|
// ④ 会签 多实例(有无切换 / collection 人员 / completionCondition 完成条件)
|
||||||
|
// 以及新增 / 删除的用户任务。只返回有变化的节点。不做通用图 diff(YAGNI)。
|
||||||
|
//
|
||||||
|
// 实现要点:
|
||||||
|
// - 用 DOMParser 命名空间感知解析(getElementsByTagNameNS / getAttributeNS 按 URI 匹配),
|
||||||
|
// 故 bpmn-js 导出的 `bpmn:` 前缀 vs 存量源的默认命名空间不影响对齐(前缀无关,只认 URI)。
|
||||||
|
// - 办理人/会签人员的比较走 candidateExpression codec:解析出 items 做规范化签名对比,
|
||||||
|
// bpmn-js round-trip 产生的纯格式差异(半角{}→全角【】等)不误报为变更。
|
||||||
|
// - 防御性:任一侧 XML 解析失败 → 返回 [](影响摘要是补充信息,版本/实例数才是权威)。
|
||||||
|
|
||||||
|
import { parseCandidateExpression } from './candidateExpression';
|
||||||
|
|
||||||
|
const BPMN_NS = 'http://www.omg.org/spec/BPMN/20100524/MODEL';
|
||||||
|
const ACTIVITI_NS = 'http://activiti.org/bpmn';
|
||||||
|
const FLOWABLE_NS = 'http://flowable.org/bpmn';
|
||||||
|
|
||||||
|
/** 单个变化节点:节点名(name 回退 id)+ 变化类别中文清单。 */
|
||||||
|
export interface NodeDiff {
|
||||||
|
nodeName: string;
|
||||||
|
changes: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** activiti/flowable 扩展属性读值(命名空间 URI 匹配 + 限定名回退),缺失返 undefined。 */
|
||||||
|
function extAttr(el: Element, local: string): string | undefined {
|
||||||
|
const tryNs = (ns: string): string | undefined => {
|
||||||
|
const v = el.getAttributeNS(ns, local);
|
||||||
|
return v == null ? undefined : v;
|
||||||
|
};
|
||||||
|
let v = tryNs(ACTIVITI_NS);
|
||||||
|
if (v === undefined) v = tryNs(FLOWABLE_NS);
|
||||||
|
if (v === undefined) {
|
||||||
|
const q = el.getAttribute('activiti:' + local) ?? el.getAttribute('flowable:' + local);
|
||||||
|
v = q == null ? undefined : q;
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解析 XML → Document;坏 XML(parsererror / 无根 / 抛异常)返 null。 */
|
||||||
|
function parseDoc(xml: string): Document | null {
|
||||||
|
if (typeof xml !== 'string' || xml.length === 0) return null;
|
||||||
|
try {
|
||||||
|
const doc = new DOMParser().parseFromString(xml, 'application/xml');
|
||||||
|
if (doc.getElementsByTagName('parsererror').length > 0) return null;
|
||||||
|
if (!doc.documentElement) return null;
|
||||||
|
return doc;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 文档内所有 userTask(按命名空间 URI),id→元素,保留文档顺序。 */
|
||||||
|
function userTasks(doc: Document): Map<string, Element> {
|
||||||
|
const map = new Map<string, Element>();
|
||||||
|
const list = doc.getElementsByTagNameNS(BPMN_NS, 'userTask');
|
||||||
|
for (let i = 0; i < list.length; i++) {
|
||||||
|
const el = list[i];
|
||||||
|
const id = el.getAttribute('id');
|
||||||
|
if (id) map.set(id, el);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
function nameOf(el: Element, id: string): string {
|
||||||
|
const name = el.getAttribute('name');
|
||||||
|
return name && name.trim() ? name : id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** userTask 的多实例(会签)loop 元素,无则 null。 */
|
||||||
|
function miOf(el: Element): Element | null {
|
||||||
|
const list = el.getElementsByTagNameNS(BPMN_NS, 'multiInstanceLoopCharacteristics');
|
||||||
|
return list.length ? list[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 多实例完成条件 body(规范化去空白),无则空串。 */
|
||||||
|
function completionBody(mi: Element): string {
|
||||||
|
const list = mi.getElementsByTagNameNS(BPMN_NS, 'completionCondition');
|
||||||
|
return list.length ? (list[0].textContent ?? '').trim() : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 办理人/会签人员表达式的**语义签名**:能解析则取 items 的规范化投影(type/content/四通知开关),
|
||||||
|
* 忽略 meta 与格式差异;不能解析(非标准表达式)则回退原串比较;空则空串。
|
||||||
|
* 两侧签名不同即视为人员配置变化。
|
||||||
|
*/
|
||||||
|
function exprSig(raw: string | undefined): string {
|
||||||
|
if (!raw) return '';
|
||||||
|
const parsed = parseCandidateExpression(raw);
|
||||||
|
if (!parsed) return 'RAW:' + raw;
|
||||||
|
return JSON.stringify(
|
||||||
|
parsed.items.map((i) => [
|
||||||
|
i.type,
|
||||||
|
i.content,
|
||||||
|
!!i.isCandidate,
|
||||||
|
!!i.isSendMail,
|
||||||
|
!!i.isSendPhone,
|
||||||
|
!!i.isSendMessage,
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 比较同一 id 的两个 userTask,返回变化类别清单(无变化返 [])。 */
|
||||||
|
function nodeChanges(a: Element, b: Element): string[] {
|
||||||
|
const changes: string[] = [];
|
||||||
|
|
||||||
|
if (exprSig(extAttr(a, 'candidateUsers')) !== exprSig(extAttr(b, 'candidateUsers'))) {
|
||||||
|
changes.push('办理人变更');
|
||||||
|
}
|
||||||
|
if ((extAttr(a, 'assignee') ?? '') !== (extAttr(b, 'assignee') ?? '')) {
|
||||||
|
changes.push('指派人变更');
|
||||||
|
}
|
||||||
|
if ((extAttr(a, 'formKey') ?? '') !== (extAttr(b, 'formKey') ?? '')) {
|
||||||
|
changes.push('表单变更');
|
||||||
|
}
|
||||||
|
|
||||||
|
const miA = miOf(a);
|
||||||
|
const miB = miOf(b);
|
||||||
|
if (miA && !miB) {
|
||||||
|
changes.push('会签关闭');
|
||||||
|
} else if (!miA && miB) {
|
||||||
|
changes.push('会签开启');
|
||||||
|
} else if (miA && miB) {
|
||||||
|
if (exprSig(extAttr(miA, 'collection')) !== exprSig(extAttr(miB, 'collection'))) {
|
||||||
|
changes.push('会签人员变更');
|
||||||
|
}
|
||||||
|
if (completionBody(miA) !== completionBody(miB)) {
|
||||||
|
changes.push('会签完成条件变更');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点级发布影响 diff。openSourceXml=打开时源,currentXml=当前 saveXML。
|
||||||
|
* 返回有变化的用户任务清单(含新增/删除);任一侧坏 XML → []。
|
||||||
|
*/
|
||||||
|
export function diffSummary(openSourceXml: string, currentXml: string): NodeDiff[] {
|
||||||
|
const srcDoc = parseDoc(openSourceXml);
|
||||||
|
const curDoc = parseDoc(currentXml);
|
||||||
|
if (!srcDoc || !curDoc) return [];
|
||||||
|
|
||||||
|
const src = userTasks(srcDoc);
|
||||||
|
const cur = userTasks(curDoc);
|
||||||
|
const out: NodeDiff[] = [];
|
||||||
|
|
||||||
|
// 当前文档顺序:匹配节点比属性;仅当前有 = 新增。
|
||||||
|
cur.forEach((curEl, id) => {
|
||||||
|
const srcEl = src.get(id);
|
||||||
|
if (!srcEl) {
|
||||||
|
out.push({ nodeName: nameOf(curEl, id), changes: ['新增用户任务'] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const changes = nodeChanges(srcEl, curEl);
|
||||||
|
if (changes.length) out.push({ nodeName: nameOf(curEl, id), changes });
|
||||||
|
});
|
||||||
|
|
||||||
|
// 仅源有 = 删除。
|
||||||
|
src.forEach((srcEl, id) => {
|
||||||
|
if (!cur.has(id)) out.push({ nodeName: nameOf(srcEl, id), changes: ['删除用户任务'] });
|
||||||
|
});
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
@@ -42,6 +42,9 @@ vi.mock('../api/processModeler', () => ({
|
|||||||
saveDraft: vi.fn(() => Promise.resolve()),
|
saveDraft: vi.fn(() => Promise.resolve()),
|
||||||
draftFromProcDef: vi.fn(() => Promise.resolve('FP-1')),
|
draftFromProcDef: vi.fn(() => Promise.resolve('FP-1')),
|
||||||
deleteDraft: vi.fn(() => Promise.resolve()),
|
deleteDraft: vi.fn(() => Promise.resolve()),
|
||||||
|
// T3.3 发布:PublishConfirm 挂载拉 impact、确认调 deploy——mock 成默认成功态。
|
||||||
|
deployModel: vi.fn(() => Promise.resolve({ ok: true, deploymentId: 'D1', processKey: 'k', newVersion: 4 })),
|
||||||
|
fetchImpact: vi.fn(() => Promise.resolve({ found: true, processKey: 'k', currentVersion: 3, runningInstances: 0 })),
|
||||||
}));
|
}));
|
||||||
vi.mock('../auth/token', async (importOriginal) => ({
|
vi.mock('../auth/token', async (importOriginal) => ({
|
||||||
...(await importOriginal<typeof import('../auth/token')>()),
|
...(await importOriginal<typeof import('../auth/token')>()),
|
||||||
@@ -59,6 +62,8 @@ import {
|
|||||||
saveDraft,
|
saveDraft,
|
||||||
draftFromProcDef,
|
draftFromProcDef,
|
||||||
deleteDraft,
|
deleteDraft,
|
||||||
|
deployModel,
|
||||||
|
fetchImpact,
|
||||||
} from '../api/processModeler';
|
} from '../api/processModeler';
|
||||||
import { getProfile } from '../auth/token';
|
import { getProfile } from '../auth/token';
|
||||||
|
|
||||||
@@ -71,6 +76,8 @@ const mCreateDraft = vi.mocked(createDraft);
|
|||||||
const mSaveDraft = vi.mocked(saveDraft);
|
const mSaveDraft = vi.mocked(saveDraft);
|
||||||
const mFromProcDef = vi.mocked(draftFromProcDef);
|
const mFromProcDef = vi.mocked(draftFromProcDef);
|
||||||
const mDeleteDraft = vi.mocked(deleteDraft);
|
const mDeleteDraft = vi.mocked(deleteDraft);
|
||||||
|
const mDeploy = vi.mocked(deployModel);
|
||||||
|
const mImpact = vi.mocked(fetchImpact);
|
||||||
const mProfile = vi.mocked(getProfile);
|
const mProfile = vi.mocked(getProfile);
|
||||||
|
|
||||||
function renderPage(initialPath = '/process-modeler') {
|
function renderPage(initialPath = '/process-modeler') {
|
||||||
@@ -103,6 +110,8 @@ beforeEach(() => {
|
|||||||
mSaveDraft.mockReset().mockResolvedValue(undefined);
|
mSaveDraft.mockReset().mockResolvedValue(undefined);
|
||||||
mFromProcDef.mockReset().mockResolvedValue('FP-1');
|
mFromProcDef.mockReset().mockResolvedValue('FP-1');
|
||||||
mDeleteDraft.mockReset().mockResolvedValue(undefined);
|
mDeleteDraft.mockReset().mockResolvedValue(undefined);
|
||||||
|
mDeploy.mockReset().mockResolvedValue({ ok: true, deploymentId: 'D1', processKey: 'k', newVersion: 4 });
|
||||||
|
mImpact.mockReset().mockResolvedValue({ found: true, processKey: 'k', currentVersion: 3, runningInstances: 0 });
|
||||||
mProfile.mockReset().mockReturnValue({ userId: 'ADMIN', account: 'admin', name: '管理员', roles: [] });
|
mProfile.mockReset().mockReturnValue({ userId: 'ADMIN', account: 'admin', name: '管理员', roles: [] });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -292,4 +301,44 @@ describe('ProcessModelerPage', () => {
|
|||||||
expect(mDeleteDraft).not.toHaveBeenCalled();
|
expect(mDeleteDraft).not.toHaveBeenCalled();
|
||||||
confirmSpy.mockRestore();
|
confirmSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ── T3.3 发布 gating + 同人确认 ────────────────────────────────────────────
|
||||||
|
const publishBtn = () => screen.getByTestId('process-modeler-publish');
|
||||||
|
|
||||||
|
it('未打开任何流程时发布按钮 disabled(无 Modeler 实例)', async () => {
|
||||||
|
renderPage();
|
||||||
|
expect(publishBtn()).toBeDisabled();
|
||||||
|
await act(async () => {
|
||||||
|
await Promise.resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('发布 gating:存量按 key 打开(尚无 modelId)→点发布不开确认弹窗、不 deploy', async () => {
|
||||||
|
renderPage('/process-modeler?procKey=' + encodeURIComponent('总包合同交底'));
|
||||||
|
await waitFor(() => expect(importXMLMock).toHaveBeenCalled());
|
||||||
|
await waitFor(() => expect(publishBtn()).not.toBeDisabled()); // 可点(触发提示分支)
|
||||||
|
fireEvent.click(publishBtn());
|
||||||
|
await act(async () => {
|
||||||
|
await Promise.resolve();
|
||||||
|
});
|
||||||
|
// 无 modelId:提示先存草稿,不开弹窗、不发布
|
||||||
|
expect(screen.queryByTestId('process-modeler-publish-confirm')).not.toBeInTheDocument();
|
||||||
|
expect(mDeploy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('发布:打开草稿(有 modelId)→点发布→开同人确认弹窗并按 modelId 拉 impact', async () => {
|
||||||
|
renderPage('/process-modeler?modelId=MD-7');
|
||||||
|
await waitFor(() => expect(importXMLMock).toHaveBeenCalled());
|
||||||
|
await waitFor(() => expect(publishBtn()).not.toBeDisabled());
|
||||||
|
fireEvent.click(publishBtn());
|
||||||
|
await waitFor(() => expect(saveXMLMock).toHaveBeenCalled());
|
||||||
|
await waitFor(() => expect(screen.getByTestId('process-modeler-publish-confirm')).toBeInTheDocument());
|
||||||
|
await waitFor(() => expect(mImpact).toHaveBeenCalledWith('MD-7'));
|
||||||
|
// 确认发布 → deployModel(MD-7) → 成功后弹窗关闭
|
||||||
|
fireEvent.click(screen.getByTestId('publish-confirm-btn'));
|
||||||
|
await waitFor(() => expect(mDeploy).toHaveBeenCalledWith('MD-7'));
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(screen.queryByTestId('process-modeler-publish-confirm')).not.toBeInTheDocument(),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
type ModelSummary,
|
type ModelSummary,
|
||||||
} from '../api/processModeler';
|
} from '../api/processModeler';
|
||||||
import { Eip4Panel, type PanelModeler } from '../modeler/Eip4Panel';
|
import { Eip4Panel, type PanelModeler } from '../modeler/Eip4Panel';
|
||||||
|
import { PublishConfirm } from '../modeler/PublishConfirm';
|
||||||
import { toast } from '../components/ui';
|
import { toast } from '../components/ui';
|
||||||
|
|
||||||
// bpmn-js/lib/Modeler 自带类型,但选项对象里的标准面板模块(本项目无类型)与 moddle JSON
|
// bpmn-js/lib/Modeler 自带类型,但选项对象里的标准面板模块(本项目无类型)与 moddle JSON
|
||||||
@@ -77,10 +78,14 @@ export function ProcessModelerPage() {
|
|||||||
const modelIdRef = useRef<string>('');
|
const modelIdRef = useRef<string>('');
|
||||||
// 当前载入流程的 key(存量 procDefKey / 草稿 key)——新建草稿的 name/key 源。
|
// 当前载入流程的 key(存量 procDefKey / 草稿 key)——新建草稿的 name/key 源。
|
||||||
const loadedKeyRef = useRef<string>('');
|
const loadedKeyRef = useRef<string>('');
|
||||||
|
// 打开时的源 XML(发布影响摘要的 diff 基线:openSource vs 当前 saveXML)。
|
||||||
|
const openSourceRef = useRef<string>('');
|
||||||
|
|
||||||
const [loadState, setLoadState] = useState<LoadState>('idle');
|
const [loadState, setLoadState] = useState<LoadState>('idle');
|
||||||
const [loadError, setLoadError] = useState('');
|
const [loadError, setLoadError] = useState('');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
// 发布弹窗:非 null 时展示 PublishConfirm,xml=点发布瞬间的 saveXML 结果。
|
||||||
|
const [publish, setPublish] = useState<{ xml: string } | null>(null);
|
||||||
const [options, setOptions] = useState<ProcessOption[]>([]);
|
const [options, setOptions] = useState<ProcessOption[]>([]);
|
||||||
const [optionsError, setOptionsError] = useState('');
|
const [optionsError, setOptionsError] = useState('');
|
||||||
// 打开器 tab:存量流程 / 草稿。
|
// 打开器 tab:存量流程 / 草稿。
|
||||||
@@ -169,6 +174,7 @@ export function ProcessModelerPage() {
|
|||||||
}
|
}
|
||||||
idMapRef.current = src.idMap ?? {};
|
idMapRef.current = src.idMap ?? {};
|
||||||
loadedKeyRef.current = src.key ?? '';
|
loadedKeyRef.current = src.key ?? '';
|
||||||
|
openSourceRef.current = src.bpmnXml; // diff 基线(此处 bpmnXml 已由上方 found 守卫保证非空)
|
||||||
// 草稿路:记住 modelId(后续保存走 PUT);存量路:清空(首次保存新建草稿)。
|
// 草稿路:记住 modelId(后续保存走 PUT);存量路:清空(首次保存新建草稿)。
|
||||||
modelIdRef.current = modelIdParam || '';
|
modelIdRef.current = modelIdParam || '';
|
||||||
await modeler.importXML(src.bpmnXml);
|
await modeler.importXML(src.bpmnXml);
|
||||||
@@ -243,6 +249,22 @@ export function ProcessModelerPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发布:需先有草稿(modelId)——未存则提示先存;已存则取当前 saveXML 开同人确认弹窗。
|
||||||
|
async function handlePublishClick() {
|
||||||
|
const modeler = modelerRef.current;
|
||||||
|
if (!modeler || saving) return;
|
||||||
|
if (!modelIdRef.current) {
|
||||||
|
toast('请先保存草稿,再发布', 'warn');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const { xml } = await modeler.saveXML({ format: true });
|
||||||
|
setPublish({ xml });
|
||||||
|
} catch {
|
||||||
|
toast('读取流程内容失败', 'err');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
return <div style={{ padding: 24, color: 'var(--text-3)' }}>流程设计器仅管理员可用。</div>;
|
return <div style={{ padding: 24, color: 'var(--text-3)' }}>流程设计器仅管理员可用。</div>;
|
||||||
}
|
}
|
||||||
@@ -313,7 +335,13 @@ export function ProcessModelerPage() {
|
|||||||
>
|
>
|
||||||
{saving ? '保存中…' : '保存草稿'}
|
{saving ? '保存中…' : '保存草稿'}
|
||||||
</button>
|
</button>
|
||||||
<button className="btn btn-sm btn-primary" data-testid="process-modeler-publish" disabled title="发布(下阶段)">
|
<button
|
||||||
|
className="btn btn-sm btn-primary"
|
||||||
|
data-testid="process-modeler-publish"
|
||||||
|
disabled={!modelerReady || saving}
|
||||||
|
onClick={handlePublishClick}
|
||||||
|
title="发布(同人确认 + 影响摘要)"
|
||||||
|
>
|
||||||
发布
|
发布
|
||||||
</button>
|
</button>
|
||||||
<button className="btn btn-sm" data-testid="process-modeler-back" onClick={() => navigate('/design-center')}>
|
<button className="btn btn-sm" data-testid="process-modeler-back" onClick={() => navigate('/design-center')}>
|
||||||
@@ -464,6 +492,18 @@ export function ProcessModelerPage() {
|
|||||||
<div ref={panelRef} data-testid="process-modeler-props" style={{ flex: 1, overflow: 'auto', minHeight: 0 }} />
|
<div ref={panelRef} data-testid="process-modeler-props" style={{ flex: 1, overflow: 'auto', minHeight: 0 }} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 同人确认发布弹窗(影响摘要 + 节点级 diff + 422 校验清单) */}
|
||||||
|
{publish && modelIdRef.current ? (
|
||||||
|
<PublishConfirm
|
||||||
|
modelId={modelIdRef.current}
|
||||||
|
openSourceXml={openSourceRef.current}
|
||||||
|
currentXml={publish.xml}
|
||||||
|
processKeyHint={loadedKeyRef.current}
|
||||||
|
onClose={() => setPublish(null)}
|
||||||
|
onPublished={() => setPublish(null)}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user