I1+I2 联锁修(同一根因:预览/diff 的两侧要对齐"打开时原始源"与"实际部署内容"):
- I1:新增 baselineTargetRef,openSourceRef 只在首次打开某目标时捕获原始源;存量首存
setParams(modelId) 触发的 reload 因归属已预置为新 modelId 而保留基线,不再被冲成「已存版」
→「打开存量→改办理人→存→发布」的 diff 恢复非空。
- I2:handlePublishClick 在开确认弹窗前先 saveDraft(currentXml) 持久化编辑器态,使
后端 deploy 读到的服务端草稿 == 预览 == diff 的 current 侧(草稿改未存直接发布不再预览≠部署)。
Minor:
- M1:diffSummary 比 content 前做全角【】↔半角{} normWidth 归一(含 RAW 兜底路径),防宽度变体误报。
- M2:completionBody 折叠全部空白后比较,防 bpmn-js 重排空白误报完成条件变更。
- M3:PublishConfirm 发布中 guardedClose 拦截遮罩/X 关闭。
I3 测试:diffSummary 跨命名空间(默认 ns 源 vs bpmn: 前缀当前)对齐命中/前缀不误报 + M1 宽度变体;
页面 I1 锁(存量 save→publish 后 diff 基线仍原始源→清单非空,已 red-check 证伪防呆)+ I2(发布前 saveDraft)。
diffSummary 16 + PublishConfirm 9 + 页面 22;全量 227 单测绿,tsc -b rc=0 + build 干净。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
189 lines
7.1 KiB
TypeScript
189 lines
7.1 KiB
TypeScript
// 同人确认发布弹窗(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);
|
||
}
|
||
}
|
||
|
||
// M3:发布进行中拦截关闭(遮罩点击 / X 按钮),避免中途关窗留下不确定态。
|
||
const guardedClose = () => {
|
||
if (!deploying) onClose();
|
||
};
|
||
|
||
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={guardedClose} 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={guardedClose} 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>
|
||
);
|
||
}
|