Merge branch 'feat/ui-empty-list-fix' into main
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
生成页 5 个 UI/UE 缺陷(dogfooding 实测):①空列表红横幅 ②子表<空>占位 ④主子表编辑 子行不回显 ⑤主子表LIST列泄漏成JSON ⑥树加子预填父名。481单测+逐个浏览器复验。
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);
|
||||
@@ -159,6 +163,8 @@ public final class PageBlueprintCompiler {
|
||||
table.put("removable", true);
|
||||
table.put("needConfirm", false);
|
||||
table.put("staticOn", "${__readonly}");
|
||||
// 空态友好占位:未设时 amis 对空 input-table 渲染字面量「<空>」(像占位符泄漏)。
|
||||
table.put("placeholder", "暂无明细,点下方「新增」添加");
|
||||
ArrayNode columns = table.putArray("columns");
|
||||
String childPk = child.childTable() + "_ID";
|
||||
// 联动目标子列集合:这些列要挂 id=<col>_${index} 供 setValue componentId 命中(id 挂列上已验证可用)。
|
||||
@@ -660,8 +666,14 @@ public final class PageBlueprintCompiler {
|
||||
form.put("type", "form");
|
||||
form.put("api", "post:/api/flow/" + blueprint.tableName() + "_ADD");
|
||||
form.put("reload", crudName);
|
||||
// 加子表单从行级按钮打开,会继承父行作用域 → 业务字段(如名称)按 name 自动回填父行值
|
||||
// (实测:加子时「名称」预填了父节点名,要先清空才能输入)。故:
|
||||
// ① 表单数据域只播 PARENTID=父节点主键(从父行作用域求值),业务字段不在其中→空白起步;
|
||||
// ② canAccessSuperData:false 关掉按 name 自动从父作用域取值。两者合力让加子表单干净。
|
||||
form.put("canAccessSuperData", false);
|
||||
form.putObject("data").put("PARENTID", "${" + blueprint.primaryKey() + "}");
|
||||
ArrayNode controls = objectMapper.createArrayNode();
|
||||
controls.add(hidden("PARENTID", "${" + blueprint.primaryKey() + "}"));
|
||||
controls.add(hidden("PARENTID", "${PARENTID}"));
|
||||
controls.addAll(formControlsExcluding(blueprint, false, "PARENTID"));
|
||||
form.set("body", controls);
|
||||
}
|
||||
|
||||
@@ -942,9 +942,21 @@ public class FlowController {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object unwrapCrudResult(Object data) {
|
||||
if (data instanceof Map<?, ?> m && m.size() == 1 && m.get("result") instanceof Map<?, ?> r
|
||||
&& r.containsKey("items") && r.containsKey("total")) {
|
||||
return r;
|
||||
if (data instanceof Map<?, ?> m && m.size() == 1 && m.get("result") instanceof Map<?, ?> r) {
|
||||
// 已归一为 crud 形态 {items,total} → 拍平到 data 顶层(amis crud 契约 data.items/data.total)
|
||||
if (r.containsKey("items") && r.containsKey("total")) {
|
||||
return r;
|
||||
}
|
||||
// 空搜索结果集:引擎对净新实体合成 _SEARCH 零行返 {result:{}}(空 map,无 listresult/pagecount),
|
||||
// normalize 的空列表特判(认 LIST_RESULT/PAGE_COUNT)不触发 → 此处兜底拍平为空列表,否则 amis crud
|
||||
// 找不到 items 数组,每个 0 行列表页弹「data.items 必须是数组」红横幅。仅当内层为空 map 才兜:
|
||||
// 单记录 _LOAD 的 result 含字段(非空),不受影响。
|
||||
if (r.isEmpty()) {
|
||||
Map<String, Object> emptyList = new LinkedHashMap<>();
|
||||
emptyList.put("items", new ArrayList<>());
|
||||
emptyList.put("total", 0);
|
||||
return emptyList;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -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,证明必须显式排除而非靠类型识别");
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,14 @@ class PageBlueprintCompilerTest {
|
||||
crud.path("columns").get(2).path("buttons").get(2).path("api").path("url").asText());
|
||||
assertEquals("${EIP4AI_CATEGORY_ID}",
|
||||
crud.path("columns").get(2).path("buttons").get(2).path("api").path("data").path("ids").asText());
|
||||
|
||||
// 加子表单作用域隔离:数据域只播 PARENTID=父主键(从父行求值)+ 关 canAccessSuperData,
|
||||
// 否则业务字段(名称)按 name 自动回填父节点值,加子时要先清空才能输入(浏览器实测 bug)。
|
||||
var addChildForm = crud.path("columns").get(2).path("buttons").get(0).path("dialog").path("body");
|
||||
assertEquals("${EIP4AI_CATEGORY_ID}", addChildForm.path("data").path("PARENTID").asText(),
|
||||
"加子表单数据域只播 PARENTID=父主键");
|
||||
assertFalse(addChildForm.path("canAccessSuperData").asBoolean(true),
|
||||
"加子表单须关 canAccessSuperData 防名称预填父节点值");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -242,6 +250,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());
|
||||
|
||||
@@ -433,6 +433,50 @@ class FlowControllerTest {
|
||||
assertEquals(0, data.get("total"), "pagecount=0 → total=0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("5d. 空搜索返 {result:{}}(空 map,连 pagecount 都无)→ 兜底 {items:[],total:0}"
|
||||
+ "(净新主子表合成 _SEARCH 零行实测形态;否则 amis crud 报「data.items 必须是数组」红横幅)")
|
||||
void normalizeEmptyResultObject() {
|
||||
// 5b 覆盖 {result:{pagecount:0}}(有 pagecount);但净新实体合成 _SEARCH 零行实测返
|
||||
// {result:{}}(空 map,连 pagecount 都没有)→ normalize 的空列表特判(认 LIST_RESULT/PAGE_COUNT)
|
||||
// 不触发 → data 停留 {result:{}} → amis crud 找不到 items 数组 → 每个 0 行列表页弹红横幅。
|
||||
String flowId = "EIP4PT_LKM_SEARCH";
|
||||
Map<String, Object> output = new LinkedHashMap<>();
|
||||
output.put("result", new LinkedHashMap<>()); // {result:{}} 空 map
|
||||
|
||||
FlowExcuteService engine = mock(FlowExcuteService.class);
|
||||
when(engine.excute(any(), any(), any())).thenReturn(output);
|
||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, uuidPassthrough()));
|
||||
|
||||
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||
assertInstanceOf(List.class, data.get("items"), "空 {result:{}} 也须兜出 items 数组");
|
||||
assertEquals(0, ((List<?>) data.get("items")).size(), "空结果 items 为空数组");
|
||||
assertEquals(0, data.get("total"), "空结果 total=0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("5e. 单记录 load 返 {result:{字段...}}(非空)→ 保持 result 形态不被空列表兜底误伤")
|
||||
@SuppressWarnings("unchecked")
|
||||
void nonEmptyResultStaysAsRecord() {
|
||||
String flowId = "SYS_X_LOAD";
|
||||
Map<String, Object> record = new LinkedHashMap<>();
|
||||
record.put("TITLE", "标题");
|
||||
Map<String, Object> output = new LinkedHashMap<>();
|
||||
output.put("result", record);
|
||||
|
||||
FlowExcuteService engine = mock(FlowExcuteService.class);
|
||||
when(engine.excute(any(), any(), any())).thenReturn(output);
|
||||
FlowController controller = new FlowController(engine, resolverReturning(flowId, namedHit()));
|
||||
|
||||
ResponseEntity<Map<String, Object>> resp = controller.executeGet(flowId, new HashMap<>());
|
||||
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||
Map<String, Object> loaded = (Map<String, Object>) data.get("result");
|
||||
assertNotNull(loaded, "非空单记录仍走 result 形态(不被空列表兜底改写)");
|
||||
assertEquals("标题", loaded.get("TITLE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("5c. 引擎执行抛异常(如视图缺失)→ 优雅 status:1 而非裸 500")
|
||||
void engineExceptionGraceful() {
|
||||
|
||||
Reference in New Issue
Block a user