Skip to content

Bug: 右侧 ViewConfigPanel 设置开关无法控制左侧列表 toolbar — 数据流断裂全量排查与修复 #719

@hotlong

Description

@hotlong

🐛 问题描述

PR #716 合并后,右侧 ViewConfigPanel 的"启用搜索/启用筛选/启用排序"开关已经关闭(OFF 状态),但左侧列表的 toolbar(Hide fields、Filter、Group、Sort、Color、Comfortable、Search 等控件)仍然全部显示,开关完全无效

image1

🔍 根本原因

数据流存在 两处断裂

断裂点 1:PluginObjectView → renderListView schema 未传递 toolbar 开关

packages/plugin-view/src/ObjectView.tsxrenderListView 回调传给 Console 的 schema 缺少 showSearch/showFilters/showSort

// 当前代码(缺失 ❌)
if (renderListView) {
    return renderListView({
        schema: {
            type: 'list-view',
            objectName: schema.objectName,
            viewType: currentViewType,
            fields: ...,
            filters: mergedFilters,
            sort: mergedSort,
            rowHeight: activeView?.rowHeight,
            densityMode: activeView?.densityMode,
            groupBy: activeView?.groupBy,
            options: ...,
            // ❌ showSearch/showFilters/showSort 未传递!
        },
        ...
    });
}

断裂点 2:ListView toolbar 控件未根据 schema.showSearch/showFilters/showSort 条件渲染

packages/plugin-list/src/ListView.tsx 的 toolbar 渲染区域,Filter/Sort/Search/HideFields/Group/Color/Density 等按钮全部是无条件渲染的,完全没有检查 schema.showSearchschema.showFiltersschema.showSort 等字段来决定是否显示。

即使上游正确传递了 showSearch: false,ListView 自身也不会响应。


✅ 修复清单(逐项对照修改)

1. PluginObjectView — renderListView schema 补齐 toolbar 开关字段

  • renderListView({ schema }) 中添加:showSearch: activeView?.showSearch ?? schema.showSearch
  • renderListView({ schema }) 中添加:showFilters: activeView?.showFilters ?? schema.showFilters
  • renderListView({ schema }) 中添加:showSort: activeView?.showSort ?? schema.showSort
  • 同时补齐 stripedborderedcolor 到 renderListView schema(已部分在 Console fullSchema 补过,但 PluginObjectView 层也要传)

2. ListView — toolbar 控件条件渲染

  • Search 按钮/搜索框:当 schema.showSearch === false 时隐藏
  • Filter 按钮/弹窗:当 schema.showFilters === false 时隐藏
  • Sort 按钮/弹窗:当 schema.showSort === false 时隐藏
  • Hide Fields 按钮:检查是否需要受某个 config 控制(如 schema.showHideFields),如不需要则保持显示
  • Group 按钮:检查是否需要受 schema.showGroup 控制
  • Color 按钮:检查是否需要受 schema.showColor 控制
  • Density/行高 按钮:检查是否需要受 schema.showDensity 控制
  • Export 按钮:确认 schema.exportOptionsschema.allowExport 控制逻辑正确

3. Console ObjectView — renderListView 回调消费验证

  • Console 的 renderListView 构建 fullSchema 时,已有 showSearch: viewDef.showSearch ?? listSchema.showSearch——确认 listSchema 参数确实包含了 PluginObjectView 传来的值
  • 确认 fullSchema 最终传给 <ListView schema={fullSchema} /> 时,ListView 能正确消费

4. 数据流全链路校验

  • ViewConfigPanel onViewUpdate('showSearch', false)setViewDraftactiveView 更新
  • activeViewobjectViewSchema.showSearchPluginObjectView schema.showSearch
  • PluginObjectViewrenderListView({ schema: { showSearch } }) → Console fullSchema.showSearch
  • fullSchema<ListView schema={fullSchema} /> → toolbar Search 按钮隐藏
  • 同理验证 showFiltersshowSort 全链路

5. generateViewSchema(非 grid 视图直渲路径)

  • 对非 grid 类型(kanban/calendar/timeline/gallery/map/gantt),generateViewSchemabaseProps 已包含 showSearch/showSort/showFilters——确认这些值能传递到各子插件组件的 toolbar

6. useMemo 依赖项审查

  • Console objectViewSchema useMemo 的依赖数组包含 activeView?.showSearchactiveView?.showFiltersactiveView?.showSort
  • Plugin gridSchema useMemo 的依赖数组包含 activeView
  • Plugin renderContent 函数的 key 是否包含足够的 deps 以触发 re-render

7. 测试覆盖

  • 为 ListView 添加测试:showSearch: false 时 Search 按钮不渲染
  • 为 ListView 添加测试:showFilters: false 时 Filter 按钮不渲染
  • 为 ListView 添加测试:showSort: false 时 Sort 按钮不渲染
  • 为 PluginObjectView 添加测试:renderListView 回调的 schema 包含 showSearch/showFilters/showSort
  • 为 Console ObjectView 添加集成测试:右侧面板关闭 search/filter/sort → 左侧 toolbar 对应控件消失
  • 修复完成后运行全部 test suite,确认所有测试通过
  • 更新 Roadmap checklist

📂 涉及文件

文件 改动类型
packages/plugin-view/src/ObjectView.tsx renderListView schema 补齐 showSearch/showFilters/showSort
packages/plugin-list/src/ListView.tsx toolbar 控件条件渲染(Search/Filter/Sort/HideFields/Group/Color/Density)
apps/console/src/components/ObjectView.tsx 验证 fullSchema 传递正确性 + useMemo deps 审查
packages/plugin-list/src/__tests__/ListView.test.tsx 新增 toolbar 开关测试
packages/plugin-view/src/__tests__/ObjectView.test.tsx 新增 renderListView schema 传递测试

关联

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions