Feat: 新增 DropdownMenu 组件#58
Merged
Merged
Conversation
- 新增DropdownMenu组件,支持滚动、选中指示与自定义渲染 - 使技能选择区使用DropdownMenu替代手写列表,统一样式与行为 - 模型选择区同样改用DropdownMenu组件,简化代码 - 添加DropdownMenu相关类型定义和滚动窗口计算函数 - 优化PromptInput中颜色和显示逻辑,提升一致性和可读性 - 修正session模块中fs.readdirSync调用的变量初始化问题
- 在模型配置变更时生成系统角色消息,包含模型设置详情 - 将模型变更消息添加至消息列表,支持消息追踪 - 在消息视图中新增模型变更消息渲染逻辑,展示模型名称和推理强度 - 调整用户消息视图布局,优化水平排列和间距 - 修改提示输入组件下拉菜单最大可见项数为6,提升视觉体验 - 扩展SessionMessage类型,支持模型变更相关元信息 - 新增单元测试覆盖DropdownMenu的可见起始项计算逻辑
- 新增 addSessionSystemMessage 方法,用于统一添加系统消息 - 优化 App.tsx 中模型切换逻辑,调用 sessionManager 添加系统消息 - 保持无活动会话时依旧能将消息追加到本地消息列表 - 重构消息创建流程,抽取 meta 和 content 变量提高代码清晰度 - 确保系统消息包含准确的时间戳及元数据配置
# Conflicts: # src/ui/App.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 概述
本次 PR 引入了通用的
DropdownMenu组件,重构了技能和模型选择列表的实现,同时增强了会话系统消息支持和 UI 显示优化。主要变更
DropdownMenu组件,支持滚动、自定义渲染/model命令的系统消息记录功能calculateVisibleStart函数的完整单元测试(17 个测试用例)🎯 变更详情
1. 新增通用 DropdownMenu 组件
文件:
src/ui/DropdownMenu.tsx(新建)核心特性
DropdownMenuItem[]数组,而非硬编码的 JSXrenderItemprop 支持完全自定义渲染React.memo和useMemo避免不必要的重渲染关键函数
计算滚动窗口的起始位置,确保活跃项居中显示(当空间允许时)。
Props 接口
2. 重构 Skills 和 Model 选择菜单
文件:
src/ui/PromptInput.tsx变更前
Skills 和 Model 菜单各自独立实现,存在大量重复代码:
变更后
统一使用
DropdownMenu组件:优势:
3. 增强
/model命令的系统消息支持文件:
src/ui/App.tsx,src/session.ts功能
当用户执行
/model命令切换模型时,会在聊天历史中添加一条系统消息:实现细节
新增
addSessionSystemMessage方法 (src/session.ts)MessageMeta 扩展
UI 显示优化 (
src/ui/MessageView.tsx)marginLeft={2})(normal effort),(high effort), 等4. 修复会话切换后欢迎页不显示的问题
文件:
src/ui/App.tsx问题
执行
/resume切换会话后,欢迎页和历史记录都不显示。根本原因
<Static>组件使用增量渲染机制,切换会话时不会重新挂载,导致:解决方案
使用
key机制强制<Static>重新挂载:优势:
5. 新增单元测试
文件:
src/tests/dropdownMenu.test.ts(新建)为
calculateVisibleStart函数编写了 17 个测试用例,覆盖:测试场景
测试结果
🧪 测试验证
自动化测试
手动测试清单
/skills命令 - Skills 下拉菜单正常显示和滚动/model命令 - Model 下拉菜单正常显示和滚动/model命令 - 切换后聊天历史中出现系统消息/resume命令 - 切换会话后欢迎页正确显示/resume命令 - 切换会话后历史记录正确加载🎨 UI/UX 改进
下拉菜单统一风格
borderStyle="round")… 3 above,… 5 more)#229ac3)🚀 性能优化
DropdownMenu组件使用 memo 包装,避免不必要的重渲染labelColumnWidth计算使用 memo 优化<Static>的增量渲染优势,仅在必要时重新挂载✅ PR 检查清单
npm run typecheck)npm run lint)npm run format:check)npm test- 184 tests)npm run build- 293.1kb)