Skip to content

[Bug] 详情页相关子表未从元数据生成列定义,导致表格内容为空 #996

@hotlong

Description

@hotlong

问题描述

在详情页面(任何业务对象),"相关"tab 下的子表仅显示标题、记录数和搜索框,表格内容(行和列)完全为空。该问题是平台级 bug,影响所有通过元数据驱动的相关列表。

image1 image2

根因分析

整条数据流链路中,没有任何一层利用 dataSource.getObjectSchema() 获取子对象的字段元数据来生成 columns:

  1. RecordDetailView 构建 related 时只传了 titletypedata没有传 columns 也没有传子对象名称(api
  2. DetailView 原样透传给 RelatedList,不做 columns 补全。
  3. RelatedList 生成 viewSchemacolumns fallback 到 [],SchemaRenderer 收到空列配置,不渲染任何内容。
RecordDetailView                    DetailView                        RelatedList
related = [{                   →    <RelatedList                  →   viewSchema = {
  title: 'Order Item',               data={related.data}               type: 'data-table',
  type: 'table',                     columns={undefined}               data: [...],
  data: [7条记录]                     api={undefined}                   columns: [] ← 空!
}]                                  />                                }

对比主流平台做法

平台 策略
Salesforce 读取子对象的 Object Metadata + Page Layout,自动生成列(label、type、顺序)
Retool 绑定查询后自动检查返回数据的 key 生成列
Appsmith 类似 Retool,表格绑定数据后自动推断列定义

ObjectUI 作为元数据驱动平台,应走 Salesforce 路线:利用已有的 dataSource.getObjectSchema(childObjectName) 获取子对象字段定义来生成 columns。

平台其他组件(ObjectGridObjectAgGridObjectMap)都已正确使用该方法,RelatedList 是唯一缺失的。

建议修复方案

RelatedList 组件内自动获取元数据(推荐)

RelatedList 中,当 api(objectName)和 dataSource 存在但 columns 为空时,调用 dataSource.getObjectSchema(api) 获取子对象字段定义,自动生成 columns:

// RelatedList.tsx — 新增 objectSchema 获取逻辑
const [objectSchema, setObjectSchema] = React.useState<any>(null);

React.useEffect(() => {
  if (api && dataSource?.getObjectSchema && (!columns || columns.length === 0)) {
    dataSource.getObjectSchema(api).then(setObjectSchema).catch(() => {});
  }
}, [api, dataSource, columns]);

// 从 objectSchema 生成 columns
const effectiveColumns = React.useMemo(() => {
  if (columns && columns.length > 0) return columns;
  if (!objectSchema?.fields) return [];
  return Object.entries(objectSchema.fields)
    .filter(([key]) => !key.startsWith('_'))
    .map(([key, def]: [string, any]) => ({
      accessorKey: key,
      header: def.label || key,
    }));
}, [columns, objectSchema]);

影响范围

平台级 bug,所有通过元数据驱动生成的相关子表均受影响。修复后需全面测试各类业务对象详情页。

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions