|
1 | | -import { Center } from '@renderer/components/Layout' |
2 | 1 | import { TopView } from '@renderer/components/TopView' |
3 | 2 | import { useAgent } from '@renderer/hooks/agents/useAgent' |
4 | 3 | import { useUpdateAgent } from '@renderer/hooks/agents/useUpdateAgent' |
5 | | -import { Alert, Spin } from 'antd' |
6 | | -import { useState } from 'react' |
| 4 | +import { useMemo } from 'react' |
7 | 5 | import { useTranslation } from 'react-i18next' |
8 | 6 |
|
9 | | -import AdvancedSettings from './AdvancedSettings' |
10 | | -import EssentialSettings from './EssentialSettings' |
11 | | -import PermissionModeSettings from './PermissionModeSettings' |
12 | | -import { InstalledPluginsSettings, PluginBrowserSettings } from './PluginsSettings/PluginsSettings' |
13 | | -import PromptSettings from './PromptSettings' |
14 | | -import { AgentLabel, LeftMenu, Settings, StyledMenu, StyledModal } from './shared' |
15 | | -import ToolsSettings from './ToolsSettings' |
| 7 | +import { BaseSettingsPopup, type SettingsMenuItem, type SettingsPopupTab } from './BaseSettingsPopup' |
| 8 | +import AdvancedSettings from './components/AdvancedSettings' |
| 9 | +import EssentialSettings from './components/EssentialSettings' |
| 10 | +import PermissionModeSettings from './components/PermissionModeSettings' |
| 11 | +import { InstalledPluginsSettings, PluginBrowserSettings } from './components/PluginsSettings/PluginsSettings' |
| 12 | +import PromptSettings from './components/PromptSettings' |
| 13 | +import ToolsSettings from './components/ToolsSettings' |
| 14 | +import { AgentLabel } from './shared' |
16 | 15 |
|
17 | 16 | interface AgentSettingPopupShowParams { |
18 | 17 | agentId: string |
19 | | - tab?: AgentSettingPopupTab |
| 18 | + tab?: SettingsPopupTab |
20 | 19 | } |
21 | 20 |
|
22 | 21 | interface AgentSettingPopupParams extends AgentSettingPopupShowParams { |
23 | 22 | resolve: () => void |
24 | 23 | } |
25 | 24 |
|
26 | | -type AgentSettingPopupTab = |
27 | | - | 'essential' |
28 | | - | 'prompt' |
29 | | - | 'permission-mode' |
30 | | - | 'tools-mcp' |
31 | | - | 'advanced' |
32 | | - | 'plugins' |
33 | | - | 'installed' |
34 | | - | 'session-mcps' |
35 | | - |
36 | 25 | const AgentSettingPopupContainer: React.FC<AgentSettingPopupParams> = ({ tab, agentId, resolve }) => { |
37 | | - const [open, setOpen] = useState(true) |
38 | 26 | const { t } = useTranslation() |
39 | | - const [menu, setMenu] = useState<AgentSettingPopupTab>(tab || 'essential') |
40 | | - |
41 | 27 | const { agent, isLoading, error } = useAgent(agentId) |
42 | 28 | const { updateAgent } = useUpdateAgent() |
43 | 29 |
|
44 | | - const onOk = () => { |
45 | | - setOpen(false) |
46 | | - } |
47 | | - |
48 | | - const onCancel = () => { |
49 | | - setOpen(false) |
50 | | - } |
51 | | - |
52 | | - const afterClose = () => { |
53 | | - resolve() |
54 | | - } |
55 | | - |
56 | | - const items = [ |
57 | | - { |
58 | | - key: 'essential', |
59 | | - label: t('agent.settings.essential') |
60 | | - }, |
61 | | - { |
62 | | - key: 'prompt', |
63 | | - label: t('agent.settings.prompt') |
64 | | - }, |
65 | | - { |
66 | | - key: 'permission-mode', |
67 | | - label: t('agent.settings.permissionMode.tab', 'Permission Mode') |
68 | | - }, |
69 | | - { |
70 | | - key: 'tools-mcp', |
71 | | - label: t('agent.settings.toolsMcp.tab', 'Tools & MCP') |
72 | | - }, |
73 | | - { |
74 | | - key: 'plugins', |
75 | | - label: t('agent.settings.plugins.available.title', 'Available Plugins') |
76 | | - }, |
77 | | - { |
78 | | - key: 'installed', |
79 | | - label: t('agent.settings.plugins.installed.title', 'Installed Plugins') |
80 | | - }, |
81 | | - { |
82 | | - key: 'advanced', |
83 | | - label: t('agent.settings.advance.title', 'Advanced Settings') |
84 | | - } |
85 | | - ] as const satisfies { key: AgentSettingPopupTab; label: string }[] |
86 | | - |
87 | | - const renderModalContent = () => { |
88 | | - if (isLoading) { |
89 | | - // TODO: use skeleton for better ux |
90 | | - return ( |
91 | | - <Center flex={1}> |
92 | | - <Spin /> |
93 | | - </Center> |
94 | | - ) |
95 | | - } |
96 | | - |
97 | | - if (error) { |
98 | | - return ( |
99 | | - <Center flex={1}> |
100 | | - <Alert type="error" message={t('agent.get.error.failed')} /> |
101 | | - </Center> |
102 | | - ) |
103 | | - } |
| 30 | + const menuItems: SettingsMenuItem[] = useMemo( |
| 31 | + () => [ |
| 32 | + { key: 'essential', label: t('agent.settings.essential') }, |
| 33 | + { key: 'prompt', label: t('agent.settings.prompt') }, |
| 34 | + { key: 'permission-mode', label: t('agent.settings.permissionMode.tab', 'Permission Mode') }, |
| 35 | + { key: 'tools-mcp', label: t('agent.settings.toolsMcp.tab', 'Tools & MCP') }, |
| 36 | + { key: 'plugins', label: t('agent.settings.plugins.available.title', 'Available Plugins') }, |
| 37 | + { key: 'installed', label: t('agent.settings.plugins.installed.title', 'Installed Plugins') }, |
| 38 | + { key: 'advanced', label: t('agent.settings.advance.title', 'Advanced Settings') } |
| 39 | + ], |
| 40 | + [t] |
| 41 | + ) |
104 | 42 |
|
105 | | - if (!agent) { |
106 | | - return null |
| 43 | + const renderTabContent = (currentTab: SettingsPopupTab) => { |
| 44 | + if (!agent) return null |
| 45 | + |
| 46 | + switch (currentTab) { |
| 47 | + case 'essential': |
| 48 | + return <EssentialSettings agentBase={agent} update={updateAgent} /> |
| 49 | + case 'prompt': |
| 50 | + return <PromptSettings agentBase={agent} update={updateAgent} /> |
| 51 | + case 'permission-mode': |
| 52 | + return <PermissionModeSettings agentBase={agent} update={updateAgent} /> |
| 53 | + case 'tools-mcp': |
| 54 | + return <ToolsSettings agentBase={agent} update={updateAgent} /> |
| 55 | + case 'plugins': |
| 56 | + return <PluginBrowserSettings agentBase={agent} update={updateAgent} /> |
| 57 | + case 'installed': |
| 58 | + return <InstalledPluginsSettings agentBase={agent} update={updateAgent} /> |
| 59 | + case 'advanced': |
| 60 | + return <AdvancedSettings agentBase={agent} update={updateAgent} /> |
| 61 | + default: |
| 62 | + return null |
107 | 63 | } |
108 | | - |
109 | | - return ( |
110 | | - <div className="flex w-full flex-1"> |
111 | | - <LeftMenu> |
112 | | - <StyledMenu |
113 | | - defaultSelectedKeys={[tab || 'essential'] satisfies AgentSettingPopupTab[]} |
114 | | - mode="vertical" |
115 | | - selectedKeys={[menu]} |
116 | | - items={items} |
117 | | - onSelect={({ key }) => setMenu(key as AgentSettingPopupTab)} |
118 | | - /> |
119 | | - </LeftMenu> |
120 | | - <Settings> |
121 | | - {menu === 'essential' && <EssentialSettings agentBase={agent} update={updateAgent} />} |
122 | | - {menu === 'prompt' && <PromptSettings agentBase={agent} update={updateAgent} />} |
123 | | - {menu === 'permission-mode' && <PermissionModeSettings agentBase={agent} update={updateAgent} />} |
124 | | - {menu === 'tools-mcp' && <ToolsSettings agentBase={agent} update={updateAgent} />} |
125 | | - {menu === 'plugins' && <PluginBrowserSettings agentBase={agent} update={updateAgent} />} |
126 | | - {menu === 'installed' && <InstalledPluginsSettings agentBase={agent} update={updateAgent} />} |
127 | | - {menu === 'advanced' && <AdvancedSettings agentBase={agent} update={updateAgent} />} |
128 | | - </Settings> |
129 | | - </div> |
130 | | - ) |
131 | 64 | } |
132 | 65 |
|
133 | 66 | return ( |
134 | | - <StyledModal |
135 | | - open={open} |
136 | | - onOk={onOk} |
137 | | - onCancel={onCancel} |
138 | | - afterClose={afterClose} |
139 | | - maskClosable={menu !== 'prompt'} |
140 | | - footer={null} |
141 | | - title={<AgentLabel agent={agent} />} |
142 | | - transitionName="animation-move-down" |
143 | | - styles={{ |
144 | | - content: { |
145 | | - padding: 0, |
146 | | - overflow: 'hidden', |
147 | | - height: '80vh', |
148 | | - display: 'flex', |
149 | | - flexDirection: 'column' |
150 | | - }, |
151 | | - header: { |
152 | | - padding: '10px 15px', |
153 | | - paddingRight: '32px', |
154 | | - borderBottom: '0.5px solid var(--color-border)', |
155 | | - margin: 0, |
156 | | - borderRadius: 0 |
157 | | - }, |
158 | | - body: { |
159 | | - padding: 0, |
160 | | - display: 'flex', |
161 | | - flex: 1 |
162 | | - } |
163 | | - }} |
164 | | - width="min(900px, 70vw)" |
165 | | - centered> |
166 | | - {renderModalContent()} |
167 | | - </StyledModal> |
| 67 | + <BaseSettingsPopup |
| 68 | + isLoading={isLoading} |
| 69 | + error={error} |
| 70 | + initialTab={tab} |
| 71 | + onClose={resolve} |
| 72 | + titleContent={<AgentLabel agent={agent} />} |
| 73 | + menuItems={menuItems} |
| 74 | + renderTabContent={renderTabContent} |
| 75 | + /> |
168 | 76 | ) |
169 | 77 | } |
170 | 78 |
|
|
0 commit comments