Skip to content

Commit d356b03

Browse files
committed
refactor: extract shared types/constants and simplify Card styles
- Move AgentConfigurationState type and defaultConfiguration to shared.tsx - Extract cardStyles constant to reduce duplication in ToolsAndMCPSettings - Remove redundant Card body description (tooltip already shows mode info)
1 parent 056c726 commit d356b03

File tree

3 files changed

+41
-55
lines changed

3 files changed

+41
-55
lines changed

src/renderer/src/pages/settings/AgentSettings/PermissionModeSettings.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { permissionModeCards } from '@renderer/config/agent'
22
import type {
3-
AgentConfiguration,
43
GetAgentResponse,
54
GetAgentSessionResponse,
65
PermissionMode,
76
UpdateAgentBaseForm,
87
UpdateAgentFunction,
98
UpdateAgentSessionFunction
109
} from '@renderer/types'
11-
import { AgentConfigurationSchema } from '@renderer/types'
1210
import { Tag } from 'antd'
1311
import { CheckCircle, ShieldAlert } from 'lucide-react'
1412
import type { FC } from 'react'
1513
import { useCallback, useMemo, useState } from 'react'
1614
import { useTranslation } from 'react-i18next'
1715

18-
import { computeModeDefaults, SettingsContainer, SettingsItem, SettingsTitle, uniq } from './shared'
16+
import {
17+
type AgentConfigurationState,
18+
computeModeDefaults,
19+
defaultConfiguration,
20+
SettingsContainer,
21+
SettingsItem,
22+
SettingsTitle,
23+
uniq
24+
} from './shared'
1925

2026
type PermissionModeSettingsProps =
2127
| {
@@ -27,18 +33,11 @@ type PermissionModeSettingsProps =
2733
update: UpdateAgentSessionFunction
2834
}
2935

