Skip to content

Commit abf1284

Browse files
committed
Add confirmation prompts to discard unsaved changes when cancelling new web and API configurations
- when creating web/api configuration and going 'back'/closing, we should be asked in a modal if we want to discard, just like when we create model provider.
1 parent 2aa3fdd commit abf1284

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1+
import * as vscode from 'vscode'
2+
import { dictionary } from '@shared/constants/dictionary'
13
import { PanelProvider } from '../panel-provider'
24
import { update } from '@/views/shared/actions/web/update'
35

46
export const handle_update_web_configuration = async (
57
provider: PanelProvider,
68
message: any
79
): Promise<void> => {
10+
if (message.is_new && message.origin === 'cancel') {
11+
const discard_button = 'Discard'
12+
const result = await vscode.window.showWarningMessage(
13+
dictionary.information_message.CONFIRM_DISCARD_UNSAVED_CHANGES(
14+
'web configuration'
15+
),
16+
{
17+
modal: true,
18+
detail:
19+
dictionary.information_message.UNSAVED_CHANGES_TO_ITEM_WILL_BE_LOST(
20+
'web configuration'
21+
)
22+
},
23+
discard_button
24+
)
25+
26+
if (result != discard_button) {
27+
return
28+
}
29+
}
30+
831
const result = await update({
932
updating_web_configuration: message.updating_web_configuration,
1033
updated_web_configuration: message.updated_web_configuration,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as vscode from 'vscode'
2+
import { dictionary } from '@shared/constants/dictionary'
13
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
24
import { UpdateWebConfigurationMessage } from '@/views/settings/types/messages'
35
import { update } from '@/views/shared/actions/web/update'
@@ -6,6 +8,27 @@ export const handle_update_web_configuration = async (
68
settings_provider: SettingsProvider,
79
message: UpdateWebConfigurationMessage
810
): Promise<void> => {
11+
if (message.is_new && message.origin === 'cancel') {
12+
const discard_button = 'Discard'
13+
const result = await vscode.window.showWarningMessage(
14+
dictionary.information_message.CONFIRM_DISCARD_UNSAVED_CHANGES(
15+
'web configuration'
16+
),
17+
{
18+
modal: true,
19+
detail:
20+
dictionary.information_message.UNSAVED_CHANGES_TO_ITEM_WILL_BE_LOST(
21+
'web configuration'
22+
)
23+
},
24+
discard_button
25+
)
26+
27+
if (result != discard_button) {
28+
return
29+
}
30+
}
31+
932
const result = await update({
1033
updating_web_configuration: message.updating_web_configuration,
1134
updated_web_configuration: message.updated_web_configuration,

‎apps/editor/src/views/shared/actions/api/update/update.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ export const update = async (params: {
1818
}): Promise<{ success: boolean; has_changes: boolean; new_id?: string }> => {
1919
const providers_manager = new ModelProvidersManager(params.context)
2020

21-
if (params.is_new && params.origin === 'cancel') {
22-
return { success: true, has_changes: false }
23-
}
24-
2521
const api_configurations = await providers_manager.get_api_configurations()
2622

2723
let api_configuration_index = -1

0 commit comments

Comments
 (0)