Skip to content

feat(plugin-dashboard): ObjectDataTable columns support string[] shorthand#1103

Merged
hotlong merged 3 commits intomainfrom
copilot/fix-columns-normalization
Mar 21, 2026
Merged

feat(plugin-dashboard): ObjectDataTable columns support string[] shorthand#1103
hotlong merged 3 commits intomainfrom
copilot/fix-columns-normalization

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 21, 2026

ObjectDataTable crashes when columns is a string[] (e.g. ['name', 'amount']) because derivedColumns passes strings straight through to the data-table renderer, which accesses col.accessorKey on a plain string → undefined.

Changes

  • normalizeColumns helper in ObjectDataTable.tsx — maps each string entry to { header, accessorKey }, passes objects through unchanged. Handles per-element normalization so mixed arrays work too.
  • Header derivation — snake_case (close_dateClose Date) and camelCase (firstNameFirst Name) both title-cased correctly.
  • 8 unit tests for normalizeColumns, 2 integration tests for the component with string columns.

Usage

// Before: only object[] worked
columns: [
  { header: 'Name', accessorKey: 'name' },
  { header: 'Close Date', accessorKey: 'close_date' },
]

// Now: string[] shorthand also works
columns: ['name', 'close_date']

// Mixed is fine too
columns: ['name', { header: 'Amount ($)', accessorKey: 'amount' }]
Original prompt

This section details on the original issue you should resolve

<issue_title>ObjectDataTable: columns 应兼容 string[] 简写格式,自动 normalize 为对象数组</issue_title>
<issue_description># 渲染兼容建议:table columns 支持字符串简写格式

目前 ObjectUI 的 ObjectDataTable 在解析 columns 字段时,直接透传了 schema.columns,没有对字符串数组 such as ['name', 'amount'] 做转换,导致当业务 schema 采用字符串简写时,下游渲染器会因为访问 undefined (col.accessorKey) 而崩溃。

但根据 @objectstack/spec 协议,Widget.options 是 z.unknown(),业务层 columns 配置为 string[] 本应属于合法且更简洁、国际化友好的写法(header 可自动推导,多语言 UI 可基于 accessorKey + i18n 自动实现)。

建议修复

在 ObjectDataTable 中,对 columns 做 normalize,兼容 string[] 和对象数组:

const normalizeColumns = (columns) => {
  if (!columns || columns.length === 0) return [];
  if (typeof columns[0] === 'string') {
    return columns.map((field) => ({
      header: field.charAt(0).toUpperCase() + field.slice(1).replace(/_/g, ' '),
      accessorKey: field,
    }));
  }
  return columns;
};

这样即��无缝支持业务 schema 更简洁的 columns 字段,同时兼容国际化和完整对象写法。

参考

建议

  • columns 支持 string[]/object[] 双语法,提升易用性和兼容性
  • 推荐在文档中增加关于 columns 用法的说明示例
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectui-demo Ready Ready Preview, Comment Mar 21, 2026 7:59am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
objectui Ignored Ignored Mar 21, 2026 7:59am
objectui-storybook Ignored Ignored Mar 21, 2026 7:59am

Request Review

ObjectDataTable now supports both string[] shorthand and object[] formats
for column configuration. String entries like 'close_date' are auto-converted
to { header: 'Close Date', accessorKey: 'close_date' }. Handles snake_case,
camelCase, and mixed arrays. Fixes #303.

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/de8fa9da-2f3d-4641-b43f-330b65eee7db
Copilot AI changed the title [WIP] Fix ObjectDataTable to normalize columns from string array feat(plugin-dashboard): ObjectDataTable columns support string[] shorthand Mar 21, 2026
Copilot AI requested a review from hotlong March 21, 2026 08:01
@hotlong hotlong marked this pull request as ready for review March 21, 2026 08:08
Copilot AI review requested due to automatic review settings March 21, 2026 08:08
@hotlong hotlong merged commit d7253fc into main Mar 21, 2026
6 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds string[] shorthand support for ObjectDataTable columns by normalizing entries into { header, accessorKey } objects, preventing downstream data-table crashes and improving header generation.

Changes:

  • Introduced normalizeColumns() to convert string column keys into full column defs (supports mixed string | object arrays).
  • Updated ObjectDataTable to pass normalized columns to the data-table renderer.
  • Added unit tests for normalizeColumns plus component-level regression tests, and documented the feature in the changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/plugin-dashboard/src/ObjectDataTable.tsx Normalizes schema.columns so string[] shorthand doesn’t crash downstream renderers.
packages/plugin-dashboard/src/tests/ObjectDataTable.test.tsx Adds regression coverage for string[] columns and direct tests for normalization behavior.
CHANGELOG.md Documents the new string[] shorthand support for ObjectDataTable columns.
Comments suppressed due to low confidence (1)

packages/plugin-dashboard/src/ObjectDataTable.tsx:143

  • The auto-derived column headers (when schema.columns is empty) still don't normalize snake_case keys (e.g. close_date becomes Close_date) and use a different casing algorithm than normalizeColumns. Consider reusing normalizeColumns for the auto-derive path (e.g. by passing keys through it) to keep header derivation consistent and avoid duplicated formatting logic.
    }
    if (finalData.length === 0) return [];
    // Exclude internal/private fields (prefixed with '_') from auto-derived columns
    const keys = Object.keys(finalData[0]).filter(k => !k.startsWith('_'));
    // Convert camelCase keys to human-readable headers (e.g. firstName → First Name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ObjectDataTable: columns 应兼容 string[] 简写格式,自动 normalize 为对象数组

3 participants