fix(ui): 主子表编辑态两个 dogfooding 真 bug(子行不回显 + LIST 列泄漏成 JSON 文本框)
实际走完 CRUD 闭环(新增→保存→编辑)揪出,纯功能 e2e 测不到:
1. 编辑态子表子行全空(若保存会丢子行):编辑表单 initApi=_LOAD 返
{data:{result:{TITLE,DETAILS:[子行]}}},但表单字段期望顶层名 → 子表
input-table(name=DETAILS)绑不上 result 内子行数组。主字段"看似"回显仅因选中行
铺进了对话框作用域(非 _LOAD 生效)。修:PageBlueprintCompiler 编辑表单 initApi 加
responseData {"&":"${result}"} 把 result 拆到表单数据顶层。
2. 主子表发布后再 compile,主表单冒出一个显原始 JSON 数组的"明细"文本框 + 列表列 +
查询条件:主子表链接给主实体加了 DETAILS(LIST)列,而 refToApiType("LIST") 因
长度<32 落 default→"string",被当普通字段渲染。修:EntityAttributesService 排除
引擎内部列 LIST/BLOB/STATUS(非可建模标量列,与 appendColumnDdl 跳过集一致),
从源头不进属性表→表单/列表/查询/建模器字段表都干净。
验证:platform-metadata 481 单测 0 失败(PageBlueprintCompilerTest 编辑表单 responseData
断言 + EntityAttributesServiceTest LIST/BLOB/STATUS 不可建模 3 测);重启 8094+重生成页+
浏览器编辑实测:子行 钢筋/3/10/30 正确回显、无 JSON 文本框、列表/查询只剩 标题。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -64,6 +64,13 @@ public class EntityAttributesService {
|
||||
for (Map<String, Object> r : raw) {
|
||||
String col = (String) r.get("COLUMNNAME");
|
||||
String refId = (String) r.get("REFERENCEID");
|
||||
// 引擎内部列(LIST=子表集合 / BLOB=大对象 / STATUS=流程状态)非可建模标量列,
|
||||
// 不进可建模属性表——否则建模器把它当字段、recipe 把它渲成表单/列表/查询控件
|
||||
// (LIST 经 refToApiType 误落 "string"→编辑表单渲成文本框显子行 JSON 数组,实测 bug)。
|
||||
// 与 MetaController.appendColumnDdl 的跳过集一致(这些列本就无物理 DDL 列)。
|
||||
if (!isModelableColumn(refId)) {
|
||||
continue;
|
||||
}
|
||||
boolean isKey = asInt(r.get("ISKEY")) == 1;
|
||||
boolean isEntityDisplay = asInt(r.get("ISENTITYDISPLAY")) == 1;
|
||||
boolean mandatory = asInt(r.get("ISMANDATORY")) == 1;
|
||||
@@ -88,6 +95,14 @@ public class EntityAttributesService {
|
||||
return new Result(t, displayColumn, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 该列是否「可建模标量列」。引擎内部列 LIST(子表集合) / BLOB(大对象) / STATUS(流程状态)
|
||||
* 非用户可填的标量字段,排除出可建模属性表(与 {@code MetaController.appendColumnDdl} 跳过集一致)。
|
||||
*/
|
||||
public static boolean isModelableColumn(String referenceId) {
|
||||
return !("LIST".equals(referenceId) || "BLOB".equals(referenceId) || "STATUS".equals(referenceId));
|
||||
}
|
||||
|
||||
/** REFERENCEID 反映射成 API 语义类型;36 位 uuid(外键引用) → reference。 */
|
||||
public static String refToApiType(String referenceId) {
|
||||
if (referenceId == null) {
|
||||
|
||||
@@ -130,12 +130,16 @@ public final class PageBlueprintCompiler {
|
||||
editForm.put("type", "form");
|
||||
editForm.put("api", masterDetailFormApi(blueprint, "_UPDATE"));
|
||||
editForm.put("reload", crudName);
|
||||
// 经 _LOAD 回显主+子行(data.result.<listColumn>=子行,已实测)。
|
||||
// 经 _LOAD 回显主+子行。_LOAD 返 {data:{result:{TITLE, <listColumn>:[子行]}}},
|
||||
// 而表单字段(TITLE/子表)期望顶层名 → 必须 responseData {"&":"${result}"} 把 result 拆到表单数据顶层,
|
||||
// 否则子表(input-table name=<listColumn>)绑不上 result 内的子行数组 → 编辑态子行全空(浏览器实测 bug;
|
||||
// 主字段曾"看似"回显仅因选中行铺进了对话框作用域,非 _LOAD 生效)。
|
||||
ObjectNode initApi = editForm.putObject("initApi");
|
||||
initApi.put("method", "post");
|
||||
initApi.put("url", "/api/flow/" + blueprint.tableName() + "_LOAD");
|
||||
initApi.putObject("data").put(blueprint.primaryKey(),
|
||||
"${" + blueprint.primaryKey() + "}");
|
||||
initApi.putObject("responseData").put("&", "${result}");
|
||||
// 选中行铺进对话框作用域,主键经 initApi 拉 _LOAD(主+子)。
|
||||
dialog.putObject("data").put("&", "${selectedItems[0]}");
|
||||
ArrayNode editControls = masterDetailFormControls(blueprint);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.eip4.platform.metadata.meta;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 可建模属性的纯静态判定单测。重点:引擎内部列 LIST/BLOB/STATUS 不可建模——
|
||||
* 否则主子表主实体的 DETAILS(LIST) 列会泄漏成表单文本框(显子行 JSON 数组)/列表列/查询条件(浏览器实测 bug)。
|
||||
*/
|
||||
class EntityAttributesServiceTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("LIST/BLOB/STATUS 引擎内部列不可建模(排除出属性表)")
|
||||
void internalColumnsNotModelable() {
|
||||
assertFalse(EntityAttributesService.isModelableColumn("LIST"), "子表集合列");
|
||||
assertFalse(EntityAttributesService.isModelableColumn("BLOB"), "大对象列");
|
||||
assertFalse(EntityAttributesService.isModelableColumn("STATUS"), "流程状态列");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("普通标量/引用列可建模")
|
||||
void scalarAndReferenceColumnsModelable() {
|
||||
assertTrue(EntityAttributesService.isModelableColumn("NVARCHAR"));
|
||||
assertTrue(EntityAttributesService.isModelableColumn("INTEGER"));
|
||||
assertTrue(EntityAttributesService.isModelableColumn("DECIMAL"));
|
||||
assertTrue(EntityAttributesService.isModelableColumn("BOOLEAN"));
|
||||
assertTrue(EntityAttributesService.isModelableColumn("CHAR"));
|
||||
assertTrue(EntityAttributesService.isModelableColumn(null), "无 refId 缺省按可建模(refToApiType 兜 string)");
|
||||
assertTrue(EntityAttributesService.isModelableColumn("11111111-1111-1111-1111-111111111111"),
|
||||
"36 位 uuid 外键引用列可建模");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("LIST 经 refToApiType 会误落 string(故须在 isModelableColumn 这层拦,不能靠类型映射)")
|
||||
void listMisTypedAsStringJustifiesExplicitExclusion() {
|
||||
assertEquals("string", EntityAttributesService.refToApiType("LIST"),
|
||||
"LIST 长度<32 落 default→string,证明必须显式排除而非靠类型识别");
|
||||
}
|
||||
}
|
||||
@@ -242,6 +242,10 @@ class PageBlueprintCompilerTest {
|
||||
assertEquals("/api/flow/EIP4AI_PURCHASE_LOAD", editForm.path("initApi").path("url").asText());
|
||||
assertEquals("${EIP4AI_PURCHASE_ID}",
|
||||
editForm.path("initApi").path("data").path("EIP4AI_PURCHASE_ID").asText());
|
||||
// _LOAD 返回 {data:{result:{TITLE, DETAILS:[...]}}};表单字段(TITLE/DETAILS)期望顶层名,
|
||||
// 故 initApi 必须 responseData 拆 result 到顶层,否则子表 DETAILS 绑不上→编辑态子行全空(实测 bug)。
|
||||
assertEquals("${result}", editForm.path("initApi").path("responseData").path("&").asText(),
|
||||
"编辑表单 initApi 须 responseData {\"&\":\"${result}\"} 拆 _LOAD 的 result 嵌套,子表才回显");
|
||||
ArrayNode editBody = (ArrayNode) editForm.path("body");
|
||||
ObjectNode editChild = findByType(editBody, "input-table");
|
||||
assertEquals("DETAILS", editChild.path("name").asText());
|
||||
|
||||
Reference in New Issue
Block a user