Skip to content

fix: UI protocol design defects — widget id, action type unification, conditional validation, naming consistency#806

Merged
hotlong merged 5 commits intomainfrom
copilot/fix-ui-protocol-design-issues
Feb 24, 2026
Merged

fix: UI protocol design defects — widget id, action type unification, conditional validation, naming consistency#806
hotlong merged 5 commits intomainfrom
copilot/fix-ui-protocol-design-issues

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

Addresses multiple UI protocol design issues: naming conflicts, missing referenceability, inconsistent action types, absent conditional validation, and misplaced shared schemas.

Schema changes

  • DashboardWidgetSchema — Add required id: SnakeCaseIdentifierSchema so GlobalFilterSchema.targetWidgets can actually reference widgets
  • WidgetActionTypeSchema — Add script and api to match ActionSchema.type (was missing 2 of 5 types)
  • PageSchema — Add .superRefine() enforcing recordReview when type is record_review, blankLayout when type is blank
  • AnimationSchema (theme.zod) — Rename timing keys to snake_case: easeInease_in, easeOutease_out, easeInOutease_in_out
  • TransitionConfigSchema — Add optional themeToken for theme animation token binding
  • ListViewSchema — Add responsive and performance fields (already present on Dashboard/Component, was missing here)
  • HttpMethodSchema/HttpRequestSchema — Move canonical definition to shared/http.zod.ts, re-export from view.zod.ts
  • Theme enums — Rename to ThemeModeSchema/DensityModeSchema/WcagContrastLevelSchema; old names kept as deprecated aliases

Example: conditional page validation

// Now fails validation — recordReview is required for record_review pages
PageSchema.parse({
  name: 'review_page',
  type: 'record_review',
  regions: [],
}); // ✗ ZodError: recordReview is required when type is "record_review"

// Passes with config provided
PageSchema.parse({
  name: 'review_page',
  type: 'record_review',
  regions: [],
  recordReview: { object: 'order', actions: [{ label: 'Approve', type: 'approve' }] },
}); // ✓

Tests

32 new tests added covering all new behaviors. All existing tests updated for schema changes. 6507 tests pass.

Original prompt

This section details on the original issue you should resolve

<issue_title>UI 协议设计缺陷与重复规范合并修正提案</issue_title>
<issue_description>## 问题概述

在全面审查了 packages/spec/src/ui 目录下的主要 UI 协议(包括 page、component、dashboard、theme、widget、action、animation 等 19 个核心 schema 文件)后,发现存在命名冲突、概念重复、部分 schema 设计不一致、条件校验缺失及部分通用 schema 存放位置不合理的问题,具体如下:


2. DashboardWidget 无唯一 id,导致 targetWidgets 无法引用

  • DashboardWidgetSchema 添加必选 idname 字段(建议使用 SnakeCaseIdentifierSchema)。
  • 相关全局过滤器等 schema 引用需联动修改。

3. Action/WidgetActionType/ActionSchema.type 重复并不一致

  • 统一所有 action 类型来源,dashboard、view、component 相关 action 类型都应引用 ActionSchema。
  • WidgetActionType 增加缺失的 scriptapi 类型,或直接完全复用 ActionSchema.type。
  • 把 dashboard header action 等 schema 的结构调整为 ActionRef + inline。

5. PageType 设计与条件校验

  • PageTypeSchema 枚举类型过多,部分 type 与 ListView 类型重叠。
  • 建议用 discriminatedUnion 或 .superRefine 实现 PageSchema 的类型/字段依赖条件校验(如 record_review 类型下 recordReview 必填等)。

6. Animation 设计重复、命名不统一

  • theme.zod 与 animation.zod 分别定义动画 token 与运行时配置,easing 命名风格不一致(camelCase 与 snake_case)。
  • 统一 easing 命名风格为 snake_case。
  • animation.zod 支持使用 theme token。

7. 各 schema 的 responsive/performance 配置统一化

  • ListView、Component、Dashboard 等应支持统一的 ResponsiveConfigSchema,确保 UI 适配逻辑一致。

8. 共享协议放置位置

  • HttpMethodSchema、HttpRequestSchema 等协议建议迁移到 shared/data 模块,避免耦合 view 层定义。

