From 976d54af29291e9ed901bc7a43a188cdbbbf55b3 Mon Sep 17 00:00:00 2001 From: Jun Han Date: Tue, 25 Dec 2018 16:48:29 +0800 Subject: [PATCH] #228: Add confirmation prompt when deleting resource (#233) --- src/constants.ts | 4 +++- src/deviceExplorer.ts | 5 ++++- src/iotHubModuleExplorer.ts | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 963a4a8..2b31674 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -89,10 +89,12 @@ export class Constants { public static IoTHubAIDeleteModuleDoneEvent = "AZ.Module.Delete.Done"; public static IoTHubAIGetModuleStartEvent = "AZ.Module.Get.Start"; public static IoTHubAIDGetModuleDoneEvent = "AZ.Module.Get.Done"; - public static IoTHubAIStartLoadDeviceTreeEvent = "General.StartLoadDeviceTree"; public static IoTHubAIShowWelcomePagetEvent = "General.WelcomePage.Show"; + public static DeleteLabel = "Delete"; + public static DeleteMessage = "Are you sure you want to delete"; + public static ConnectionStringFormat = { [Constants.IotHubConnectionStringKey]: "HostName=;SharedAccessKeyName=;SharedAccessKey=", [Constants.DeviceConnectionStringKey]: "HostName=;DeviceId=;SharedAccessKey=", diff --git a/src/deviceExplorer.ts b/src/deviceExplorer.ts index 8ef12f3..dac9424 100644 --- a/src/deviceExplorer.ts +++ b/src/deviceExplorer.ts @@ -101,7 +101,10 @@ export class DeviceExplorer extends BaseExplorer { deviceItem = await Utility.getInputDevice(deviceItem, "AZ.Device.Delete.Start"); if (deviceItem && deviceItem.label) { - return this.deleteDeviceById(deviceItem.label, label, registry); + const result = await vscode.window.showWarningMessage(`${Constants.DeleteMessage} "${deviceItem.label}"?`, { modal: true }, Constants.DeleteLabel); + if (result === Constants.DeleteLabel) { + return this.deleteDeviceById(deviceItem.label, label, registry); + } } } diff --git a/src/iotHubModuleExplorer.ts b/src/iotHubModuleExplorer.ts index ea06ce6..719beb5 100644 --- a/src/iotHubModuleExplorer.ts +++ b/src/iotHubModuleExplorer.ts @@ -91,6 +91,11 @@ export class IotHubModuleExplorer extends BaseExplorer { return; } + const result = await vscode.window.showWarningMessage(`${Constants.DeleteMessage} "${moduleItem.moduleId}"?`, { modal: true }, Constants.DeleteLabel); + if (result !== Constants.DeleteLabel) { + return; + } + const registry: iothub.Registry = iothub.Registry.fromConnectionString(iotHubConnectionString); this._outputChannel.show();