30-
type AgentConfigurationState = AgentConfiguration & Record<string, unknown>
31-
32-
const defaultConfiguration: AgentConfigurationState = AgentConfigurationSchema.parse({})
33-
3436
export const PermissionModeSettings: FC<PermissionModeSettingsProps> = ({ agentBase, update }) => {
3537
const { t } = useTranslation()
3638
const [isUpdatingMode, setIsUpdatingMode] = useState(false)
3739

38-
const configuration: AgentConfigurationState = useMemo(
39-
() => agentBase?.configuration ?? defaultConfiguration,
40-
[agentBase?.configuration]
41-
)
40+
const configuration = useMemo(() => agentBase?.configuration ?? defaultConfiguration, [agentBase?.configuration])
4241
const selectedMode = useMemo(
4342
() => agentBase?.configuration?.permission_mode ?? defaultConfiguration.permission_mode,
4443
[agentBase?.configuration?.permission_mode]

src/renderer/src/pages/settings/AgentSettings/ToolsAndMCPSettings.tsx

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@ import CollapsibleSearchBar from '@renderer/components/CollapsibleSearchBar'
22
import { permissionModeCards } from '@renderer/config/agent'
33
import { useMCPServers } from '@renderer/hooks/useMCPServers'
44
import type {
5-
AgentConfiguration,
65
GetAgentResponse,
76
GetAgentSessionResponse,
87
UpdateAgentBaseForm,
98
UpdateAgentFunction,
109
UpdateAgentSessionFunction
1110
} from '@renderer/types'
12-
import { AgentConfigurationSchema } from '@renderer/types'
11+
import type { CardProps } from 'antd'
1312
import { Card, Switch, Tag, Tooltip } from 'antd'
1413
import { Wrench } from 'lucide-react'
1514
import type { FC } from 'react'
1615
import { useCallback, useMemo, useState } from 'react'
1716
import { useTranslation } from 'react-i18next'
1817

19-
import { computeModeDefaults, SettingsContainer, SettingsItem, SettingsTitle, uniq } from './shared'
18+
import {
19+
computeModeDefaults,
20+
defaultConfiguration,
21+
SettingsContainer,
22+
SettingsItem,
23+
SettingsTitle,
24+
uniq
25+
} from './shared'
2026

2127
type ToolsAndMCPSettingsProps =
2228
| {
@@ -28,9 +34,19 @@ type ToolsAndMCPSettingsProps =
2834
update: UpdateAgentSessionFunction
2935
}
3036

31-
type AgentConfigurationState = AgentConfiguration & Record<string, unknown>
32-
33-
const defaultConfiguration: AgentConfigurationState = AgentConfigurationSchema.parse({})
37+
const cardStyles: CardProps['styles'] = {
38+
header: {
39+
paddingLeft: '12px',
40+
paddingRight: '12px',
41+
borderBottom: 'none'
42+
},
43+
body: {
44+
paddingLeft: '12px',
45+
paddingRight: '12px',
46+
paddingTop: '0px',
47+
paddingBottom: '0px'
48+
}
49+
}
3450

3551
export const ToolsAndMCPSettings: FC<ToolsAndMCPSettingsProps> = ({ agentBase, update }) => {
3652
const { t } = useTranslation()
@@ -195,30 +211,8 @@ export const ToolsAndMCPSettings: FC<ToolsAndMCPSettingsProps> = ({ agentBase, u
195211
</Tooltip>
196212
</div>
197213
}
198-
styles={{
199-
header: {
200-
paddingLeft: '12px',
201-
paddingRight: '12px',
202-
borderBottom: 'none'
203-
},
204-
body: {
205-
paddingLeft: '12px',
206-
paddingRight: '12px',
207-
paddingTop: '0px',
208-
paddingBottom: '0px'
209-
}
210-
}}>
211-
{isAuto ? (
212-
<div className="py-0 pb-3">
213-
<span className="text-foreground-400 text-xs">
214-
{t(
215-
'agent.settings.tooling.preapproved.autoDescription',
216-
'This tool is auto-approved by the current permission mode.'
217-
)}
218-
</span>
219-
</div>
220-
) : null}
221-
</Card>
214+
styles={cardStyles}
215+
/>
222216
)
223217
})
224218
)}
@@ -281,19 +275,7 @@ export const ToolsAndMCPSettings: FC<ToolsAndMCPSettingsProps> = ({ agentBase, u
281275
</Tooltip>
282276
</div>
283277
}
284-
styles={{
285-
header: {
286-
paddingLeft: '12px',
287-
paddingRight: '12px',
288-
borderBottom: 'none'
289-
},
290-
body: {
291-
paddingLeft: '12px',
292-
paddingRight: '12px',
293-
paddingTop: '0px',
294-
paddingBottom: '0px'
295-
}
296-
}}
278+
styles={cardStyles}
297279
/>
298280
)
299281
})}

src/renderer/src/pages/settings/AgentSettings/shared.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import EmojiIcon from '@renderer/components/EmojiIcon'
22
import type { ScrollbarProps } from '@renderer/components/Scrollbar'
33
import Scrollbar from '@renderer/components/Scrollbar'
44
import { getAgentTypeLabel } from '@renderer/i18n/label'
5-
import type { AgentEntity, AgentSessionEntity, PermissionMode, Tool } from '@renderer/types'
5+
import type { AgentConfiguration, AgentEntity, AgentSessionEntity, PermissionMode, Tool } from '@renderer/types'
6+
import { AgentConfigurationSchema } from '@renderer/types'
67
import { cn } from '@renderer/utils'
78
import { Menu, Modal } from 'antd'
89
import { uniq } from 'lodash'
@@ -12,6 +13,10 @@ import styled from 'styled-components'
1213

1314
import { SettingDivider } from '..'
1415

16+
// Shared types and constants for agent settings
17+
export type AgentConfigurationState = AgentConfiguration & Record<string, unknown>
18+
export const defaultConfiguration: AgentConfigurationState = AgentConfigurationSchema.parse({})
19+
1520
/**
1621
* Computes the list of tool IDs that should be automatically approved for a given permission mode.
1722
*/

0 commit comments

Comments
 (0)