diff --git a/Composer/packages/client/src/recoilModel/dispatchers/dialogs.ts b/Composer/packages/client/src/recoilModel/dispatchers/dialogs.ts index e3fa238b24..1e9fa89910 100644 --- a/Composer/packages/client/src/recoilModel/dispatchers/dialogs.ts +++ b/Composer/packages/client/src/recoilModel/dispatchers/dialogs.ts @@ -15,6 +15,7 @@ import { showCreateDialogModalState, dialogState, } from '../atoms/botState'; +import { dispatcherState } from '../DispatcherWrapper'; import { createLgFileState, removeLgFileState } from './lg'; import { createLuFileState, removeLuFileState } from './lu'; @@ -24,7 +25,16 @@ import { removeDialogSchema } from './dialogSchema'; export const dialogsDispatcher = () => { const removeDialog = useRecoilCallback( (callbackHelpers: CallbackInterface) => async (id: string, projectId: string) => { - const { set, reset } = callbackHelpers; + const { set, reset, snapshot } = callbackHelpers; + + const dialog = await snapshot.getPromise(dialogState({ projectId, dialogId: id })); + + // If the dialog is a generated form dialog, delete using form dialog dispatcher + if (dialog.content?.$schema) { + const { removeFormDialog } = await snapshot.getPromise(dispatcherState); + await removeFormDialog({ projectId, dialogId: id }); + return; + } reset(dialogState({ projectId, dialogId: id })); set(dialogIdsState(projectId), (previousDialogIds) => previousDialogIds.filter((dialogId) => dialogId !== id)); diff --git a/Composer/packages/client/src/recoilModel/dispatchers/formDialogs.ts b/Composer/packages/client/src/recoilModel/dispatchers/formDialogs.ts index 7ef47347d8..65830803ab 100644 --- a/Composer/packages/client/src/recoilModel/dispatchers/formDialogs.ts +++ b/Composer/packages/client/src/recoilModel/dispatchers/formDialogs.ts @@ -13,7 +13,7 @@ import { formDialogGenerationProgressingState, formDialogLibraryTemplatesState, } from '../atoms/appState'; -import { formDialogSchemaIdsState, formDialogSchemaState } from '../atoms/botState'; +import { dialogState, formDialogSchemaIdsState, formDialogSchemaState } from '../atoms/botState'; import { dispatcherState } from '../DispatcherWrapper'; export const formDialogsDispatcher = () => { @@ -79,7 +79,7 @@ export const formDialogsDispatcher = () => { } catch (error) { set(applicationErrorState, { message: error.message, - summary: formatMessage('Generating form dialog using ${schemaId} schema failed.', { schemaId }), + summary: formatMessage('Generating form dialog using "{ schemaId }" schema failed.', { schemaId }), }); } finally { set(formDialogGenerationProgressingState, false); @@ -87,6 +87,29 @@ export const formDialogsDispatcher = () => { } ); + const removeFormDialog = useRecoilCallback( + (callbackHelpers: CallbackInterface) => async ({ projectId, dialogId }) => { + const { set, snapshot } = callbackHelpers; + + const dialog = await snapshot.getPromise(dialogState({ projectId, dialogId })); + const { reloadProject } = await snapshot.getPromise(dispatcherState); + + try { + if (!dialog) { + return; + } + + const response = await httpClient.delete(`/formDialogs/${projectId}/${dialogId}`); + await reloadProject(callbackHelpers, response); + } catch (error) { + set(applicationErrorState, { + message: error.message, + summary: formatMessage('Deleting "{ dialogId }" failed.', { dialogId }), + }); + } + } + ); + const navigateToGeneratedDialog = ({ projectId, schemaId }) => { navigate(`/bot/${projectId}/dialogs/${schemaId}`); }; @@ -103,5 +126,6 @@ export const formDialogsDispatcher = () => { generateFormDialog, navigateToGeneratedDialog, navigateToFormDialogSchema, + removeFormDialog, }; }; diff --git a/Composer/packages/server/src/locales/en-US.json b/Composer/packages/server/src/locales/en-US.json index d5235726b6..611d6098c0 100644 --- a/Composer/packages/server/src/locales/en-US.json +++ b/Composer/packages/server/src/locales/en-US.json @@ -611,9 +611,6 @@ "could_not_connect_to_storage_50411de0": { "message": "Could not connect to storage." }, - "could_not_init_plugin_1f1c29cd": { - "message": "Could not init plugin" - }, "couldn_t_complete_the_update_a337a359": { "message": "Couldn''t complete the update:" }, @@ -812,6 +809,9 @@ "delete_property_b3786fa0": { "message": "Delete Property" }, + "deleting_dialogid_failed_1d7cc05a": { + "message": "Deleting \"{ dialogId }\" failed." + }, "describe_your_skill_88554792": { "message": "Describe your skill" }, @@ -1163,6 +1163,9 @@ "form_title_baf85c7e": { "message": "form title" }, + "form_wide_operations_1c1a73eb": { + "message": "form-wide operations" + }, "forms_380ab2ae": { "message": "Forms" }, @@ -1181,8 +1184,8 @@ "generate_dialog_b80a85b2": { "message": "Generate dialog" }, - "generating_form_dialog_using_schemaid_schema_faile_8062f953": { - "message": "Generating form dialog using ${ schemaId } schema failed." + "generating_form_dialog_using_schemaid_schema_faile_82ebdd72": { + "message": "Generating form dialog using \"{ schemaId }\" schema failed." }, "get_a_new_copy_of_the_runtime_code_84970bf": { "message": "Get a new copy of the runtime code"