From ea62294bd83cbbcfb959e0ce457bedc83a657f85 Mon Sep 17 00:00:00 2001 From: icarus Date: Sun, 21 Sep 2025 22:16:15 +0800 Subject: [PATCH] refactor(agent-settings): extract shared components and improve styling - Move common components (AgentLabel, SettingsTitle, SettingsInline) to shared file - Update CSS to use @layer base for better organization - Fix agent type label translation key in AgentModal - Add agent type label utility function --- src/renderer/src/assets/styles/index.css | 14 ++++---- .../components/Popups/agent/AgentModal.tsx | 2 +- src/renderer/src/i18n/label.ts | 16 ++++++++- .../AgentSettings/AgentEssentialSettings.tsx | 17 ++++++---- .../AgentSettings/AgentPromptSettings.tsx | 10 +++--- .../pages/settings/AgentSettings/index.tsx | 13 ++++---- .../pages/settings/AgentSettings/shared.tsx | 33 +++++++++++++++++++ 7 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 src/renderer/src/pages/settings/AgentSettings/shared.tsx diff --git a/src/renderer/src/assets/styles/index.css b/src/renderer/src/assets/styles/index.css index 0c6bee69d2..960d28061d 100644 --- a/src/renderer/src/assets/styles/index.css +++ b/src/renderer/src/assets/styles/index.css @@ -11,12 +11,14 @@ @import '../fonts/ubuntu/ubuntu.css'; @import '../fonts/country-flag-fonts/flag.css'; -*, -*::before, -*::after { - box-sizing: border-box; - /* margin: 0; */ - font-weight: normal; +@layer base { + *, + *::before, + *::after { + box-sizing: border-box; + /* margin: 0; */ + font-weight: normal; + } } *:focus { diff --git a/src/renderer/src/components/Popups/agent/AgentModal.tsx b/src/renderer/src/components/Popups/agent/AgentModal.tsx index c19640c12d..ef5ac31785 100644 --- a/src/renderer/src/components/Popups/agent/AgentModal.tsx +++ b/src/renderer/src/components/Popups/agent/AgentModal.tsx @@ -317,7 +317,7 @@ export const AgentModal: React.FC = ({ agent, trigger, isOpen: _isOpen, o selectedKeys={[form.type]} onChange={onAgentTypeChange} items={agentOptions} - label={t('agent.add.type.label')} + label={t('agent.type.label')} placeholder={t('agent.add.type.placeholder')} renderValue={renderOption}> {(option) => ( diff --git a/src/renderer/src/i18n/label.ts b/src/renderer/src/i18n/label.ts index 9c858c3baa..db29d3f5e1 100644 --- a/src/renderer/src/i18n/label.ts +++ b/src/renderer/src/i18n/label.ts @@ -5,7 +5,13 @@ */ import { loggerService } from '@logger' -import { BuiltinMCPServerName, BuiltinMCPServerNames, BuiltinOcrProviderId, ThinkingOption } from '@renderer/types' +import { + AgentType, + BuiltinMCPServerName, + BuiltinMCPServerNames, + BuiltinOcrProviderId, + ThinkingOption +} from '@renderer/types' import i18n from './index' @@ -339,3 +345,11 @@ export const getBuiltinOcrProviderLabel = (key: BuiltinOcrProviderId) => { else if (key == 'paddleocr') return 'PaddleOCR' else return getLabel(builtinOcrProviderKeyMap, key) } + +const agentTypeKeyMap = { + 'claude-code': 'Claude Code' +} as const satisfies Record + +export const getAgentTypeLabel = (key: AgentType) => { + return getLabel(agentTypeKeyMap, key, t('agent.type.unknown')) +} diff --git a/src/renderer/src/pages/settings/AgentSettings/AgentEssentialSettings.tsx b/src/renderer/src/pages/settings/AgentSettings/AgentEssentialSettings.tsx index 90eb278295..e06b5a5ac8 100644 --- a/src/renderer/src/pages/settings/AgentSettings/AgentEssentialSettings.tsx +++ b/src/renderer/src/pages/settings/AgentSettings/AgentEssentialSettings.tsx @@ -1,12 +1,13 @@ -import { Avatar } from '@heroui/react' -import { Box, HStack } from '@renderer/components/Layout' -import { getAgentAvatar } from '@renderer/config/agent' +import { HStack } from '@renderer/components/Layout' import { useUpdateAgent } from '@renderer/hooks/agents/useUpdateAgent' import { AgentEntity, UpdateAgentForm } from '@renderer/types' import { Input } from 'antd' import { FC, useState } from 'react' import { useTranslation } from 'react-i18next' +import { SettingDivider } from '..' +import { AgentLabel, SettingsInline, SettingsTitle } from './shared' + interface AgentEssentialSettingsProps { agent: AgentEntity | undefined | null update: ReturnType @@ -26,11 +27,13 @@ const AgentEssentialSettings: FC = ({ agent, update return (
- - {t('common.name')} - + + {t('agent.type.label')} + + + + {t('common.name')} - @@ -50,12 +52,12 @@ const AgentPromptSettings: FC = ({ agent, update }) => return ( - - {t('common.prompt')} + + {t('common.prompt')} - + {showPreview ? ( diff --git a/src/renderer/src/pages/settings/AgentSettings/index.tsx b/src/renderer/src/pages/settings/AgentSettings/index.tsx index 9a2cbc39c8..e1801d3954 100644 --- a/src/renderer/src/pages/settings/AgentSettings/index.tsx +++ b/src/renderer/src/pages/settings/AgentSettings/index.tsx @@ -1,7 +1,5 @@ -import { Avatar } from '@heroui/react' import { HStack } from '@renderer/components/Layout' import { TopView } from '@renderer/components/TopView' -import { getAgentAvatar } from '@renderer/config/agent' import { useAgent } from '@renderer/hooks/agents/useAgent' import { useUpdateAgent } from '@renderer/hooks/agents/useUpdateAgent' import { Menu, Modal } from 'antd' @@ -11,6 +9,7 @@ import styled from 'styled-components' import AgentEssentialSettings from './AgentEssentialSettings' import AgentPromptSettings from './AgentPromptSettings' +import { AgentLabel } from './shared' interface AgentSettingPopupShowParams { agentId: string @@ -65,10 +64,12 @@ const AgentSettingPopupContainer: React.FC = ({ tab, ag maskClosable={false} footer={null} title={ -
- - {agent?.name ?? ''} -
+ } transitionName="animation-move-down" styles={{ diff --git a/src/renderer/src/pages/settings/AgentSettings/shared.tsx b/src/renderer/src/pages/settings/AgentSettings/shared.tsx new file mode 100644 index 0000000000..6ca583db65 --- /dev/null +++ b/src/renderer/src/pages/settings/AgentSettings/shared.tsx @@ -0,0 +1,33 @@ +import { Avatar, AvatarProps, cn } from '@heroui/react' +import { getAgentAvatar } from '@renderer/config/agent' +import { getAgentTypeLabel } from '@renderer/i18n/label' +import { AgentType } from '@renderer/types' +import React from 'react' + +export const SettingsTitle: React.FC = ({ children }) => { + return
{children}
+} + +export const SettingsInline: React.FC = ({ children }) => { + return
{children}
+} + +export type AgentLabelProps = { + type: AgentType + name?: string + classNames?: { + container?: string + avatar?: string + name?: string + } + avatarProps?: AvatarProps +} + +export const AgentLabel: React.FC = ({ type, name, classNames, avatarProps }) => { + return ( +
+ + {name ?? getAgentTypeLabel(type)} +
+ ) +}