fix(modeler): 侧板评审收口——会签保真读回/切换节点回归测试/meta可见性+清除确认
I-1 会签保真:isSequential/elementVariable/completionCondition 原值读进 CosignState、 写回用读到的值(真实库 isSequential=true×2 / elementVariable=assign|loop_assign / 完成条件 >0.6×7 原强写会静默改坏派任);完成条件 body 不匹配预设→「自定义(保留)」态,仅主动选预设才 改写;elementVariable 缺省态与原本无 completionCondition 写回时省略,不凭空写空。parseCompletion 改精确匹配预设串(修 >0.55 误判过半的子串 bug)。新增串行开关+循环变量输入。 I-2 双节点回归:A(meta X)→B(meta Y)→编辑 B→写回 meta===Y≠X,防串台。 I-3 meta 可见性:顶部只读徽标显示非空业务 meta(如任务后置服务 PM_XXX);删光 items 且含非空 业务 meta 时 window.confirm 确认才写 undefined(取消则本地态与引擎均不变)。 顺手:扩展属性强制 activiti:/flowable: 前缀 + 拉黑有专用控件的键(candidateUsers/formKey/ collection/elementVariable);非标准办理人表达式(parse→null)显示「编辑将覆盖」警示;订阅 commandStack.changed,非自身写入时对当前选中重灌本地态(undo/redo 脱同步防线)。 测试 Eip4Panel 21→33;全量 vitest 186 绿 / tsc -b 干净 / npm run build 成功。仅动自己文件。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
// EIP4 定制侧板:选中 userTask 时叠加办理人/会签/formKey/扩展属性/任务监听器五控件。
|
||||
//
|
||||
// 设计要点(计划 T2.4 + §0.5 P5):
|
||||
// - 全部写操作经 bpmn-js `modeling.updateProperties(element, {...})`,undo/redo 天然生效。
|
||||
// 设计要点(计划 T2.4 + §0.5 P5 + 评审收口):
|
||||
// - 全部写操作经 bpmn-js `modeling.updateProperties(element,{...})`,undo/redo 天然生效。
|
||||
// - 办理人/会签共用 items 编辑器(ItemsEditor),表达式编解码走 candidateExpression codec。
|
||||
// - 🔴 meta 透传硬要求:codec parse 出的外层业务字段(taskSuccessService 等)存入 ref,
|
||||
// 写回时原样带回 build,否则重新部署会打掉已部署流程的任务后置服务钩子。
|
||||
// - 扩展属性只列长尾 $attrs(已声明属性如 formKey/candidateUsers 不进 $attrs,故不重复)。
|
||||
// - 🔴 meta 透传硬要求:codec parse 出的外层业务字段(taskSuccessService 等)存入 state,
|
||||
// 写回时原样带回 build,否则重新部署会打掉已部署流程的任务后置服务钩子。顶部只读徽标显示,
|
||||
// 删光 items 时 confirm 确认才写 undefined(评审 I-3)。
|
||||
// - 🔴 会签保真(评审 I-1):isSequential/elementVariable/completionCondition 原始值读进 state、
|
||||
// 写回用读到的值(真实库有 isSequential=true / elementVariable=assign / 完成条件 >0.6 等
|
||||
// 非预设形态,强写会静默改坏派任);完成条件 body 不匹配预设时置「自定义(保留)」态,
|
||||
// 仅用户主动选预设才改写。
|
||||
// - 扩展属性只列长尾 $attrs;新增强制 activiti:/flowable: 前缀并拉黑有专用控件的键。
|
||||
// - taskListener 重建时原样保留其 field 子元素(moddle 元素引用不动)。
|
||||
// - 原生标准属性面板照旧显示于本侧板下方,本控件顶部灰字提示以本控件为准。
|
||||
// - undo/redo:订阅 commandStack.changed,非自身写入时对当前选中重灌本地态。
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
buildCandidateExpression,
|
||||
@@ -16,6 +21,7 @@ import {
|
||||
type UserPropertyItem,
|
||||
} from './candidateExpression';
|
||||
import { fetchWfTemplates, type WfTemplateOption } from '../api/processModeler';
|
||||
import { toast } from '../components/ui';
|
||||
import type { BpmnElement, SelectionModeler } from './useSelectedElement';
|
||||
import { useSelectedElement } from './useSelectedElement';
|
||||
|
||||
@@ -46,22 +52,31 @@ const CANDIDATE_TYPES: Array<{ value: string; label: string }> = [
|
||||
|
||||
const LISTENER_EVENTS = ['create', 'assignment', 'complete', 'all'];
|
||||
|
||||
// 有专用控件的属性,禁止再从「扩展属性」兜底编辑器写入(去重、防冲突)。
|
||||
const RESERVED_EXT_LOCALNAMES = new Set(['candidateUsers', 'formKey', 'collection', 'elementVariable']);
|
||||
|
||||
// ── 会签完成条件预设 ─────────────────────────────────────────────────────────
|
||||
type CompletionType = 'all' | 'majority' | 'count';
|
||||
type CompletionType = 'all' | 'majority' | 'count' | 'custom';
|
||||
const COMPLETION_ALL = '${nrOfCompletedInstances/nrOfInstances==1}';
|
||||
const COMPLETION_MAJORITY = '${nrOfCompletedInstances/nrOfInstances>0.5}';
|
||||
|
||||
function completionBody(type: CompletionType, n: number): string {
|
||||
if (type === 'majority') return COMPLETION_MAJORITY;
|
||||
if (type === 'count') return '${nrOfCompletedInstances>=' + n + '}';
|
||||
function completionBodyFor(s: CosignState): string {
|
||||
if (s.completionType === 'majority') return COMPLETION_MAJORITY;
|
||||
if (s.completionType === 'count') return '${nrOfCompletedInstances>=' + s.completionN + '}';
|
||||
if (s.completionType === 'custom') return s.completionCustomBody;
|
||||
return COMPLETION_ALL;
|
||||
}
|
||||
function parseCompletion(body: string | undefined): { type: CompletionType; n: number } {
|
||||
if (!body) return { type: 'all', n: 2 };
|
||||
if (body.indexOf('>0.5') >= 0) return { type: 'majority', n: 2 };
|
||||
const m = body.match(/nrOfCompletedInstances>=(\d+)/);
|
||||
if (m) return { type: 'count', n: Number(m[1]) };
|
||||
return { type: 'all', n: 2 };
|
||||
// 精确匹配预设串(不用子串,否则 >0.55 会误判为过半);非预设/无 body → 自定义(保留)。
|
||||
function parseCompletion(body: string | undefined): {
|
||||
type: CompletionType;
|
||||
n: number;
|
||||
custom: string;
|
||||
} {
|
||||
if (body === COMPLETION_ALL) return { type: 'all', n: 2, custom: '' };
|
||||
if (body === COMPLETION_MAJORITY) return { type: 'majority', n: 2, custom: '' };
|
||||
const m = body ? body.match(/^\$\{nrOfCompletedInstances>=(\d+)\}$/) : null;
|
||||
if (m) return { type: 'count', n: Number(m[1]), custom: '' };
|
||||
return { type: 'custom', n: 2, custom: body ?? '' };
|
||||
}
|
||||
|
||||
// ── moddle 读值(兼容 .get(name) 与直读属性) ──────────────────────────────────
|
||||
@@ -72,6 +87,18 @@ function mget(obj: unknown, name: string): unknown {
|
||||
return o[name];
|
||||
}
|
||||
|
||||
// 非空业务 meta → 只读徽标/确认文案(用于「删光办理人会一并移除 X」)。
|
||||
function notableMeta(meta: Record<string, unknown>): string[] {
|
||||
const out: string[] = [];
|
||||
if (typeof meta.taskSuccessService === 'string' && meta.taskSuccessService)
|
||||
out.push('任务后置服务:' + meta.taskSuccessService);
|
||||
if (typeof meta.messageTemplate === 'string' && meta.messageTemplate) out.push('消息模板');
|
||||
if (meta.isSkipInitiator === true) out.push('跳过发起人');
|
||||
if (meta.isNoUserSkip === true) out.push('无办理人自动跳过');
|
||||
if (meta.isSkipBeforeTask === true) out.push('跳过前置任务办理人');
|
||||
return out;
|
||||
}
|
||||
|
||||
function newCandidateItem(): UserPropertyItem {
|
||||
return {
|
||||
type: 'user',
|
||||
@@ -94,10 +121,26 @@ interface ListenerRow {
|
||||
interface CosignState {
|
||||
enabled: boolean;
|
||||
items: UserPropertyItem[];
|
||||
/** 保真:串行/并行,读回原值(真实库有 isSequential=true)。 */
|
||||
isSequential: boolean;
|
||||
/** 保真:循环变量名,读回原值(真实库有 assign/loop_assign/缺省);为空则写回时省略该属性。 */
|
||||
elementVariable: string;
|
||||
completionType: CompletionType;
|
||||
completionN: number;
|
||||
/** completionType==='custom' 时保留的原始 body;'' 表示原本无 completionCondition。 */
|
||||
completionCustomBody: string;
|
||||
}
|
||||
|
||||
const FRESH_COSIGN: CosignState = {
|
||||
enabled: false,
|
||||
items: [],
|
||||
isSequential: false,
|
||||
elementVariable: 'assignee',
|
||||
completionType: 'all',
|
||||
completionN: 2,
|
||||
completionCustomBody: '',
|
||||
};
|
||||
|
||||
// ── items 编辑器(办理人 / 会签人员复用) ──────────────────────────────────────
|
||||
function ItemsEditor({
|
||||
idPrefix,
|
||||
@@ -219,25 +262,24 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
|
||||
const isUserTask = element?.type === 'bpmn:UserTask';
|
||||
|
||||
// ── 本地编辑态(选中变更时从 businessObject 重新初始化) ──────────────────────
|
||||
// ── 本地编辑态(选中变更 / undo-redo 时从 businessObject 重新初始化) ─────────
|
||||
const [candidateItems, setCandidateItems] = useState<UserPropertyItem[]>([]);
|
||||
const [cosign, setCosign] = useState<CosignState>({
|
||||
enabled: false,
|
||||
items: [],
|
||||
completionType: 'all',
|
||||
completionN: 2,
|
||||
});
|
||||
const [candidateMeta, setCandidateMeta] = useState<Record<string, unknown>>({});
|
||||
const [candidateNonStandard, setCandidateNonStandard] = useState(false);
|
||||
const [cosign, setCosign] = useState<CosignState>(FRESH_COSIGN);
|
||||
const [cosignMeta, setCosignMeta] = useState<Record<string, unknown>>({});
|
||||
const [formKey, setFormKey] = useState('');
|
||||
const [extAttrs, setExtAttrs] = useState<Array<{ key: string; value: string }>>([]);
|
||||
const [newAttr, setNewAttr] = useState<{ key: string; value: string }>({ key: '', value: '' });
|
||||
const [listeners, setListeners] = useState<ListenerRow[]>([]);
|
||||
const [templates, setTemplates] = useState<WfTemplateOption[]>([]);
|
||||
// undo/redo 重灌计数:commandStack.changed(非自身写入)时自增,触发 init 重跑。
|
||||
const [syncTick, setSyncTick] = useState(0);
|
||||
|
||||
// meta 透传:codec parse 出的外层业务字段,写回时原样带回(不进 UI 渲染,只存 ref)。
|
||||
const candidateMetaRef = useRef<Record<string, unknown>>({});
|
||||
const cosignMetaRef = useRef<Record<string, unknown>>({});
|
||||
// 非 taskListener 的扩展元素(formProperty 等)原样保留(引用不动)。
|
||||
const otherExtRef = useRef<unknown[]>([]);
|
||||
// 自身写入标记:updateProperties 会触发 commandStack.changed,借此跳过自触发重灌。
|
||||
const selfWriteRef = useRef(false);
|
||||
|
||||
// formKey 数据源加载一次。
|
||||
useEffect(() => {
|
||||
@@ -250,42 +292,66 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 选中变更 → 从 businessObject 重新初始化本地态。
|
||||
// undo/redo 脱同步防线:非自身写入的 commandStack 变更 → 对当前选中重灌本地态。
|
||||
useEffect(() => {
|
||||
if (!modeler) return;
|
||||
const handler = () => {
|
||||
if (selfWriteRef.current) {
|
||||
selfWriteRef.current = false; // 自身 updateProperties 触发,不重灌(避免规范化闪烁)
|
||||
return;
|
||||
}
|
||||
setSyncTick((t) => t + 1);
|
||||
};
|
||||
modeler.on('commandStack.changed', handler);
|
||||
return () => {
|
||||
modeler.off?.('commandStack.changed', handler);
|
||||
};
|
||||
}, [modeler]);
|
||||
|
||||
// 选中变更 / 外部命令 → 从 businessObject 重新初始化本地态。
|
||||
useEffect(() => {
|
||||
if (!element || element.type !== 'bpmn:UserTask') {
|
||||
setCandidateItems([]);
|
||||
setCosign({ enabled: false, items: [], completionType: 'all', completionN: 2 });
|
||||
setCandidateMeta({});
|
||||
setCandidateNonStandard(false);
|
||||
setCosign(FRESH_COSIGN);
|
||||
setCosignMeta({});
|
||||
setFormKey('');
|
||||
setExtAttrs([]);
|
||||
setNewAttr({ key: '', value: '' });
|
||||
setListeners([]);
|
||||
candidateMetaRef.current = {};
|
||||
cosignMetaRef.current = {};
|
||||
otherExtRef.current = [];
|
||||
return;
|
||||
}
|
||||
const bo = element.businessObject;
|
||||
|
||||
// 办理人
|
||||
const cand = parseCandidateExpression(bo.get('activiti:candidateUsers') as string | undefined);
|
||||
const rawCand = bo.get('activiti:candidateUsers') as string | undefined;
|
||||
const cand = parseCandidateExpression(rawCand);
|
||||
setCandidateItems(cand?.items ?? []);
|
||||
candidateMetaRef.current = cand?.meta ?? {};
|
||||
setCandidateMeta(cand?.meta ?? {});
|
||||
setCandidateNonStandard(!!rawCand && !cand); // 非空但解析失败=非标准表达式
|
||||
|
||||
// 会签
|
||||
// 会签(保真读回 isSequential/elementVariable/completionCondition 原值)
|
||||
const loop = bo.get('loopCharacteristics');
|
||||
if (loop) {
|
||||
const parsed = parseCandidateExpression(mget(loop, 'activiti:collection') as string | undefined);
|
||||
const cc = parseCompletion((mget(loop, 'completionCondition') as { body?: string } | undefined)?.body);
|
||||
const cc = parseCompletion(
|
||||
(mget(loop, 'completionCondition') as { body?: string } | undefined)?.body,
|
||||
);
|
||||
setCosign({
|
||||
enabled: true,
|
||||
items: parsed?.items ?? [],
|
||||
isSequential: Boolean(mget(loop, 'isSequential')),
|
||||
elementVariable: (mget(loop, 'activiti:elementVariable') as string) ?? '',
|
||||
completionType: cc.type,
|
||||
completionN: cc.n,
|
||||
completionCustomBody: cc.custom,
|
||||
});
|
||||
cosignMetaRef.current = parsed?.meta ?? {};
|
||||
setCosignMeta(parsed?.meta ?? {});
|
||||
} else {
|
||||
setCosign({ enabled: false, items: [], completionType: 'all', completionN: 2 });
|
||||
cosignMetaRef.current = {};
|
||||
setCosign(FRESH_COSIGN);
|
||||
setCosignMeta({});
|
||||
}
|
||||
|
||||
// formKey
|
||||
@@ -319,22 +385,33 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
} as ListenerRow;
|
||||
}),
|
||||
);
|
||||
}, [element]);
|
||||
}, [element, syncTick]);
|
||||
|
||||
function update(props: Record<string, unknown>) {
|
||||
if (element && modeling) modeling.updateProperties(element, props);
|
||||
if (element && modeling) {
|
||||
selfWriteRef.current = true;
|
||||
modeling.updateProperties(element, props);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 办理人写回 ─────────────────────────────────────────────────────────────
|
||||
function writeCandidate(items: UserPropertyItem[]) {
|
||||
setCandidateItems(items);
|
||||
if (items.length === 0) {
|
||||
// 删光 items:若外层含非空业务 meta,confirm 确认才写 undefined(否则连带清除业务字段)。
|
||||
const notable = notableMeta(candidateMeta);
|
||||
if (
|
||||
notable.length > 0 &&
|
||||
typeof window !== 'undefined' &&
|
||||
!window.confirm('清空办理人将一并移除:' + notable.join('、') + '。确认清空?')
|
||||
) {
|
||||
return; // 取消:本地态与引擎均不变
|
||||
}
|
||||
setCandidateItems([]);
|
||||
update({ 'activiti:candidateUsers': undefined });
|
||||
return;
|
||||
}
|
||||
update({
|
||||
'activiti:candidateUsers': buildCandidateExpression(items, 'candidate', candidateMetaRef.current),
|
||||
});
|
||||
setCandidateItems(items);
|
||||
update({ 'activiti:candidateUsers': buildCandidateExpression(items, 'candidate', candidateMeta) });
|
||||
}
|
||||
|
||||
// ── 会签写回 ───────────────────────────────────────────────────────────────
|
||||
@@ -348,17 +425,18 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
const collection = buildCandidateExpression(
|
||||
next.items,
|
||||
'multiInstance' as CandidateVariant,
|
||||
cosignMetaRef.current,
|
||||
cosignMeta,
|
||||
);
|
||||
const completionCondition = moddle.create('bpmn:FormalExpression', {
|
||||
body: completionBody(next.completionType, next.completionN),
|
||||
});
|
||||
const loop = moddle.create('bpmn:MultiInstanceLoopCharacteristics', {
|
||||
isSequential: false,
|
||||
const props: Record<string, unknown> = {
|
||||
isSequential: next.isSequential,
|
||||
'activiti:collection': collection,
|
||||
'activiti:elementVariable': 'assignee',
|
||||
completionCondition,
|
||||
});
|
||||
};
|
||||
// elementVariable 为空(真实库缺省态)则省略,不凭空写空属性。
|
||||
if (next.elementVariable) props['activiti:elementVariable'] = next.elementVariable;
|
||||
const body = completionBodyFor(next);
|
||||
// body 为空(原本无 completionCondition)则不发出该子元素,保真。
|
||||
if (body) props.completionCondition = moddle.create('bpmn:FormalExpression', { body });
|
||||
const loop = moddle.create('bpmn:MultiInstanceLoopCharacteristics', props);
|
||||
update({ loopCharacteristics: loop });
|
||||
}
|
||||
|
||||
@@ -372,6 +450,15 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
function addExtAttr() {
|
||||
const key = newAttr.key.trim();
|
||||
if (!key) return;
|
||||
if (!key.startsWith('activiti:') && !key.startsWith('flowable:')) {
|
||||
toast('扩展属性键必须以 activiti: 或 flowable: 开头', 'warn');
|
||||
return;
|
||||
}
|
||||
const local = key.slice(key.indexOf(':') + 1);
|
||||
if (RESERVED_EXT_LOCALNAMES.has(local)) {
|
||||
toast('该属性有专用控件,请用上方对应控件编辑', 'warn');
|
||||
return;
|
||||
}
|
||||
setExtAttrs((prev) => {
|
||||
const rest = prev.filter((a) => a.key !== key);
|
||||
return [...rest, { key, value: newAttr.value }];
|
||||
@@ -428,6 +515,8 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
);
|
||||
}
|
||||
|
||||
const candidateBadges = notableMeta(candidateMeta);
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid="process-modeler-eip4-panel"
|
||||
@@ -438,6 +527,22 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
</div>
|
||||
|
||||
<Section title="办理人">
|
||||
{candidateBadges.length > 0 ? (
|
||||
<div
|
||||
data-testid="eip4-candidate-meta-badge"
|
||||
style={{ fontSize: 12, color: 'var(--text-2)', marginBottom: 8, lineHeight: 1.6 }}
|
||||
>
|
||||
含业务配置:{candidateBadges.join('、')}(清空办理人会一并移除)
|
||||
</div>
|
||||
) : null}
|
||||
{candidateNonStandard ? (
|
||||
<div
|
||||
data-testid="eip4-candidate-nonstandard"
|
||||
style={{ fontSize: 12, color: 'var(--warn, #d48806)', marginBottom: 8 }}
|
||||
>
|
||||
当前为非标准办理人表达式,编辑将覆盖原表达式。
|
||||
</div>
|
||||
) : null}
|
||||
<ItemsEditor idPrefix="eip4-candidate" items={candidateItems} onChange={writeCandidate} />
|
||||
</Section>
|
||||
|
||||
@@ -453,12 +558,31 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
</label>
|
||||
{cosign.enabled ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 13 }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-testid="eip4-cosign-sequential"
|
||||
checked={cosign.isSequential}
|
||||
onChange={(e) => writeCosign({ ...cosign, isSequential: e.target.checked })}
|
||||
/>
|
||||
串行(顺序会签)
|
||||
</label>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 13 }}>
|
||||
<span style={{ flex: '0 0 auto' }}>循环变量</span>
|
||||
<input
|
||||
data-testid="eip4-cosign-element-variable"
|
||||
value={cosign.elementVariable}
|
||||
placeholder="assignee"
|
||||
onChange={(e) => writeCosign({ ...cosign, elementVariable: e.target.value })}
|
||||
style={{ flex: 1, minWidth: 0 }}
|
||||
/>
|
||||
</label>
|
||||
<ItemsEditor
|
||||
idPrefix="eip4-cosign"
|
||||
items={cosign.items}
|
||||
onChange={(items) => writeCosign({ ...cosign, items })}
|
||||
/>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 13 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 13, flexWrap: 'wrap' }}>
|
||||
<span>完成条件</span>
|
||||
<select
|
||||
data-testid="eip4-cosign-completion-type"
|
||||
@@ -467,6 +591,10 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
writeCosign({ ...cosign, completionType: e.target.value as CompletionType })
|
||||
}
|
||||
>
|
||||
{/* 自定义(保留)仅在当前为自定义态时可选中——presets 不提供切到自定义,防误清 */}
|
||||
{cosign.completionType === 'custom' ? (
|
||||
<option value="custom">自定义(保留)</option>
|
||||
) : null}
|
||||
<option value="all">全票通过</option>
|
||||
<option value="majority">过半通过</option>
|
||||
<option value="count">指定数</option>
|
||||
@@ -483,6 +611,14 @@ export function Eip4Panel({ modeler }: { modeler: PanelModeler | null }) {
|
||||
style={{ width: 64 }}
|
||||
/>
|
||||
) : null}
|
||||
{cosign.completionType === 'custom' ? (
|
||||
<span
|
||||
data-testid="eip4-cosign-completion-custom"
|
||||
style={{ fontSize: 12, color: 'var(--text-3)' }}
|
||||
>
|
||||
当前条件:<code>{cosign.completionCustomBody || '(无)'}</code>
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user