Skip to content

feat(plugin-form): Auto-layout for ObjectForm — smart columns, colSpan, create-mode filtering#613

Merged
hotlong merged 3 commits intomainfrom
copilot/optimize-default-layout
Feb 19, 2026
Merged

feat(plugin-form): Auto-layout for ObjectForm — smart columns, colSpan, create-mode filtering#613
hotlong merged 3 commits intomainfrom
copilot/optimize-default-layout

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 19, 2026

ObjectForm's default layout renders all fields in a single flat column regardless of count or type, producing unnecessarily long forms for typical business objects.

Auto-layout engine (autoLayout.ts)

Pure utility functions applied as a fallback when no explicit layout config is provided:

  • Column inference — ≤3 fields → 1 col, ≥4 fields → 2 cols
  • Wide field colSpantextarea, markdown, html, grid, rich-text auto-span full row
  • Create-mode filteringformula, summary, auto_number fields hidden (server-computed, not user-editable)
  • User priority — explicit columns, colSpan, or sections in schema are never overridden

Integration

4-line integration in SimpleObjectForm before FormSchema construction. Skipped entirely when sections are configured.

const autoLayoutResult = !hasSections
  ? applyAutoLayout(formFields, objectSchema, schema.columns, schema.mode)
  : { fields: formFields, columns: schema.columns };

Tests

26 unit tests covering all utility functions, edge cases (empty fields, user overrides, create-mode filtering affecting column inference), and immutability guarantees.

Original prompt

This section details on the original issue you should resolve

<issue_title>平台级优化:元数据驱动表单默认布局与字段自动分��/列分布(Auto-Layout for ObjectForm)</issue_title>
<issue_description>## 背景
ObjectUI 平台的 ObjectForm(元数据驱动表单控件)目前的默认策略是:

  • 如果 schema 未指定 columns/sections,自动生成所有字段,全部采用 1 列平铺(单列长表单)。
  • 无论对象字段多少、类型如何,体验都不够理想。例如常见业务对象(如 Task、Contact、Order)创建时字段多,平铺易导致滚动过长、重要区块混杂、占用空间严重。

优化目标

平台层面为所有对象表单提供更智能、零配置的默认布局(Auto-Layout)体验。 让调用方无需繁琐配置,也可获得:

  • 自动推断最优 columns(如字段多时用 2 列,少时用 1 列)
  • 字段类型驱动智能 colSpan(textarea、markdown、grid 等宽字段自动占满行,其余半行)
  • 支持宽/窄字段分组、可选/必填分组等自动 section
  • Create 模式下自动过滤公式、只读字段等
  • 用户配置优先级最高,平台逻辑仅作为兜底

参考实现思路

  1. columns 自动推断
    • 字段 <= 3:单列;字段 >= 4 且无宽字段:2 列;字段 >= 8 可扩展到 3~4 列(可调)。
    • 发现 textarea、markdown、grid 字段自动 colSpan = columns。
  2. section 智能分组(可选)
    • 必填字段与可选/布尔宽度字段分开,textarea/备注类字段独立。
  3. Create 模式过滤
    • 自动隐藏 formula、summary、auto_number 等只读/自动生成字段,简化界面。
  4. 保底可被覆盖
    • 若 schema 明确设置 columns、colSpan、sections,平台应完全尊重,不做推断。

期望收益

  • 即插即用:各对象无需"手动定制表单"即可获得优雅表单布局
  • 一致性 & 体验提升:平台所有对象表单(无论业务/插件/自定义)都具备合理空间利用和分组、可读性显著提升
  • 改动最小、收益极高:底层增强,不影响 API,老项目零迁移风险

建议参考位置

packages/plugin-form/src/ObjectForm.tsx 的 SimpleObjectForm 内部(formFields → FormSchema 前)


相关资料


⚠️ 每次开发/调整记得运行 test,并同步相关问题和 roadmap。</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 19, 2026

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

Project Deployment Actions Updated (UTC)
objectui Ready Ready Preview, Comment Feb 19, 2026 6:04am
objectui-demo Ready Ready Preview, Comment Feb 19, 2026 6:04am
objectui-storybook Ready Ready Preview, Comment Feb 19, 2026 6:04am

