Skip to content

Commit

Permalink
Fix multi user extension login for setup environment and create envir…
Browse files Browse the repository at this point in the history
…onment flows (#3907)

* Fix multi user login for setup target and create environment flows

* update  based on comments. Removes Add/Remove event handlers and instead used the weak event listener
  • Loading branch information
bbonaby authored Oct 3, 2024
1 parent c6bbd93 commit 70b3d83
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 128 deletions.
26 changes: 9 additions & 17 deletions common/Renderers/DevHomeChoiceSetWithDynamicRefresh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json;
using AdaptiveCards.ObjectModel.WinUI3;
using AdaptiveCards.Rendering.WinUI3;
using CommunityToolkit.WinUI.Helpers;
using DevHome.Common.DevHomeAdaptiveCards.CardModels;
using DevHome.Common.DevHomeAdaptiveCards.InputValues;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -85,9 +86,14 @@ private Grid SetupParentComboBoxForDynamicRefresh(AdaptiveChoiceSetInput choiceS
comboBox.ItemsSource = listOfComboBoxItems;
comboBox.SelectedIndex = int.TryParse(choiceSet.Value, out var selectedIndex) ? selectedIndex : UnSelectedIndex;

// Setup event handlers
comboBox.SelectionChanged += RefreshCardOnSelectionChanged;
comboBox.Unloaded += RemoveEventHandler;
// Setup selection changed weak event handler
var selectionChangedWeakRef = new WeakEventListener<ComboBox, object, SelectionChangedEventArgs>(comboBox)
{
OnEventAction = (instance, source, args) => RefreshCardOnSelectionChanged(instance, args),
OnDetachAction = (weakEventListener) => comboBox.SelectionChanged -= weakEventListener.OnEvent,
};

comboBox.SelectionChanged += selectionChangedWeakRef.OnEvent;

// Use the choiceSets Id as the name of the combo box.
comboBox.Name = choiceSet.Id;
Expand Down Expand Up @@ -224,20 +230,6 @@ private void RefreshCardOnSelectionChanged(object sender, SelectionChangedEventA
}
}

private void RemoveEventHandler(object sender, object args)
{
if (sender is ComboBox parentComboBox)
{
parentComboBox.SelectionChanged -= RefreshCardOnSelectionChanged;
parentComboBox.Unloaded -= RemoveEventHandler;
_childChoiceSetDataForOnParentSelectionChanged.Remove(parentComboBox);
if (_choiceSetParentIdToChildIdMap.TryGetValue(parentComboBox.Name, out var childComboBoxId))
{
_choiceSetIdToUIElementMap.Remove(childComboBoxId);
}
}
}

private void UpdateComboBoxWithDynamicData(ComboBox parentComboBox, ComboBox childComboBox)
{
_childChoiceSetDataForOnParentSelectionChanged.TryGetValue(parentComboBox, out var newDataForChildComboBox);
Expand Down
2 changes: 1 addition & 1 deletion settings/DevHome.Settings/Assets/DarkHostConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"fontFamily": "'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif",
"fontSizes": {
"small": 12,
"default": 12,
"default": 14,
"medium": 14,
"large": 18,
"extraLarge": 26
Expand Down
2 changes: 1 addition & 1 deletion settings/DevHome.Settings/Assets/LightHostConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"fontFamily": "'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif",
"fontSizes": {
"small": 12,
"default": 12,
"default": 14,
"medium": 14,
"large": 18,
"extraLarge": 26
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevHome.Common.Environments.Models;
using DevHome.SetupFlow.ViewModels.Environments;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;

namespace DevHome.SetupFlow.Converters;

/// <summary>
/// Converts the state of the EnvironmentCreationOptions page to a visibility enum.
/// </summary>
public class CreationStateKindToVisibilityConverter : IValueConverter
{
private const string ProgressRingGridName = "ProgressRingGrid";

private const string AdaptiveCardGridName = "AdaptiveCardGrid";

public object Convert(object value, Type targetType, object parameter, string language)
{
var parameterString = (string)parameter;
var creationStateKind = (CreationPageStateKind)value;

if (parameterString.Equals(AdaptiveCardGridName, StringComparison.Ordinal))
{
return creationStateKind switch
{
CreationPageStateKind.InitialPageAdaptiveCardLoaded => Visibility.Visible,
_ => Visibility.Collapsed,
};
}

if (parameterString.Equals(ProgressRingGridName, StringComparison.Ordinal))
{
return creationStateKind switch
{
CreationPageStateKind.InitialPageAdaptiveCardLoading => Visibility.Visible,
CreationPageStateKind.OtherPageAdaptiveCardLoading => Visibility.Visible,
_ => Visibility.Collapsed,
};
}

return Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,10 @@
<value>There was an error loading the data required to create {0} environments</value>
<comment>Locked={"{0}"} Error text display when we are unable to retrieve the creation data for a Dev Home provider. {0} is the name of the provider</comment>
</data>
<data name="ErrorLoadingCreationUIForDeveloperId" xml:space="preserve">
<value>There was an error loading {0} environments for '{1}'.</value>
<comment>Locked={"{0}", "{1}"} Error text to display when a Dev Home provider returns an error when returning environments for a specific user. {0} is the name of the provider and {1} is the users logon Id.</comment>
</data>
<data name="EnvironmentCreationReviewTabTitle" xml:space="preserve">
<value>Environment</value>
<comment>Title for create environment review tab</comment>
Expand Down Expand Up @@ -2035,4 +2039,8 @@
<value>Please check your network settings and try again.</value>
<comment>Text displayed when there is no internet connection</comment>
</data>
<data name="EnvironmentSelectAccountHeader.Header" xml:space="preserve">
<value>Select an account</value>
<comment>Header text for combo box where the user can select an account</comment>
</data>
</root>
4 changes: 2 additions & 2 deletions tools/SetupFlow/DevHome.SetupFlow/Utilities/DevDriveUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using CommunityToolkit.Common;
using Serilog;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.UI.Shell;
using static CommunityToolkit.Common.Converters;

namespace DevHome.SetupFlow.Utilities;

Expand Down Expand Up @@ -269,7 +269,7 @@ public static string ConvertBytesToString(ulong sizeInBytes)
if (result != 0)
{
// fallback to using community toolkit which shows this unlocalized. In the form of 50 GB, 40 TB etc.
return Converters.ToFileSizeString((long)sizeInBytes);
return ToFileSizeString((long)sizeInBytes);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ public ComputeSystemCardViewModel(ComputeSystemCache computeSystem, IComputeSyst
_dispatcherQueue = dispatcherQueue;
_computeSystemManager = manager;
ComputeSystemTitle = computeSystem.DisplayName.Value;
ComputeSystemAlternativeTitle = computeSystem.SupplementalDisplayName.Value;

if (!string.IsNullOrEmpty(computeSystem.SupplementalDisplayName.Value))
{
ComputeSystemAlternativeTitle = $"({computeSystem.SupplementalDisplayName.Value})";
}

ComputeSystem = computeSystem;
ComputeSystem.StateChanged += _computeSystemManager.OnComputeSystemStateChanged;
_computeSystemManager.ComputeSystemStateChanged += OnComputeSystemStateChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public partial class ComputeSystemsListViewModel : ObservableObject

public AdvancedCollectionView ComputeSystemCardAdvancedCollectionView { get; private set; }

public Dictionary<DeveloperIdWrapper, ComputeSystemsResult> DevIdToComputeSystemMap { get; set; }

public ComputeSystemProvider Provider { get; set; }

public DeveloperIdWrapper CurrentDeveloperId { get; set; }
Expand Down Expand Up @@ -101,21 +99,22 @@ public override string ToString()
return AccessibilityName;
}

public ComputeSystemsListViewModel(ComputeSystemsLoadedData loadedData)
public ComputeSystemsListViewModel(
ComputeSystemProviderDetails providerDetails,
KeyValuePair<DeveloperIdWrapper, ComputeSystemsResult> devIdComputeSystemPair)
{
Provider = loadedData.ProviderDetails.ComputeSystemProvider;
DevIdToComputeSystemMap = loadedData.DevIdToComputeSystemMap;

// Get the first developerId and compute system result.
var devIdToResultKeyValuePair = DevIdToComputeSystemMap.FirstOrDefault();
CurrentResult = devIdToResultKeyValuePair.Value;
CurrentDeveloperId = devIdToResultKeyValuePair.Key;
Provider = providerDetails.ComputeSystemProvider;
CurrentResult = devIdComputeSystemPair.Value;
CurrentDeveloperId = devIdComputeSystemPair.Key;

DisplayName = Provider.DisplayName;

if ((CurrentResult != null) && (CurrentResult.ComputeSystems != null))
{
ComputeSystems = CurrentResult.ComputeSystems.Select(computeSystem => new ComputeSystemCache(computeSystem)).ToList();
// Filter out compute systems that do not support configuration.
ComputeSystems = CurrentResult.ComputeSystems
.Where(computeSystem => computeSystem.SupportedOperations.HasFlag(ComputeSystemOperations.ApplyConfiguration))
.Select(computeSystem => new ComputeSystemCache(computeSystem)).ToList();
}

// Create a new AdvancedCollectionView for the ComputeSystemCards collection.
Expand Down
Loading

0 comments on commit 70b3d83

Please sign in to comment.