9. 其他一致性/命名问题

  • theme.zod.ts 内 type/value 命名建议统一为 ThemeModeSchema、DensityModeSchema 等,避免 TS 类型与 const 冲突。

</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

vercel bot commented Feb 24, 2026

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

Project Deployment Actions Updated (UTC)
objectstack-play Error Error Feb 24, 2026 9:51am
spec Error Error Feb 24, 2026 9:51am

Request Review

Copilot AI and others added 2 commits February 24, 2026 09:37
Update dashboard.test.ts to reflect the new required 'id' field
(SnakeCaseIdentifierSchema) added to DashboardWidgetSchema.

- Add meaningful snake_case id to every widget object in tests
- Update WidgetActionTypeSchema tests: 'script' and 'api' are now valid types
- Remove outdated assertion that 'script' should be rejected

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…onditional validation, easing naming, migrate HTTP schemas, rename theme enums, add responsive to ListView

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
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] Fix UI protocol design flaws and merge duplicate specs fix: UI protocol design defects — widget id, action type unification, conditional validation, naming consistency Feb 24, 2026
Copilot AI requested a review from hotlong February 24, 2026 09:54
@hotlong hotlong marked this pull request as ready for review February 24, 2026 09:59
Copilot AI review requested due to automatic review settings February 24, 2026 09:59
@hotlong hotlong merged commit f1ed882 into main Feb 24, 2026
2 of 4 checks passed
Copy link
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 fixes multiple UI protocol design defects identified in issue #805, including missing widget IDs, inconsistent action types, absent conditional validation, and naming inconsistencies. The changes ensure protocol consistency, improve referenceability, and align with the project's naming conventions (snake_case for data values, camelCase for configuration keys).

Changes:

  • Added required id field to DashboardWidgetSchema for targetWidgets referencing in global filters
  • Unified WidgetActionTypeSchema with ActionSchema.type by adding missing script and api types
  • Added .superRefine() conditional validation to PageSchema for type-specific required fields
  • Renamed animation timing keys in AnimationSchema to snake_case (ease_in, ease_out, ease_in_out)
  • Added themeToken reference support to TransitionConfigSchema for theme animation token binding
  • Added responsive and performance fields to ListViewSchema for consistency with other UI components
  • Migrated HttpMethodSchema/HttpRequestSchema from view.zod.ts to shared/http.zod.ts with backward-compatible re-exports
  • Renamed theme enums to ThemeModeSchema/DensityModeSchema/WcagContrastLevelSchema with deprecated aliases

Reviewed changes

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

Show a summary per file
File Description
packages/spec/src/ui/dashboard.zod.ts Added required id field to DashboardWidgetSchema, added script and api to WidgetActionTypeSchema
packages/spec/src/ui/dashboard.test.ts Updated all 100+ widget test fixtures with id field, added 27 new tests for widget id and action type changes
packages/spec/src/ui/page.zod.ts Added superRefine conditional validation for record_review and blank page types
packages/spec/src/ui/page.test.ts Updated 5 existing tests and added 6 new tests for conditional validation
packages/spec/src/ui/theme.zod.ts Renamed timing keys to snake_case, renamed enums to *Schema suffix with deprecated aliases
packages/spec/src/ui/theme.test.ts Updated timing key references, added 3 new test suites for naming changes
packages/spec/src/ui/view.zod.ts Replaced HttpMethod/Request definitions with imports from shared, added responsive/performance fields to ListView
packages/spec/src/ui/view.test.ts Added 2 new test suites for responsive/performance and backward compatibility
packages/spec/src/ui/animation.zod.ts Added themeToken field to TransitionConfigSchema
packages/spec/src/ui/animation.test.ts Added test suite for themeToken support
packages/spec/src/shared/http.zod.ts Added HttpMethodSchema and HttpRequestSchema migrated from view.zod
packages/spec/src/shared/http.test.ts Added 2 test suites for migrated HTTP schemas
packages/spec/src/stack.test.ts Updated 3 widget fixtures with required id field
ROADMAP.md Updated last modified date and added 8 completed tasks documenting all schema changes

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.

UI 协议设计缺陷与重复规范合并修正提案

3 participants