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:
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user