From b517a91dce2f35e40013641dd6369b7d4d5dc347 Mon Sep 17 00:00:00 2001 From: GeoffCoxMSFT Date: Fri, 26 Mar 2021 13:31:57 -0700 Subject: [PATCH 1/2] Display error w/o token on auth failure --- .../packages/server/src/locales/en-US.json | 15 ++++---- .../azurePublish/src/components/api.tsx | 19 +++++++++-- .../src/components/azureProvisionDialog.tsx | 34 ++++++++++++++----- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/Composer/packages/server/src/locales/en-US.json b/Composer/packages/server/src/locales/en-US.json index 6bf443ffd3..a1cb3db09b 100644 --- a/Composer/packages/server/src/locales/en-US.json +++ b/Composer/packages/server/src/locales/en-US.json @@ -299,6 +299,9 @@ "apr_9_2020_3c8b47d7": { "message": "Apr 9, 2020" }, + "are_you_sure_you_want_to_delete_your_bot_this_acti_214a9e11": { + "message": "Are you sure you want to delete your bot? This action cannot be undone and your bot and all related files in the bot project folder will be permanently deleted. Your Azure resources will remain unchanged." + }, "are_you_sure_you_want_to_exit_the_onboarding_produ_c2de1b23": { "message": "Are you sure you want to exit the Onboarding Product Tour? You can restart the tour in the onboarding settings." }, @@ -1427,9 +1430,6 @@ "extension_settings_899ccb55": { "message": "Extension Settings" }, - "external_resources_will_not_be_changed_c08b0009": { - "message": "External resources will not be changed." - }, "external_service_adapters_5218e6a3": { "message": "External service adapters" }, @@ -1640,9 +1640,6 @@ "http_request_79847109": { "message": "HTTP Request" }, - "i_want_to_delete_this_bot_f81a4735": { - "message": "I want to delete this bot" - }, "i_want_to_keep_the_template_content_in_the_file_ju_769331d9": { "message": "I want to keep the template content in the file, just want to dereference from this response (hint: keep the content if you currently, or plan to re-use in another location)" }, @@ -3638,9 +3635,6 @@ "warning_aacb8c24": { "message": "Warning" }, - "warning_the_action_you_are_about_to_take_cannot_be_1071a3c3": { - "message": "Warning: the action you are about to take cannot be undone. Going further will delete this bot and any related files in the bot project folder." - }, "warningsmsg_e2c04bfe": { "message": "{ warningsMsg }" }, @@ -3731,6 +3725,9 @@ "yes_dde87d5": { "message": "Yes" }, + "yes_delete_d43476ee": { + "message": "Yes, delete" + }, "you_already_have_a_kb_with_that_name_choose_anothe_b7f7c517": { "message": "You already have a KB with that name. Choose another name and try again." }, diff --git a/extensions/azurePublish/src/components/api.tsx b/extensions/azurePublish/src/components/api.tsx index 55bf56d9e3..350db893a9 100644 --- a/extensions/azurePublish/src/components/api.tsx +++ b/extensions/azurePublish/src/components/api.tsx @@ -2,6 +2,7 @@ // Licensed under the MIT License. /* eslint-disable no-underscore-dangle */ import axios from 'axios'; +import formatMessage from 'format-message'; import { SubscriptionClient } from '@azure/arm-subscriptions'; import { Subscription } from '@azure/arm-subscriptions/esm/models'; import { ResourceManagementClient } from '@azure/arm-resources'; @@ -27,6 +28,11 @@ import * as Images from './images'; const logger = debug('composer:extension:azureProvision'); +/** + * Retrieves the list of subscriptions from Azure + * @param token The authentication token + * @returns The list of subscriptions or throws + */ export const getSubscriptions = async (token: string): Promise> => { const tokenCredentials = new TokenCredentials(token); try { @@ -37,15 +43,22 @@ export const getSubscriptions = async (token: string): Promise { const extensionState = { ...defaultExtensionState, ...getItem(profileName) }; const [subscriptions, setSubscriptions] = useState(); + const [subscriptionsErrorMessage, setSubscriptionsErrorMessage] = useState(); const [deployLocations, setDeployLocations] = useState([]); const [luisLocations, setLuisLocations] = useState([]); @@ -356,11 +357,24 @@ export const AzureProvisionDialog: React.FC = () => { useEffect(() => { if (token) { - getSubscriptions(token).then((data) => { - if (isMounted.current) { - setSubscriptions(data); - } - }); + setSubscriptionsErrorMessage(undefined); + getSubscriptions(token) + .then((data) => { + if (isMounted.current) { + setSubscriptions(data); + if (data.length === 0) { + setSubscriptionsErrorMessage( + formatMessage( + 'Your subscription list is empty, please add your subscription, or login with another account.' + ) + ); + } + } + }) + .catch((err) => { + setSubscriptionsErrorMessage(err.message); + }); + getResources(); } }, [token]); @@ -657,10 +671,12 @@ export const AzureProvisionDialog: React.FC = () => { )} )} - {choice.key === 'create' && loginErrorMsg !== '' &&
{loginErrorMsg}
} - {choice.key === 'create' && currentUser && subscriptionOption?.length < 1 && ( -
- Your subscription list is empty, please add your subscription, or login with another account. + {choice.key === 'create' && loginErrorMsg !== '' && ( +
{loginErrorMsg}
+ )} + {choice.key === 'create' && currentUser && subscriptionsErrorMessage && ( +
+ {subscriptionsErrorMessage}
)} From a822e0d151fff0c7cbae11bc7e393cf45b15f3fa Mon Sep 17 00:00:00 2001 From: GeoffCoxMSFT Date: Wed, 31 Mar 2021 13:34:36 -0700 Subject: [PATCH 2/2] Fixed mounted checks --- .../src/components/azureProvisionDialog.tsx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/extensions/azurePublish/src/components/azureProvisionDialog.tsx b/extensions/azurePublish/src/components/azureProvisionDialog.tsx index 00b501bbb5..e6097a85f6 100644 --- a/extensions/azurePublish/src/components/azureProvisionDialog.tsx +++ b/extensions/azurePublish/src/components/azureProvisionDialog.tsx @@ -373,8 +373,10 @@ export const AzureProvisionDialog: React.FC = () => { const getResources = async () => { try { - const resources = await getResourceList(currentProjectId(), publishType); - setExtensionResourceOptions(resources); + if (isMounted.current) { + const resources = await getResourceList(currentProjectId(), publishType); + setExtensionResourceOptions(resources); + } } catch (err) { // todo: how do we handle API errors in this component console.log('ERROR', err); @@ -398,7 +400,9 @@ export const AzureProvisionDialog: React.FC = () => { } }) .catch((err) => { - setSubscriptionsErrorMessage(err.message); + if (isMounted.current) { + setSubscriptionsErrorMessage(err.message); + } }); getResources(); @@ -409,14 +413,18 @@ export const AzureProvisionDialog: React.FC = () => { if (token && currentSubscription) { try { const resourceGroups = await getResourceGroups(token, currentSubscription); - setResourceGroups(resourceGroups); + if (isMounted.current) { + setResourceGroups(resourceGroups); - // After the resource groups load, isNewResourceGroupName can be determined - setIsNewResourceGroupName(!resourceGroups?.some((r) => r.name === currentResourceGroupName)); + // After the resource groups load, isNewResourceGroupName can be determined + setIsNewResourceGroupName(!resourceGroups?.some((r) => r.name === currentResourceGroupName)); + } } catch (err) { // todo: how do we handle API errors in this component console.log('ERROR', err); - setResourceGroups(undefined); + if (isMounted.current) { + setResourceGroups(undefined); + } } } else { setResourceGroups(undefined);