Skip to content

Commit 0d917db

Browse files
committed
Refactor the Settings UI by extracting General and Presets sections into dedicated components and implement functionality to manage the Gemini User ID setting
1 parent ab6178f commit 0d917db

10 files changed

Lines changed: 267 additions & 85 deletions

File tree

‎packages/ui/src/components/editor/common/Input/Input.module.scss‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
border: 1px solid var(--vscode-input-border);
44
color: var(--vscode-input-foreground);
55
padding: var(--padding-4px) var(--padding-8px);
6-
border-radius: var(--border-radius);
7-
outline: none;
6+
border-radius: var(--border-radius-4px);
87
width: 100%;
8+
outline: none;
99

1010
&:focus {
11-
border-color: var(--vscode-focusBorder);
12-
}
13-
14-
&::placeholder {
15-
color: var(--vscode-input-placeholderForeground);
11+
outline: 1px solid var(--vscode-focusBorder);
12+
outline-offset: -1px;
1613
}
1714
}

‎packages/ui/src/components/editor/common/Input/Input.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import styles from './Input.module.scss'
22

33
type Props = {
4+
id?: string
45
type?: string
56
value: string
67
placeholder?: string
78
max_width?: number
89
onChange: (value: string) => void
10+
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void
911
}
1012

1113
export const Input: React.FC<Props> = (props) => {
@@ -15,9 +17,11 @@ export const Input: React.FC<Props> = (props) => {
1517

1618
return (
1719
<input
20+
id={props.id}
1821
type={props.type || 'text'}
1922
value={props.value}
2023
onChange={(e) => props.onChange(e.target.value)}
24+
onKeyDown={props.onKeyDown}
2125
className={styles.input}
2226
placeholder={props.placeholder}
2327
style={style}

‎packages/vscode/src/views/panel/frontend/EditPresetForm/EditPresetForm.tsx‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Field } from '@ui/components/editor/panel/Field'
77
import { Slider } from '@ui/components/editor/panel/Slider'
88
import { Button } from '@ui/components/editor/panel/Button'
99
import { Checkbox } from '@ui/components/editor/common/Checkbox'
10+
import { Input } from '@ui/components/editor/common/Input'
1011
import { BackendMessage } from '@/views/panel/types/messages'
1112

1213
type Props = {
@@ -237,23 +238,18 @@ export const EditPresetForm: React.FC<Props> = (props) => {
237238

238239
{supports_user_provided_model && (
239240
<Field label="Model" html_for="custom-model">
240-
<input
241+
<Input
241242
id="custom-model"
242243
type="text"
243244
value={model || ''}
244-
onChange={(e) => set_model(e.target.value)}
245+
onChange={set_model}
245246
placeholder="Enter model name"
246247
/>
247248
</Field>
248249
)}
249250

250251
<Field label="Name" html_for="name">
251-
<input
252-
id="name"
253-
type="text"
254-
value={name}
255-
onChange={(e) => set_name(e.target.value)}
256-
/>
252+
<Input id="name" type="text" value={name} onChange={set_name} />
257253
</Field>
258254

259255
{supports_port && (
@@ -269,17 +265,17 @@ export const EditPresetForm: React.FC<Props> = (props) => {
269265
)
270266
}
271267
>
272-
<input
268+
<Input
273269
id="port"
274270
type="text"
275-
value={port}
276-
onChange={(e) => set_port(parseInt(e.target.value))}
271+
value={String(port ?? '')}
272+
onChange={(value) => {
273+
const num = parseInt(value, 10)
274+
set_port(isNaN(num) ? undefined : num)
275+
}}
277276
placeholder="e.g. 3000"
278-
onKeyDown={
279-
(e) =>
280-
!/[0-9]/.test(e.key) &&
281-
e.key != 'Backspace' &&
282-
e.preventDefault() // This way we don't see arrows up/down
277+
onKeyDown={(e) =>
278+
!/[0-9]/.test(e.key) && e.key != 'Backspace' && e.preventDefault()
283279
}
284280
/>
285281
</Field>
@@ -352,12 +348,12 @@ export const EditPresetForm: React.FC<Props> = (props) => {
352348

353349
{supports_thinking_budget && (
354350
<Field label="Thinking Budget" html_for="thinking-budget">
355-
<input
351+
<Input
356352
id="thinking-budget"
357353
type="text"
358-
value={thinking_budget ?? ''}
359-
onChange={(e) => {
360-
const num = parseInt(e.target.value, 10)
354+
value={String(thinking_budget ?? '')}
355+
onChange={(value) => {
356+
const num = parseInt(value, 10)
361357
set_thinking_budget(isNaN(num) ? undefined : num)
362358
}}
363359
placeholder="e.g. 8000"

‎packages/vscode/src/views/settings/backend/settings-provider.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,25 @@ export class SettingsProvider {
222222
case 'UPDATE_CONTEXT_SIZE_WARNING_THRESHOLD':
223223
await handle_update_context_size_warning_threshold(this, message)
224224
break
225+
case 'GET_GEMINI_USER_ID': {
226+
const config = vscode.workspace.getConfiguration('codeWebChat')
227+
const geminiUserId =
228+
config.get<number | null>('geminiUserId') ?? null
229+
this.postMessage({
230+
command: 'GEMINI_USER_ID',
231+
geminiUserId
232+
})
233+
break
234+
}
235+
case 'UPDATE_GEMINI_USER_ID':
236+
await vscode.workspace
237+
.getConfiguration('codeWebChat')
238+
.update(
239+
'geminiUserId',
240+
message.geminiUserId,
241+
vscode.ConfigurationTarget.Global
242+
)
243+
break
225244
case 'OPEN_EDITOR_SETTINGS':
226245
await vscode.commands.executeCommand(
227246
'workbench.action.openSettings'
@@ -242,6 +261,13 @@ export class SettingsProvider {
242261
void handle_get_edit_context_configurations(this)
243262
void handle_get_intelligent_update_configurations(this)
244263
void handle_get_context_size_warning_threshold(this)
264+
{
265+
const config = vscode.workspace.getConfiguration('codeWebChat')
266+
this.postMessage({
267+
command: 'GEMINI_USER_ID',
268+
geminiUserId: config.get<number | null>('geminiUserId') ?? null
269+
})
270+
}
245271
}
246272
})
247273
)

‎packages/vscode/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import { NavigationDivider } from '@ui/components/editor/settings/NavigationDivi
66
import { Item } from '@ui/components/editor/settings/Item'
77
import { ApiToolConfigurationSection } from './sections/ApiToolConfigurationSection'
88
import { Section } from '@ui/components/editor/settings/Section'
9-
import { TextButton } from '@ui/components/editor/settings/TextButton'
10-
import { Input } from '@ui/components/editor/common/Input'
119
import { Textarea } from '@ui/components/editor/settings/Textarea'
1210
import {
1311
ConfigurationForClient,
1412
ProviderForClient
1513
} from '@/views/settings/types/messages'
14+
import { GeneralSection } from './sections/GeneralSection'
15+
import { PresetsSection } from './sections/PresetsSection'
1616

1717
type NavItem =
1818
| 'general'
19+
| 'presets'
1920
| 'model-providers'
2021
| 'edit-context'
2122
| 'code-completions'
@@ -32,6 +33,11 @@ const NAV_ITEMS_CONFIG: NavConfigItem[] = [
3233
id: 'general',
3334
label: 'General'
3435
},
36+
{
37+
type: 'item',
38+
id: 'presets',
39+
label: 'Presets'
40+
},
3541
{
3642
type: 'item',
3743
id: 'model-providers',
@@ -53,6 +59,7 @@ type Props = {
5359
intelligent_update_configs: ConfigurationForClient[]
5460
commit_message_instructions: string
5561
context_size_warning_threshold: number
62+
gemini_user_id: number | null
5663

5764
// handlers
5865
set_providers: (providers: ProviderForClient[]) => void
@@ -62,6 +69,7 @@ type Props = {
6269
set_commit_messages_configs: (configs: ConfigurationForClient[]) => void
6370
on_context_size_warning_threshold_change: (threshold: number) => void
6471
on_commit_instructions_change: (instructions: string) => void
72+
on_gemini_user_id_change: (id: number | null) => void
6573
on_open_editor_settings: () => void
6674
on_add_provider: () => void
6775
on_delete_provider: (provider_name: string) => void
@@ -84,15 +92,14 @@ export const Home: React.FC<Props> = (props) => {
8492
const scroll_container_ref = useRef<HTMLDivElement>(null)
8593
const section_refs = useRef<Record<NavItem, HTMLDivElement | null>>({
8694
general: null,
95+
presets: null,
8796
'model-providers': null,
8897
'edit-context': null,
8998
'code-completions': null,
9099
'intelligent-update': null,
91100
'commit-messages': null
92101
})
93102
const [commit_instructions, set_commit_instructions] = useState('')
94-
const [context_size_warning_threshold, set_context_size_warning_threshold] =
95-
useState('')
96103
const [stuck_sections, set_stuck_sections] = useState(new Set<NavItem>())
97104

98105
const handle_stuck_change = useCallback((id: NavItem, is_stuck: boolean) => {
@@ -115,6 +122,10 @@ export const Home: React.FC<Props> = (props) => {
115122
(is_stuck: boolean) => handle_stuck_change('general', is_stuck),
116123
[handle_stuck_change]
117124
)
125+
const presets_on_stuck_change = useCallback(
126+
(is_stuck: boolean) => handle_stuck_change('presets', is_stuck),
127+
[handle_stuck_change]
128+
)
118129
const model_providers_on_stuck_change = useCallback(
119130
(is_stuck: boolean) => handle_stuck_change('model-providers', is_stuck),
120131
[handle_stuck_change]
@@ -147,12 +158,6 @@ export const Home: React.FC<Props> = (props) => {
147158
set_commit_instructions(props.commit_message_instructions || '')
148159
}, [props.commit_message_instructions])
149160

150-
useEffect(() => {
151-
set_context_size_warning_threshold(
152-
String(props.context_size_warning_threshold)
153-
)
154-
}, [props.context_size_warning_threshold])
155-
156161
useEffect(() => {
157162
const handler = setTimeout(() => {
158163
if (
@@ -169,25 +174,6 @@ export const Home: React.FC<Props> = (props) => {
169174
props.commit_message_instructions
170175
])
171176

172-
useEffect(() => {
173-
const handler = setTimeout(() => {
174-
const num_threshold = parseInt(context_size_warning_threshold, 10)
175-
if (
176-
!isNaN(num_threshold) &&
177-
num_threshold >= 0 &&
178-
props.context_size_warning_threshold !== undefined &&
179-
num_threshold !== props.context_size_warning_threshold
180-
) {
181-
props.on_context_size_warning_threshold_change(num_threshold)
182-
}
183-
}, 500)
184-
return () => clearTimeout(handler)
185-
}, [
186-
context_size_warning_threshold,
187-
props.on_context_size_warning_threshold_change,
188-
props.context_size_warning_threshold
189-
])
190-
191177
const handle_scroll_to_section = (item_id: NavItem) => {
192178
const section = section_refs.current[item_id]
193179
const scroll_container = scroll_container_ref.current
@@ -241,35 +227,21 @@ export const Home: React.FC<Props> = (props) => {
241227
)
242228
})}
243229
>
244-
<Section
230+
<GeneralSection
245231
ref={(el) => (section_refs.current['general'] = el)}
246-
title="General"
247-
subtitle="General settings for the extension."
232+
context_size_warning_threshold={props.context_size_warning_threshold}
233+
on_context_size_warning_threshold_change={
234+
props.on_context_size_warning_threshold_change
235+
}
236+
on_open_editor_settings={props.on_open_editor_settings}
248237
on_stuck_change={general_on_stuck_change}
249-
>
250-
<Item
251-
title="Open Editor Settings"
252-
description="For general editor settings, visit the Editor Settings Page."
253-
slot={
254-
<TextButton on_click={props.on_open_editor_settings}>
255-
Open Editor Settings
256-
</TextButton>
257-
}
258-
/>
259-
<Item
260-
title="Context Size Warning Threshold"
261-
description="Set the token count threshold for showing a warning about large context sizes."
262-
slot_placement="below"
263-
slot={
264-
<Input
265-
type="number"
266-
value={context_size_warning_threshold}
267-
onChange={set_context_size_warning_threshold}
268-
max_width={100}
269-
/>
270-
}
271-
/>
272-
</Section>
238+
/>
239+
<PresetsSection
240+
ref={(el) => (section_refs.current['presets'] = el)}
241+
gemini_user_id={props.gemini_user_id}
242+
on_gemini_user_id_change={props.on_gemini_user_id_change}
243+
on_stuck_change={presets_on_stuck_change}
244+
/>
273245
<Section
274246
ref={(el) => (section_refs.current['model-providers'] = el)}
275247
title="Model Providers"

0 commit comments

Comments
 (0)