Request Review

Copilot AI and others added 2 commits February 19, 2026 05:51
… colSpan, and create-mode filtering

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve default layout for ObjectForm with auto-layout feat(plugin-form): Auto-layout for ObjectForm — smart columns, colSpan, create-mode filtering Feb 19, 2026
Copilot AI requested a review from hotlong February 19, 2026 05:57
@hotlong hotlong marked this pull request as ready for review February 19, 2026 06:01
Copilot AI review requested due to automatic review settings February 19, 2026 06:01
@hotlong hotlong merged commit 560a7a0 into main Feb 19, 2026
5 of 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

This PR implements an auto-layout engine for ObjectForm that provides intelligent, zero-configuration default layouts for metadata-driven forms. The feature addresses a longstanding UX issue where all forms rendered as single-column layouts regardless of field count or type, resulting in unnecessarily long forms.

Changes:

  • New autoLayout.ts module with pure utility functions for column inference (≤3 fields → 1 col, ≥4 → 2 cols), auto colSpan for wide fields, and create-mode filtering of auto-generated fields
  • Integration in ObjectForm.tsx with 4-line implementation that applies auto-layout as a fallback when no explicit layout is configured
  • Comprehensive unit tests (26 tests) covering all utility functions, edge cases, and immutability guarantees
  • ROADMAP updates documenting the completed auto-layout features

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/plugin-form/src/autoLayout.ts New auto-layout engine with utility functions for intelligent form layout inference
packages/plugin-form/src/__tests__/autoLayout.test.ts Comprehensive unit tests (26 tests) covering all auto-layout functionality
packages/plugin-form/src/ObjectForm.tsx Integration of auto-layout logic into SimpleObjectForm component
packages/plugin-form/src/index.tsx Exports auto-layout utility functions as part of public API
pnpm-lock.yaml Lockfile regeneration with hotcrm submodule packages included
ROADMAP.md Documentation of completed auto-layout features
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment on lines +579 to +583
// Apply auto-layout: infer columns and colSpan when not explicitly configured
const hasSections = schema.sections?.length;
const autoLayoutResult = !hasSections
? applyAutoLayout(formFields, objectSchema, schema.columns, schema.mode)
: { fields: formFields, columns: schema.columns };
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

Auto-layout (including create-mode filtering of formula/summary/auto_number fields and auto colSpan for wide fields) is completely skipped when sections are defined. This creates inconsistent behavior: forms without sections get intelligent auto-generated field filtering in create mode, but forms with sections do not. Consider applying at least the filterCreateModeFields logic before the sections check to ensure consistent behavior across all form variants.

Copilot uses AI. Check for mistakes.
*/
export function filterCreateModeFields(
fields: FormField[],
objectSchema: any
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The objectSchema parameter is typed as any, which defeats TypeScript's type safety. Consider creating a proper interface or type for the object schema structure. At minimum, it should define the expected shape with a fields property that is a record of field definitions with a type property.

Copilot uses AI. Check for mistakes.
export function applyAutoLayout(
formFields: FormField[],
objectSchema: any,
schemaColumns: number | undefined,
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The objectSchema parameter is typed as any, which defeats TypeScript's type safety. Consider creating a proper interface or type for the object schema structure. At minimum, it should define the expected shape with a fields property that is a record of field definitions with a type property.

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +24
export {
applyAutoLayout,
inferColumns,
isWideFieldType,
isAutoGeneratedFieldType,
applyAutoColSpan,
filterCreateModeFields,
} from './autoLayout';
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

According to Rule #2 (Documentation Driven Development) in the coding guidelines, for EVERY feature implemented or refactored, you MUST update the corresponding documentation including the package README.md and content/docs/guide/*.md files. The auto-layout feature is a significant platform-level enhancement but is not documented in packages/plugin-form/README.md or the guide documentation. Users need to know about this zero-config default behavior, when it activates, and how to override it.

Copilot generated this review using guidance from repository custom instructions.
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.

平台级优化:元数据驱动表单默认布局与字段自动分��/列分布(Auto-Layout for ObjectForm)

3 participants