From d8f6fd9d23ee1fb0e9cfabaeabe361ff49f539ff Mon Sep 17 00:00:00 2001 From: "Craig Boger (from Dev Box)" Date: Tue, 21 Jan 2025 16:37:31 -0800 Subject: [PATCH] Fix state changing when selecting region or resetting to global. --- .../Panes/SettingsPane/SettingsPane.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx index be23d6f49..f9ac0773b 100644 --- a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx +++ b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx @@ -311,18 +311,18 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ } } - // TODO: Check if region selection has been updated. Update database account in user context accordingly. - // If global is selected, then remove the region selection from local storage. - if (selectedRegion !== LocalStorageUtility.getEntryString(StorageKey.SelectedRegion)) { - LocalStorageUtility.setEntryString(StorageKey.SelectedRegion, selectedRegion); - let selectedRegionalEndpoint: string | undefined; - if (selectedRegion === Constants.RegionSelectionOptions.Global) { - selectedRegionalEndpoint = undefined; - } else { - selectedRegionalEndpoint = regionOptions.find((option) => option.key === selectedRegion)?.data?.endpoint; - } + const storedRegion = LocalStorageUtility.getEntryString(StorageKey.SelectedRegion); + const selectedRegionIsGlobal = selectedRegion === Constants.RegionSelectionOptions.Global; + if (selectedRegionIsGlobal && storedRegion) { + LocalStorageUtility.removeEntry(StorageKey.SelectedRegion); updateUserContext({ - selectedRegionalEndpoint: selectedRegionalEndpoint, + selectedRegionalEndpoint: undefined, + refreshCosmosClient: true, + }); + } else if (!selectedRegionIsGlobal && selectedRegion !== storedRegion) { + LocalStorageUtility.setEntryString(StorageKey.SelectedRegion, selectedRegion); + updateUserContext({ + selectedRegionalEndpoint: regionOptions.find((option) => option.key === selectedRegion)?.data?.endpoint, refreshCosmosClient: true, }); }