fix: sidebar code icon reset bug (#9307) (#9333)

* fix: 修复侧边栏重置时 Code 图标消失的问题 (#9307)

问题原因:
- types/index.ts 中的 SidebarIcon 类型定义缺少 'code_tools'
- 存在重复的类型定义和常量定义导致不一致

修复内容:
- 在 types/index.ts 的 SidebarIcon 类型中添加 'code_tools'
- 删除 minapps.ts 中重复的 DEFAULT_SIDEBAR_ICONS 常量
- 统一从 @renderer/types 导入 SidebarIcon 类型
- 删除 settings.ts 中重复的 SidebarIcon 类型定义

这确保了在导航栏设置为左侧时,点击侧边栏设置的重置按钮后,
Code 图标能够正确显示。

* refactor: 将侧边栏配置移至 config 目录

根据 code review 建议,将侧边栏相关配置从 store/settings.ts
移动到 config/sidebar.ts,使配置管理更加清晰。

改动内容:
- 创建 config/sidebar.ts 存放侧边栏配置常量
- 更新相关文件的导入路径
- 在 settings.ts 中重新导出以保持向后兼容
- 添加 REQUIRED_SIDEBAR_ICONS 常量便于未来扩展

这个改动保持了最小化原则,不影响现有功能。
This commit is contained in:
Jason Young 2025-08-21 00:49:42 +08:00 committed by GitHub
parent 8297546ed7
commit 27eef50b9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 33 additions and 36 deletions

View File

@ -0,0 +1,23 @@
import { SidebarIcon } from '@renderer/types'
/**
*
*
*/
export const DEFAULT_SIDEBAR_ICONS: SidebarIcon[] = [
'assistants',
'agents',
'paintings',
'translate',
'minapp',
'knowledge',
'files',
'code_tools'
]
/**
*
*
* 便
*/
export const REQUIRED_SIDEBAR_ICONS: SidebarIcon[] = ['assistants']

View File

@ -3,13 +3,13 @@ import { ResetIcon } from '@renderer/components/Icons'
import { HStack } from '@renderer/components/Layout'
import TextBadge from '@renderer/components/TextBadge'
import { isMac, THEME_COLOR_PRESETS } from '@renderer/config/constant'
import { DEFAULT_SIDEBAR_ICONS } from '@renderer/config/sidebar'
import { useTheme } from '@renderer/context/ThemeProvider'
import { useNavbarPosition, useSettings } from '@renderer/hooks/useSettings'
import useUserTheme from '@renderer/hooks/useUserTheme'
import { useAppDispatch } from '@renderer/store'
import {
AssistantIconType,
DEFAULT_SIDEBAR_ICONS,
setAssistantIconType,
setClickAssistantToShowTopic,
setCustomCss,

View File

@ -10,14 +10,13 @@ import {
import { getSidebarIconLabel } from '@renderer/i18n/label'
import { useAppDispatch } from '@renderer/store'
import { setSidebarIcons } from '@renderer/store/settings'
import { SidebarIcon } from '@renderer/types'
import { message } from 'antd'
import { Code, FileSearch, Folder, Languages, LayoutGrid, MessageSquareQuote, Palette, Sparkle } from 'lucide-react'
import { FC, useCallback, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import styled from 'styled-components'
import { SidebarIcon } from '../../../store/settings'
interface SidebarIconsManagerProps {
visibleIcons: SidebarIcon[]
disabledIcons: SidebarIcon[]

View File

@ -4,6 +4,7 @@ import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE, isMac } from '@renderer/conf
import { DEFAULT_MIN_APPS } from '@renderer/config/minapps'
import { isFunctionCallingModel, isNotSupportedTextDelta, SYSTEM_MODELS } from '@renderer/config/models'
import { TRANSLATE_PROMPT } from '@renderer/config/prompts'
import { DEFAULT_SIDEBAR_ICONS } from '@renderer/config/sidebar'
import {
isSupportArrayContentProvider,
isSupportDeveloperRoleProvider,
@ -32,7 +33,7 @@ import { DEFAULT_TOOL_ORDER } from './inputTools'
import { initialState as llmInitialState, moveProvider } from './llm'
import { mcpSlice } from './mcp'
import { defaultActionItems } from './selectionStore'
import { DEFAULT_SIDEBAR_ICONS, initialState as settingsInitialState } from './settings'
import { initialState as settingsInitialState } from './settings'
import { initialState as shortcutsInitialState } from './shortcuts'
import { defaultWebSearchProviders } from './websearch'

View File

@ -1,16 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { DEFAULT_MIN_APPS } from '@renderer/config/minapps'
import { MinAppType, SidebarIcon } from '@renderer/types'
export const DEFAULT_SIDEBAR_ICONS: SidebarIcon[] = [
'assistants',
'agents',
'paintings',
'translate',
'minapp',
'knowledge',
'files'
]
import { MinAppType } from '@renderer/types'
export interface MinAppsState {
enabled: MinAppType[]

View File

@ -1,5 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { TRANSLATE_PROMPT } from '@renderer/config/prompts'
import { DEFAULT_SIDEBAR_ICONS } from '@renderer/config/sidebar'
import {
ApiServerConfig,
AssistantsSortType,
@ -10,6 +11,7 @@ import {
OpenAISummaryText,
PaintingProvider,
S3Config,
SidebarIcon,
ThemeMode,
TranslateLanguageCode
} from '@renderer/types'
@ -21,26 +23,8 @@ import { RemoteSyncState } from './backup'
export type SendMessageShortcut = 'Enter' | 'Shift+Enter' | 'Ctrl+Enter' | 'Command+Enter' | 'Alt+Enter'
export type SidebarIcon =
| 'assistants'
| 'agents'
| 'paintings'
| 'translate'
| 'minapp'
| 'knowledge'
| 'files'
| 'code_tools'
export const DEFAULT_SIDEBAR_ICONS: SidebarIcon[] = [
'assistants',
'agents',
'paintings',
'translate',
'minapp',
'knowledge',
'files',
'code_tools'
]
// Re-export for backward compatibility
export { DEFAULT_SIDEBAR_ICONS }
export interface NutstoreSyncRuntime extends RemoteSyncState {}

View File

@ -692,7 +692,7 @@ export const isAutoDetectionMethod = (method: string): method is AutoDetectionMe
return Object.hasOwn(AutoDetectionMethods, method)
}
export type SidebarIcon = 'assistants' | 'agents' | 'paintings' | 'translate' | 'minapp' | 'knowledge' | 'files'
export type SidebarIcon = 'assistants' | 'agents' | 'paintings' | 'translate' | 'minapp' | 'knowledge' | 'files' | 'code_tools'
export type ExternalToolResult = {
mcpTools?: MCPTool[]