Skip to content

Commit 2aa3fdd

Browse files
committed
Implement web configuration creation flow by adding support for insertion indices and creation state to message handlers and hooks
1 parent 2dea0dd commit 2aa3fdd

6 files changed

Lines changed: 53 additions & 10 deletions

File tree

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import { CreateWebConfigurationMessage } from '@/views/settings/types/messages'
22
import { create } from '@/views/shared/actions/web/create'
3+
import { SettingsProvider } from '../settings-provider'
4+
import { config_web_configuration_to_ui_format } from '@/utils/web-configuration-format-converters'
35

46
export const handle_create_web_configuration = async (
7+
provider: SettingsProvider,
58
message: CreateWebConfigurationMessage
69
): Promise<void> => {
7-
if (!message.web_configuration_id) {
8-
await create({
9-
placement: message.create_on_top ? 'top' : 'bottom',
10-
reference_index: message.insertion_index
10+
const result = await create({
11+
placement: message.create_on_top ? 'top' : 'bottom',
12+
reference_index: message.insertion_index
13+
})
14+
15+
if (result) {
16+
provider.postMessage({
17+
command: 'START_WEB_CONFIGURATION_CREATION',
18+
web_configuration: config_web_configuration_to_ui_format(result.config),
19+
insertion_index: result.insertion_index
1120
})
1221
}
1322
}

‎apps/editor/src/views/settings/backend/message-handlers/handle-update-web-configuration.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export const handle_update_web_configuration = async (
99
const result = await update({
1010
updating_web_configuration: message.updating_web_configuration,
1111
updated_web_configuration: message.updated_web_configuration,
12-
origin: message.origin
12+
origin: message.origin,
13+
is_new: message.is_new,
14+
insertion_index: message.insertion_index
1315
})
1416

1517
if (result.success) {

‎apps/editor/src/views/settings/backend/settings-provider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export class SettingsProvider {
239239
} else if (message.command == 'DELETE_WEB_CONFIGURATION') {
240240
await handle_delete_web_configuration(message.name)
241241
} else if (message.command == 'CREATE_WEB_CONFIGURATION') {
242-
await handle_create_web_configuration(message)
242+
await handle_create_web_configuration(this, message)
243243
} else if (message.command == 'PICK_CHATBOT') {
244244
await handle_pick_chatbot(this, message)
245245
} else if (message.command == 'PICK_MODEL') {

‎apps/editor/src/views/settings/frontend/Settings.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export const Settings = () => {
2020
set_updating_web_configuration,
2121
set_updated_web_configuration,
2222
edit_web_configuration_cancel_handler,
23-
edit_web_configuration_save_handler
23+
edit_web_configuration_save_handler,
24+
set_is_new_web_configuration,
25+
set_web_configuration_insertion_index
2426
} = use_web_configuration_editing(vscode)
2527

2628
const {
@@ -202,6 +204,8 @@ export const Settings = () => {
202204
)
203205
if (config) {
204206
set_updating_web_configuration(config)
207+
set_is_new_web_configuration(false)
208+
set_web_configuration_insertion_index(undefined)
205209
}
206210
}}
207211
on_delete_web_configuration={

‎apps/editor/src/views/settings/frontend/hooks/use-web-configuration-editing.ts‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export const use_web_configuration_editing = (vscode: any) => {
88
useState<WebConfiguration>()
99
const [updated_web_configuration, set_updated_web_configuration] =
1010
useState<WebConfiguration>()
11+
const [is_new_web_configuration, set_is_new_web_configuration] =
12+
useState(false)
13+
const [
14+
web_configuration_insertion_index,
15+
set_web_configuration_insertion_index
16+
] = useState<number>()
1117

1218
useEffect(() => {
1319
set_updated_web_configuration(updating_web_configuration)
@@ -19,7 +25,8 @@ export const use_web_configuration_editing = (vscode: any) => {
1925
command: 'UPDATE_WEB_CONFIGURATION',
2026
updating_web_configuration: updating_web_configuration!,
2127
updated_web_configuration: updated_web_configuration,
22-
origin: 'cancel'
28+
origin: 'cancel',
29+
is_new: is_new_web_configuration
2330
})
2431
} else {
2532
set_updating_web_configuration(undefined)
@@ -32,7 +39,9 @@ export const use_web_configuration_editing = (vscode: any) => {
3239
command: 'UPDATE_WEB_CONFIGURATION',
3340
updating_web_configuration: updating_web_configuration!,
3441
updated_web_configuration: updated_web_configuration,
35-
origin: 'save'
42+
origin: 'save',
43+
is_new: is_new_web_configuration,
44+
insertion_index: web_configuration_insertion_index
3645
})
3746
}
3847
}
@@ -43,6 +52,14 @@ export const use_web_configuration_editing = (vscode: any) => {
4352
if (message.command == 'WEB_CONFIGURATION_UPDATED') {
4453
set_updating_web_configuration(undefined)
4554
set_updated_web_configuration(undefined)
55+
set_is_new_web_configuration(false)
56+
set_web_configuration_insertion_index(undefined)
57+
} else if (message.command == 'START_WEB_CONFIGURATION_CREATION') {
58+
const msg = message as any
59+
set_updating_web_configuration(msg.web_configuration)
60+
set_updated_web_configuration(msg.web_configuration)
61+
set_is_new_web_configuration(true)
62+
set_web_configuration_insertion_index(msg.insertion_index)
4663
}
4764
}
4865

@@ -55,6 +72,8 @@ export const use_web_configuration_editing = (vscode: any) => {
5572
set_updating_web_configuration,
5673
set_updated_web_configuration,
5774
edit_web_configuration_cancel_handler,
58-
edit_web_configuration_save_handler
75+
edit_web_configuration_save_handler,
76+
set_is_new_web_configuration,
77+
set_web_configuration_insertion_index
5978
}
6079
}

‎apps/editor/src/views/settings/types/messages.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ export interface UpdateWebConfigurationMessage {
253253
updating_web_configuration: WebConfiguration
254254
updated_web_configuration: WebConfiguration
255255
origin?: 'cancel' | 'save'
256+
is_new?: boolean
257+
insertion_index?: number
256258
}
257259

258260
export interface CreateApiConfigurationMessage {
@@ -489,6 +491,12 @@ export interface WebConfigurationUpdatedMessage {
489491
command: 'WEB_CONFIGURATION_UPDATED'
490492
}
491493

494+
export interface StartWebConfigurationCreationMessage {
495+
command: 'START_WEB_CONFIGURATION_CREATION'
496+
web_configuration: WebConfiguration
497+
insertion_index?: number
498+
}
499+
492500
export interface StartApiConfigurationCreationMessage {
493501
command: 'START_API_CONFIGURATION_CREATION'
494502
api_configuration: ApiConfiguration
@@ -549,6 +557,7 @@ export type BackendMessage =
549557
| NewlyPickedChatbotMessage
550558
| NewlyPickedReasoningEffortMessage
551559
| WebConfigurationUpdatedMessage
560+
| StartWebConfigurationCreationMessage
552561
| StartApiConfigurationCreationMessage
553562
| ApiConfigurationUpdatedMessage
554563
| NewlyPickedModelProviderMessage

0 commit comments

Comments
 (0)