From b2bc4ac5dc535c40f1b9d9750aa861e804691aaa Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Wed, 14 Feb 2024 12:37:52 -0800 Subject: [PATCH 01/16] USing tags --- .../DevHome.SetupFlow.csproj | 1 + .../ViewModels/AddRepoViewModel.cs | 110 +++++++++++++++++- .../IncrementalRepoViewItemViewModel.cs | 49 ++++++++ .../Views/AddRepoDialog.xaml | 38 ++++-- .../Views/AddRepoDialog.xaml.cs | 49 +++----- .../Views/RepoConfigView.xaml.cs | 12 +- 6 files changed, 207 insertions(+), 52 deletions(-) create mode 100644 tools/SetupFlow/DevHome.SetupFlow/ViewModels/IncrementalRepoViewItemViewModel.cs diff --git a/tools/SetupFlow/DevHome.SetupFlow/DevHome.SetupFlow.csproj b/tools/SetupFlow/DevHome.SetupFlow/DevHome.SetupFlow.csproj index bdc73d242f..ac5c2c0a23 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/DevHome.SetupFlow.csproj +++ b/tools/SetupFlow/DevHome.SetupFlow/DevHome.SetupFlow.csproj @@ -10,6 +10,7 @@ + diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 1d8dd8c5bd..c7bbf7c15e 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -10,6 +10,9 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.WinUI.Collections; +using CommunityToolkit.WinUI.Controls; +using DevHome.Common.Contracts; using DevHome.Common.Extensions; using DevHome.Common.Services; using DevHome.Common.TelemetryEvents.DeveloperId; @@ -48,7 +51,7 @@ public partial class AddRepoViewModel : ObservableObject private readonly List _previouslySelectedRepos; /// - /// Because logic is split between the back-end and the view model, incrementally migrating code from the view + /// Because logic is split between the back-end and the view model, migrating code from the view /// to the view model is impossible. /// This member is here to support this partial migration. Once all the code-behind logic is out of the view /// _addRepoDialog can be removed. @@ -71,6 +74,14 @@ public FolderPickerViewModel FolderPickerViewModel get; private set; } + /// + /// Gets the view model to handle adding a dev drive. + /// + public EditDevDriveViewModel EditDevDriveViewModel + { + get; private set; + } + private ElementTheme SelectedTheme => _host.GetService().Theme; /// @@ -128,7 +139,7 @@ public List EverythingToClone /// All repositories currently shown on the screen. /// [ObservableProperty] - private ObservableCollection _repositories = new(); + private IncrementalLoadingCollection _repositories = new(); /// /// Should the URL page be visible? @@ -198,6 +209,33 @@ public List EverythingToClone [ObservableProperty] private bool _isCancelling; + private enum SegmentedItemTag + { + Account, + URL, + } + + [RelayCommand] + public void ChangePage(SegmentedItem selectedItem) + { + var pageToGoTo = Enum.Parse(selectedItem.Tag.ToString()); + + if (pageToGoTo == SegmentedItemTag.Account) + { + ChangeToAccountPage(); + return; + } + + if (pageToGoTo == SegmentedItemTag.URL) + { + ChangeToUrlPage(); + return; + } + + // enum did not match. Don't change. + return; + } + /// /// Indicates if the ListView is currently filtering items. A result of manually filtering a list view /// is that the SelectionChanged is fired for any selected item that is removed and the item isn't "re-selected" @@ -238,7 +276,9 @@ public void FilterRepositories(string text) } _isFiltering = true; - Repositories = new ObservableCollection(OrderRepos(filteredRepositories)); + var localRepositoires = OrderRepos(filteredRepositories).ToList(); + var indexer = new IncrementalRepoViewItemViewModel(localRepositoires); + Repositories = new IncrementalLoadingCollection(indexer); _isFiltering = false; } @@ -350,6 +390,30 @@ private void MenuItemClick(string selectedItemName) }); } + [RelayCommand] + public void SortRepos(string sortMethod) + { + var repositories = new List(); + if (sortMethod.Equals("Name asending", StringComparison.OrdinalIgnoreCase)) + { + repositories = _repositoriesForAccount + .OrderBy(x => Path.Join(x.OwningAccountName, x.DisplayName)) + .Select(x => new RepoViewListItem(x)) + .ToList(); + } + + if (sortMethod.Equals("Name desending", StringComparison.OrdinalIgnoreCase)) + { + repositories = _repositoriesForAccount + .OrderByDescending(x => Path.Join(x.OwningAccountName, x.DisplayName)) + .Select(x => new RepoViewListItem(x)) + .ToList(); + } + + var indexer = new IncrementalRepoViewItemViewModel(repositories); + Repositories = new IncrementalLoadingCollection(indexer); + } + /// /// Makes the MenuFlyout object used to display multple accounts in the repo tool. /// @@ -442,7 +506,8 @@ public AddRepoViewModel( IHost host, Guid activityId, string defaultClonePath, - AddRepoDialog addRepoDialog) + AddRepoDialog addRepoDialog, + IDevDriveManager devDriveManager) { _addRepoDialog = addRepoDialog; _stringResource = stringResource; @@ -459,6 +524,14 @@ public AddRepoViewModel( _activityId = activityId; FolderPickerViewModel = new FolderPickerViewModel(stringResource); FolderPickerViewModel.CloneLocation = defaultClonePath; + + EditDevDriveViewModel = new EditDevDriveViewModel(devDriveManager); + + EditDevDriveViewModel.DevDriveClonePathUpdated += (_, updatedDevDriveRootPath) => + { + FolderPickerViewModel.CloneLocationAlias = EditDevDriveViewModel.GetDriveDisplayName(DevDriveDisplayNameKind.FormattedDriveLabelKind); + FolderPickerViewModel.CloneLocation = updatedDevDriveRootPath; + }; } /// @@ -495,6 +568,14 @@ public void SetChangedEvents(TypedEventHandler /// All previously selected repos excluding any added via URL. public IEnumerable SetRepositories(string repositoryProvider, string loginId) { - Repositories = new ObservableCollection(OrderRepos(_repositoriesForAccount)); + var localRepositoires = OrderRepos(_repositoriesForAccount).ToList(); + var indexer = new IncrementalRepoViewItemViewModel(localRepositoires); + Repositories = new IncrementalLoadingCollection(indexer); return _previouslySelectedRepos.Where(x => x.OwningAccount != null) .Where(x => x.ProviderName.Equals(repositoryProvider, StringComparison.OrdinalIgnoreCase) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/IncrementalRepoViewItemViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/IncrementalRepoViewItemViewModel.cs new file mode 100644 index 0000000000..1a560a867c --- /dev/null +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/IncrementalRepoViewItemViewModel.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using CommunityToolkit.WinUI.Collections; +using DevHome.SetupFlow.Models; + +namespace DevHome.SetupFlow.ViewModels; + +public class IncrementalRepoViewItemViewModel : IIncrementalSource +{ + private readonly List _items; + + public IncrementalRepoViewItemViewModel() + { + _items = new List(); + } + + public IncrementalRepoViewItemViewModel(List items) + { + _items = items; + } + + public async Task> GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default) + { + // Gets items from the collection according to pageIndex and pageSize parameters. + var result = (from p in _items + select p).Skip(pageIndex * pageSize).Take(pageSize); + + // Simulates a longer request... + // Make sure the list is still in order after a refresh, + // even if the first page takes longer to load + if (pageIndex == 0) + { + await Task.Delay(200, cancellationToken); + } + else + { + await Task.Delay(100, cancellationToken); + } + + return result; + } +} diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index 9cf1caad7a..01a1c04a40 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -45,9 +45,14 @@ - - - + + + + + + + + @@ -88,13 +93,28 @@ - + + + + + + + + Name asending + Name desending + + + + + + + @@ -168,7 +188,7 @@ @@ -182,15 +202,15 @@ + Visibility="{x:Bind AddRepoViewModel.EditDevDriveViewModel.DevDriveValidationError, Mode=OneWay}"/> diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs index 12f0b14b4e..18eb9ae087 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs @@ -42,14 +42,6 @@ public AddRepoViewModel AddRepoViewModel get; set; } - /// - /// Gets or sets the view model to handle adding a dev drive. - /// - public EditDevDriveViewModel EditDevDriveViewModel - { - get; set; - } - /// /// Hold the clone location in case the user decides not to add a dev drive. /// @@ -68,14 +60,7 @@ public AddRepoDialog( var userFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); var defaultClonePath = Path.Join(userFolder, "source", "repos"); - AddRepoViewModel = new AddRepoViewModel(stringResource, previouslySelectedRepos, host, activityId, defaultClonePath, this); - EditDevDriveViewModel = new EditDevDriveViewModel(devDriveManager); - - EditDevDriveViewModel.DevDriveClonePathUpdated += (_, updatedDevDriveRootPath) => - { - AddRepoViewModel.FolderPickerViewModel.CloneLocationAlias = EditDevDriveViewModel.GetDriveDisplayName(DevDriveDisplayNameKind.FormattedDriveLabelKind); - AddRepoViewModel.FolderPickerViewModel.CloneLocation = updatedDevDriveRootPath; - }; + AddRepoViewModel = new AddRepoViewModel(stringResource, previouslySelectedRepos, host, activityId, defaultClonePath, this, devDriveManager); // Changing view to account so the selection changed event for Segment correctly shows URL. AddRepoViewModel.CurrentPage = PageKind.AddViaAccount; @@ -130,13 +115,13 @@ public async Task SetupDevDrivesAsync() { await Task.Run(() => { - EditDevDriveViewModel.SetUpStateIfDevDrivesIfExists(); + AddRepoViewModel.EditDevDriveViewModel.SetUpStateIfDevDrivesIfExists(); - if (EditDevDriveViewModel.DevDrive != null && - EditDevDriveViewModel.DevDrive.State == DevDriveState.ExistsOnSystem) + if (AddRepoViewModel.EditDevDriveViewModel.DevDrive != null && + AddRepoViewModel.EditDevDriveViewModel.DevDrive.State == DevDriveState.ExistsOnSystem) { AddRepoViewModel.FolderPickerViewModel.InDevDriveScenario = true; - EditDevDriveViewModel.ClonePathUpdated(); + AddRepoViewModel.EditDevDriveViewModel.ClonePathUpdated(); } }); } @@ -145,7 +130,7 @@ private void ChangeToAccountPage() { AddRepoViewModel.ChangeToAccountPage(); AddRepoViewModel.FolderPickerViewModel.CloseFolderPicker(); - EditDevDriveViewModel.HideDevDriveUI(); + AddRepoViewModel.EditDevDriveViewModel.HideDevDriveUI(); // If DevHome has 1 provider installed and the provider has 1 logged in account // switch to the repo page. @@ -164,7 +149,7 @@ private void ChangeToUrlPage() RepositoryProviderComboBox.SelectedIndex = -1; AddRepoViewModel.ChangeToUrlPage(); AddRepoViewModel.FolderPickerViewModel.ShowFolderPicker(); - EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); + AddRepoViewModel.EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); ToggleCloneButton(); } @@ -188,7 +173,7 @@ private void CloneLocation_TextChanged(object sender, TextChangedEventArgs e) var location = cloneLocationTextBox.Text; if (string.Equals(cloneLocationTextBox.Name, "DevDriveCloneLocationAliasTextBox", StringComparison.Ordinal)) { - location = (EditDevDriveViewModel.DevDrive != null) ? EditDevDriveViewModel.GetDriveDisplayName() : string.Empty; + location = (AddRepoViewModel.EditDevDriveViewModel.DevDrive != null) ? AddRepoViewModel.EditDevDriveViewModel.GetDriveDisplayName() : string.Empty; } // In cases where location is empty don't update the cloneLocation. Only update when there are actual values. @@ -346,7 +331,7 @@ private async void SwitchToRepoPage(string repositoryProviderName) { AddRepoViewModel.ChangeToRepoPage(); AddRepoViewModel.FolderPickerViewModel.ShowFolderPicker(); - EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); + AddRepoViewModel.EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); AddRepoViewModel.SelectedAccount = AddRepoViewModel.Accounts.First(); AddRepoViewModel.ShouldEnablePrimaryButton = false; } @@ -370,7 +355,7 @@ private void MakeNewDevDriveCheckBox_Click(object sender, RoutedEventArgs e) { AddRepoViewModel.FolderPickerViewModel.CloneLocationAlias = string.Empty; AddRepoViewModel.FolderPickerViewModel.InDevDriveScenario = false; - EditDevDriveViewModel.RemoveNewDevDrive(); + AddRepoViewModel.EditDevDriveViewModel.RemoveNewDevDrive(); AddRepoViewModel.FolderPickerViewModel.EnableBrowseButton(); AddRepoViewModel.FolderPickerViewModel.CloneLocation = _oldCloneLocation; } @@ -381,7 +366,7 @@ private void MakeNewDevDriveCheckBox_Click(object sender, RoutedEventArgs e) /// private async void CustomizeDevDriveHyperlinkButton_ClickAsync(object sender, RoutedEventArgs e) { - await EditDevDriveViewModel.PopDevDriveCustomizationAsync(); + await AddRepoViewModel.EditDevDriveViewModel.PopDevDriveCustomizationAsync(); ToggleCloneButton(); } @@ -391,9 +376,9 @@ private async void CustomizeDevDriveHyperlinkButton_ClickAsync(object sender, Ro private void ToggleCloneButton() { var isEverythingGood = AddRepoViewModel.ValidateRepoInformation() && AddRepoViewModel.FolderPickerViewModel.ValidateCloneLocation(); - if (EditDevDriveViewModel.DevDrive != null && EditDevDriveViewModel.DevDrive.State != DevDriveState.ExistsOnSystem) + if (AddRepoViewModel.EditDevDriveViewModel.DevDrive != null && AddRepoViewModel.EditDevDriveViewModel.DevDrive.State != DevDriveState.ExistsOnSystem) { - isEverythingGood &= EditDevDriveViewModel.IsDevDriveValid(); + isEverythingGood &= AddRepoViewModel.EditDevDriveViewModel.IsDevDriveValid(); } AddRepoViewModel.ShouldEnablePrimaryButton = isEverythingGood; @@ -449,12 +434,12 @@ private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e) /// public void UpdateDevDriveInfo() { - EditDevDriveViewModel.MakeDefaultDevDrive(); + AddRepoViewModel.EditDevDriveViewModel.MakeDefaultDevDrive(); AddRepoViewModel.FolderPickerViewModel.DisableBrowseButton(); _oldCloneLocation = AddRepoViewModel.FolderPickerViewModel.CloneLocation; - AddRepoViewModel.FolderPickerViewModel.CloneLocation = EditDevDriveViewModel.GetDriveDisplayName(); - AddRepoViewModel.FolderPickerViewModel.CloneLocationAlias = EditDevDriveViewModel.GetDriveDisplayName(DevDriveDisplayNameKind.FormattedDriveLabelKind); + AddRepoViewModel.FolderPickerViewModel.CloneLocation = AddRepoViewModel.EditDevDriveViewModel.GetDriveDisplayName(); + AddRepoViewModel.FolderPickerViewModel.CloneLocationAlias = AddRepoViewModel.EditDevDriveViewModel.GetDriveDisplayName(DevDriveDisplayNameKind.FormattedDriveLabelKind); AddRepoViewModel.FolderPickerViewModel.InDevDriveScenario = true; - EditDevDriveViewModel.IsDevDriveCheckboxChecked = true; + AddRepoViewModel.EditDevDriveViewModel.IsDevDriveCheckboxChecked = true; } } diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/RepoConfigView.xaml.cs b/tools/SetupFlow/DevHome.SetupFlow/Views/RepoConfigView.xaml.cs index 2eefc208d0..a236cf9c35 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/RepoConfigView.xaml.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/RepoConfigView.xaml.cs @@ -78,7 +78,7 @@ private async Task AddRepoAsync() _addRepoDialog.SetDeveloperIdChangedEvents(); - if (_addRepoDialog.EditDevDriveViewModel.CanShowDevDriveUI && ViewModel.ShouldAutoCheckDevDriveCheckbox) + if (_addRepoDialog.AddRepoViewModel.EditDevDriveViewModel.CanShowDevDriveUI && ViewModel.ShouldAutoCheckDevDriveCheckbox) { _addRepoDialog.UpdateDevDriveInfo(); } @@ -86,9 +86,9 @@ private async Task AddRepoAsync() _addRepoDialog.IsSecondaryButtonEnabled = true; var result = await _addRepoDialog.ShowAsync(ContentDialogPlacement.InPlace); - var devDrive = _addRepoDialog.EditDevDriveViewModel.DevDrive; + var devDrive = _addRepoDialog.AddRepoViewModel.EditDevDriveViewModel.DevDrive; - if (_addRepoDialog.EditDevDriveViewModel.IsWindowOpen) + if (_addRepoDialog.AddRepoViewModel.EditDevDriveViewModel.IsWindowOpen) { ViewModel.DevDriveManager.RequestToCloseDevDriveWindow(devDrive); } @@ -145,7 +145,7 @@ private async Task AddRepoAsync() // Check if user unchecked the Dev Drive checkbox before closing, to update the the behavior the next time the user launches the dialog. Note we only keep // track of this for the current launch of the setup flow. If the user completes or cancels the setup flow and re enters, we do not keep the unchecked behavior. - if (!_addRepoDialog.EditDevDriveViewModel.IsDevDriveCheckboxChecked) + if (!_addRepoDialog.AddRepoViewModel.EditDevDriveViewModel.IsDevDriveCheckboxChecked) { ViewModel.ShouldAutoCheckDevDriveCheckbox = false; } @@ -177,8 +177,8 @@ private async Task AddRepoAsync() addKind, _addRepoDialog.AddRepoViewModel.EverythingToClone.Count, providerName, - _addRepoDialog.EditDevDriveViewModel.DevDrive.State == DevDriveState.New, - _addRepoDialog.EditDevDriveViewModel.DevDriveDetailsChanged), + _addRepoDialog.AddRepoViewModel.EditDevDriveViewModel.DevDrive.State == DevDriveState.New, + _addRepoDialog.AddRepoViewModel.EditDevDriveViewModel.DevDriveDetailsChanged), ActivityId); } else if (cloneLocationKind == CloneLocationKind.LocalPath) From 0cfb56db863a70ce8ee8b50b4c35eddf4a23a053 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Fri, 16 Feb 2024 14:31:43 -0800 Subject: [PATCH 02/16] Can clone repos again. --- .../AddRepoDialogTests.cs | 7 +- .../ViewModels/AddRepoViewModel.cs | 101 ++++++++++++------ .../Views/AddRepoDialog.xaml | 4 +- .../Views/AddRepoDialog.xaml.cs | 99 ++--------------- 4 files changed, 84 insertions(+), 127 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs index 88d3caadae..9e686caf69 100644 --- a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs +++ b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using DevHome.Common.Extensions; +using DevHome.Common.Services; using DevHome.SetupFlow.Models; using DevHome.SetupFlow.Services; using DevHome.SetupFlow.ViewModels; @@ -28,7 +29,7 @@ public void HideRetryBannerTest() [TestMethod] public void SwitchToUrlScreenTest() { - var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), string.Empty, null); + var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), string.Empty, null, TestHost.GetService()); addRepoViewModel.ChangeToUrlPage(); Assert.AreEqual(Visibility.Visible, addRepoViewModel.ShowUrlPage); Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowAccountPage); @@ -41,8 +42,8 @@ public void SwitchToUrlScreenTest() [TestMethod] public void SwitchToRepoScreenTest() { - var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), string.Empty, null); - addRepoViewModel.ChangeToRepoPage(); + var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), string.Empty, null, TestHost.GetService()); + addRepoViewModel.ChangeToRepoPage().Wait(); Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowUrlPage); Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowAccountPage); Assert.AreEqual(Visibility.Visible, addRepoViewModel.ShowRepoPage); diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index c7bbf7c15e..6daa53a010 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -14,6 +14,7 @@ using CommunityToolkit.WinUI.Controls; using DevHome.Common.Contracts; using DevHome.Common.Extensions; +using DevHome.Common.Models; using DevHome.Common.Services; using DevHome.Common.TelemetryEvents.DeveloperId; using DevHome.Common.TelemetryEvents.SetupFlow; @@ -374,6 +375,9 @@ private void CancelButtonPressed() [ObservableProperty] private MenuFlyout _accountsToShow; + [ObservableProperty] + private Frame _loginUiContent; + /// /// Switches the repos shown to the account selected. /// @@ -466,7 +470,7 @@ private async Task AddAccountClicked() // Store the logged in accounts to help figure out what account the user logged into. var loggedInAccounts = await Task.Run(() => _providers.GetAllLoggedInAccounts(_selectedRepoProvider)); - await LogUserIn(_selectedRepoProvider, _addRepoDialog.GetLoginUiContent(), true); + await LogUserIn(_selectedRepoProvider, LoginUiContent, true); var loggedInAccountsWithNewAccount = await Task.Run(() => _providers.GetAllLoggedInAccounts(_selectedRepoProvider)); ShowRepoPage = Visibility.Visible; @@ -512,12 +516,6 @@ public AddRepoViewModel( _addRepoDialog = addRepoDialog; _stringResource = stringResource; _host = host; - ChangeToUrlPage(); - - // override changes ChangeToUrlPage to correctly set the state. - UrlParsingError = string.Empty; - ShouldShowUrlError = Visibility.Collapsed; - ShowErrorTextBox = Visibility.Collapsed; _previouslySelectedRepos = previouslySelectedRepos ?? new List(); EverythingToClone = new List(_previouslySelectedRepos); @@ -532,6 +530,33 @@ public AddRepoViewModel( FolderPickerViewModel.CloneLocationAlias = EditDevDriveViewModel.GetDriveDisplayName(DevDriveDisplayNameKind.FormattedDriveLabelKind); FolderPickerViewModel.CloneLocation = updatedDevDriveRootPath; }; + + ChangeToUrlPage(); + + // override changes ChangeToUrlPage to correctly set the state. + UrlParsingError = string.Empty; + ShouldShowUrlError = Visibility.Collapsed; + ShowErrorTextBox = Visibility.Collapsed; + } + + /// + /// Toggles the clone button. Make sure other view models have correct information. + /// + public void ToggleCloneButton() + { + var isEverythingGood = ValidateRepoInformation() && FolderPickerViewModel.ValidateCloneLocation(); + if (EditDevDriveViewModel.DevDrive != null && EditDevDriveViewModel.DevDrive.State != DevDriveState.ExistsOnSystem) + { + isEverythingGood &= EditDevDriveViewModel.IsDevDriveValid(); + } + + ShouldEnablePrimaryButton = isEverythingGood; + + // Fill in EverythingToClone with the location + if (isEverythingGood) + { + SetCloneLocation(FolderPickerViewModel.CloneLocation); + } } /// @@ -570,12 +595,10 @@ public void ChangeToUrlPage() { /* RepositoryProviderComboBox.SelectedIndex = -1; - AddRepoViewModel.ChangeToUrlPage(); - AddRepoViewModel.FolderPickerViewModel.ShowFolderPicker(); - AddRepoViewModel.EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); - ToggleCloneButton(); */ + FolderPickerViewModel.ShowFolderPicker(); + EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); Log.Logger?.ReportInfo(Log.Component.RepoConfig, "Changing to Url page"); ShowUrlPage = Visibility.Visible; ShowAccountPage = Visibility.Collapsed; @@ -585,25 +608,38 @@ public void ChangeToUrlPage() CurrentPage = PageKind.AddViaUrl; PrimaryButtonText = _stringResource.GetLocalized(StringResourceKey.RepoEverythingElsePrimaryButtonText); ShouldShowLoginUi = false; + + ToggleCloneButton(); } public void ChangeToAccountPage() { - /* - * AddRepoViewModel.ChangeToAccountPage(); - AddRepoViewModel.FolderPickerViewModel.CloseFolderPicker(); - AddRepoViewModel.EditDevDriveViewModel.HideDevDriveUI(); + // List of extensions needs to be refreshed before accessing + GetExtensions(); + if (ProviderNames.Count == 1) + { + _providers.StartIfNotRunning(ProviderNames[0]); + var accounts = _providers.GetAllLoggedInAccounts(ProviderNames[0]); + if (accounts.Count() == 1) + { + CanSkipAccountConnection = true; + } + } + + FolderPickerViewModel.CloseFolderPicker(); + EditDevDriveViewModel.HideDevDriveUI(); // If DevHome has 1 provider installed and the provider has 1 logged in account // switch to the repo page. - if (AddRepoViewModel.CanSkipAccountConnection) + if (CanSkipAccountConnection) { - RepositoryProviderComboBox.SelectedValue = AddRepoViewModel.ProviderNames[0]; - SwitchToRepoPage(AddRepoViewModel.ProviderNames[0]); + ChangeToRepoPage().Wait(); + return; } + /* + *Don't know why this is here. Remove if not needed. SwitchViewsSegmentedView.IsEnabled = true; - ToggleCloneButton(); */ Log.Logger?.ReportInfo(Log.Component.RepoConfig, "Changing to Account page"); @@ -617,21 +653,20 @@ public void ChangeToAccountPage() PrimaryButtonText = _stringResource.GetLocalized(StringResourceKey.RepoAccountPagePrimaryButtonText); ShouldShowLoginUi = false; - // List of extensions needs to be refreshed before accessing - GetExtensions(); - if (ProviderNames.Count == 1) - { - _providers.StartIfNotRunning(ProviderNames[0]); - var accounts = _providers.GetAllLoggedInAccounts(ProviderNames[0]); - if (accounts.Count() == 1) - { - CanSkipAccountConnection = true; - } - } + ToggleCloneButton(); } - public void ChangeToRepoPage() + public async Task ChangeToRepoPage() { + await GetAccountsAsync(_selectedRepoProvider, LoginUiContent); + if (Accounts.Any()) + { + FolderPickerViewModel.ShowFolderPicker(); + EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); + SelectedAccount = Accounts.First(); + ShouldEnablePrimaryButton = false; + } + Log.Logger?.ReportInfo(Log.Component.RepoConfig, "Changing to Repo page"); ShowUrlPage = Visibility.Collapsed; ShowAccountPage = Visibility.Collapsed; @@ -851,7 +886,7 @@ private void ValidateUriAndChangeUiIfBad(string url, out Uri uri) /// If ShouldShowUrlError == Visible the repo is not added to the list of repos to clone. /// /// The location to clone the repo to - public void AddRepositoryViaUri(string url, string cloneLocation, Frame loginFrame) + public void AddRepositoryViaUri(string url, string cloneLocation) { ShouldEnablePrimaryButton = false; Uri uri = null; @@ -866,7 +901,7 @@ public void AddRepositoryViaUri(string url, string cloneLocation, Frame loginFra // Causing GetCloningInformationFromURL to fall back to git. var provider = _providers.CanAnyProviderSupportThisUri(uri); - var cloningInformation = GetCloningInformationFromUrl(provider, cloneLocation, uri, loginFrame); + var cloningInformation = GetCloningInformationFromUrl(provider, cloneLocation, uri, LoginUiContent); if (cloningInformation == null) { // Error information is already set. diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index 01a1c04a40..e7fffe37d1 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -74,7 +74,7 @@ - + @@ -88,7 +88,7 @@ - + diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs index 18eb9ae087..8d79426213 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs @@ -126,40 +126,13 @@ await Task.Run(() => }); } - private void ChangeToAccountPage() - { - AddRepoViewModel.ChangeToAccountPage(); - AddRepoViewModel.FolderPickerViewModel.CloseFolderPicker(); - AddRepoViewModel.EditDevDriveViewModel.HideDevDriveUI(); - - // If DevHome has 1 provider installed and the provider has 1 logged in account - // switch to the repo page. - if (AddRepoViewModel.CanSkipAccountConnection) - { - RepositoryProviderComboBox.SelectedValue = AddRepoViewModel.ProviderNames[0]; - SwitchToRepoPage(AddRepoViewModel.ProviderNames[0]); - } - - SwitchViewsSegmentedView.IsEnabled = true; - ToggleCloneButton(); - } - - private void ChangeToUrlPage() - { - RepositoryProviderComboBox.SelectedIndex = -1; - AddRepoViewModel.ChangeToUrlPage(); - AddRepoViewModel.FolderPickerViewModel.ShowFolderPicker(); - AddRepoViewModel.EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); - ToggleCloneButton(); - } - /// /// Open up the folder picker for choosing a clone location. /// private async void ChooseCloneLocationButton_Click(object sender, RoutedEventArgs e) { await AddRepoViewModel.FolderPickerViewModel.ChooseCloneLocation(); - ToggleCloneButton(); + AddRepoViewModel.ToggleCloneButton(); } /// @@ -182,7 +155,7 @@ private void CloneLocation_TextChanged(object sender, TextChangedEventArgs e) AddRepoViewModel.FolderPickerViewModel.ValidateCloneLocation(); - ToggleCloneButton(); + AddRepoViewModel.ToggleCloneButton(); } /// @@ -229,16 +202,7 @@ private void RepositoriesListView_SelectionChanged(object sender, SelectionChang var providerName = (string)RepositoryProviderComboBox.SelectedValue; AddRepoViewModel.AddOrRemoveRepository(providerName, loginId, e.AddedItems, e.RemovedItems); - ToggleCloneButton(); - } - - /// - /// Gets the frame used for logging in a user. This can go away when the frame is moved to the view model. - /// - /// The frame used to log users in. - public Frame GetLoginUiContent() - { - return LoginUIContent; + AddRepoViewModel.ToggleCloneButton(); } /// @@ -260,7 +224,7 @@ private async void AddRepoContentDialog_PrimaryButtonClick(ContentDialog sender, // Get the number of repos already selected to clone in a previous instance. // Used to figure out if the repo was added after the user logged into an account. var numberOfReposToCloneCount = AddRepoViewModel.EverythingToClone.Count; - AddRepoViewModel.AddRepositoryViaUri(AddRepoViewModel.Url, AddRepoViewModel.FolderPickerViewModel.CloneLocation, LoginUIContent); + AddRepoViewModel.AddRepositoryViaUri(AddRepoViewModel.Url, AddRepoViewModel.FolderPickerViewModel.CloneLocation); // On the first run, ignore any warnings. // If this is set to visible and the user needs to log in they'll see an error message after the log-in @@ -301,7 +265,7 @@ private async void AddRepoContentDialog_PrimaryButtonClick(ContentDialog sender, // and the number of repos to clone will not be changed. if (numberOfReposToCloneCount == AddRepoViewModel.EverythingToClone.Count) { - AddRepoViewModel.AddRepositoryViaUri(AddRepoViewModel.Url, AddRepoViewModel.FolderPickerViewModel.CloneLocation, LoginUIContent); + AddRepoViewModel.AddRepositoryViaUri(AddRepoViewModel.Url, AddRepoViewModel.FolderPickerViewModel.CloneLocation); } if (AddRepoViewModel.ShouldShowUrlError == Visibility.Visible) @@ -319,24 +283,13 @@ private async void AddRepoContentDialog_PrimaryButtonClick(ContentDialog sender, var repositoryProviderName = (string)RepositoryProviderComboBox.SelectedItem; if (!string.IsNullOrEmpty(repositoryProviderName)) { - SwitchToRepoPage(repositoryProviderName); + var deferral = args.GetDeferral(); + await AddRepoViewModel.ChangeToRepoPage(); + deferral.Complete(); } } } - private async void SwitchToRepoPage(string repositoryProviderName) - { - await AddRepoViewModel.GetAccountsAsync(repositoryProviderName, LoginUIContent); - if (AddRepoViewModel.Accounts.Any()) - { - AddRepoViewModel.ChangeToRepoPage(); - AddRepoViewModel.FolderPickerViewModel.ShowFolderPicker(); - AddRepoViewModel.EditDevDriveViewModel.ShowDevDriveUIIfEnabled(); - AddRepoViewModel.SelectedAccount = AddRepoViewModel.Accounts.First(); - AddRepoViewModel.ShouldEnablePrimaryButton = false; - } - } - /// /// Adds or removes the default dev drive. This dev drive will be made at the loading screen. /// @@ -367,27 +320,7 @@ private void MakeNewDevDriveCheckBox_Click(object sender, RoutedEventArgs e) private async void CustomizeDevDriveHyperlinkButton_ClickAsync(object sender, RoutedEventArgs e) { await AddRepoViewModel.EditDevDriveViewModel.PopDevDriveCustomizationAsync(); - ToggleCloneButton(); - } - - /// - /// Toggles the clone button. Make sure other view models have correct information. - /// - private void ToggleCloneButton() - { - var isEverythingGood = AddRepoViewModel.ValidateRepoInformation() && AddRepoViewModel.FolderPickerViewModel.ValidateCloneLocation(); - if (AddRepoViewModel.EditDevDriveViewModel.DevDrive != null && AddRepoViewModel.EditDevDriveViewModel.DevDrive.State != DevDriveState.ExistsOnSystem) - { - isEverythingGood &= AddRepoViewModel.EditDevDriveViewModel.IsDevDriveValid(); - } - - AddRepoViewModel.ShouldEnablePrimaryButton = isEverythingGood; - - // Fill in EverythingToClone with the location - if (isEverythingGood) - { - AddRepoViewModel.SetCloneLocation(AddRepoViewModel.FolderPickerViewModel.CloneLocation); - } + AddRepoViewModel.ToggleCloneButton(); } private void RepoUrlTextBox_TextChanged(object sender, RoutedEventArgs e) @@ -398,19 +331,7 @@ private void RepoUrlTextBox_TextChanged(object sender, RoutedEventArgs e) AddRepoViewModel.Url = (sender as TextBox).Text; } - ToggleCloneButton(); - } - - private void Segmented_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - if (AddRepoViewModel.CurrentPage == PageKind.AddViaUrl) - { - ChangeToAccountPage(); - } - else - { - ChangeToUrlPage(); - } + AddRepoViewModel.ToggleCloneButton(); } /// From e5a4b717aa184465187686ae0514796e8f3d505c Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Fri, 16 Feb 2024 14:41:53 -0800 Subject: [PATCH 03/16] Changing visibility to bool. --- .../AddRepoDialogTests.cs | 4 +- .../Models/RepositoryProvider.cs | 2 +- .../ViewModels/AddRepoViewModel.cs | 67 +++++++++---------- .../Views/AddRepoDialog.xaml.cs | 9 +-- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs index 9e686caf69..b5f6d63758 100644 --- a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs +++ b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs @@ -29,7 +29,7 @@ public void HideRetryBannerTest() [TestMethod] public void SwitchToUrlScreenTest() { - var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), string.Empty, null, TestHost.GetService()); + var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), null, TestHost.GetService()); addRepoViewModel.ChangeToUrlPage(); Assert.AreEqual(Visibility.Visible, addRepoViewModel.ShowUrlPage); Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowAccountPage); @@ -42,7 +42,7 @@ public void SwitchToUrlScreenTest() [TestMethod] public void SwitchToRepoScreenTest() { - var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), string.Empty, null, TestHost.GetService()); + var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), null, TestHost.GetService()); addRepoViewModel.ChangeToRepoPage().Wait(); Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowUrlPage); Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowAccountPage); diff --git a/tools/SetupFlow/DevHome.SetupFlow/Models/RepositoryProvider.cs b/tools/SetupFlow/DevHome.SetupFlow/Models/RepositoryProvider.cs index 87137cd410..7fe0b8ff5a 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Models/RepositoryProvider.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Models/RepositoryProvider.cs @@ -38,7 +38,7 @@ internal sealed class RepositoryProvider /// /// Dictionary with all the repositories per account. /// - private Dictionary> _repositories = new(); + private readonly Dictionary> _repositories = new(); /// /// The DeveloperId provider used to log a user into an account. diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 6daa53a010..acbe22041c 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -146,25 +146,25 @@ public List EverythingToClone /// Should the URL page be visible? /// [ObservableProperty] - private Visibility _showUrlPage; + private bool _showUrlPage; /// /// Should the account page be visible? /// [ObservableProperty] - private Visibility _showAccountPage; + private bool _showAccountPage; /// /// Should the repositories page be visible? /// [ObservableProperty] - private Visibility _showRepoPage; + private bool _showRepoPage; /// /// Should the error text be shown? /// [ObservableProperty] - private Visibility _showErrorTextBox; + private bool _showErrorTextBox; /// /// Keeps track of if the account button is checked. Used to switch UIs @@ -190,7 +190,7 @@ public List EverythingToClone public bool IsAccountComboBoxEnabled => Accounts.Count > 1; [ObservableProperty] - private Visibility _shouldShowUrlError; + private bool _shouldShowUrlError; [ObservableProperty] private bool _isFetchingRepos; @@ -466,14 +466,14 @@ private async Task AddAccountClicked() _previouslySelectedRepos.AddRange(EverythingToClone); } - ShowRepoPage = Visibility.Collapsed; + ShowRepoPage = false; // Store the logged in accounts to help figure out what account the user logged into. var loggedInAccounts = await Task.Run(() => _providers.GetAllLoggedInAccounts(_selectedRepoProvider)); await LogUserIn(_selectedRepoProvider, LoginUiContent, true); var loggedInAccountsWithNewAccount = await Task.Run(() => _providers.GetAllLoggedInAccounts(_selectedRepoProvider)); - ShowRepoPage = Visibility.Visible; + ShowRepoPage = true; Accounts = new ObservableCollection(loggedInAccountsWithNewAccount.Select(x => x.LoginId)); AccountsToShow = ConstructFlyout(); @@ -509,7 +509,6 @@ public AddRepoViewModel( List previouslySelectedRepos, IHost host, Guid activityId, - string defaultClonePath, AddRepoDialog addRepoDialog, IDevDriveManager devDriveManager) { @@ -521,6 +520,9 @@ public AddRepoViewModel( EverythingToClone = new List(_previouslySelectedRepos); _activityId = activityId; FolderPickerViewModel = new FolderPickerViewModel(stringResource); + + var userFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + var defaultClonePath = Path.Join(userFolder, "source", "repos"); FolderPickerViewModel.CloneLocation = defaultClonePath; EditDevDriveViewModel = new EditDevDriveViewModel(devDriveManager); @@ -535,8 +537,8 @@ public AddRepoViewModel( // override changes ChangeToUrlPage to correctly set the state. UrlParsingError = string.Empty; - ShouldShowUrlError = Visibility.Collapsed; - ShowErrorTextBox = Visibility.Collapsed; + ShouldShowUrlError = false; + ShowErrorTextBox = false; } /// @@ -593,16 +595,12 @@ public void SetChangedEvents(TypedEventHandler x.RepositoryToClone.OwningAccountName.Equals(cloningInformation.RepositoryToClone.OwningAccountName, StringComparison.OrdinalIgnoreCase) && x.RepositoryToClone.DisplayName.Equals(cloningInformation.RepositoryToClone.DisplayName, StringComparison.OrdinalIgnoreCase))) { UrlParsingError = _stringResource.GetLocalized(StringResourceKey.UrlValidationRepoAlreadyAdded); - ShouldShowUrlError = Visibility.Visible; + ShouldShowUrlError = true; Log.Logger?.ReportInfo(Log.Component.RepoConfig, "Repository has already been added."); TelemetryFactory.Get().LogCritical("RepoTool_RepoAlreadyAdded_Event", false, _activityId); return; @@ -926,7 +925,7 @@ public void AddRepositoryViaUri(string url, string cloneLocation) EverythingToClone.Add(cloningInformation); ShouldEnablePrimaryButton = true; - ShouldShowUrlError = Visibility.Collapsed; + ShouldShowUrlError = false; } /// @@ -987,7 +986,7 @@ private CloningInformation GetCloningInformationFromUrl(RepositoryProvider provi // Should have a better error string. // TODO: Figure out a better error message? UrlParsingError = _stringResource.GetLocalized(StringResourceKey.UrlNoAccountsHaveAccess); - ShouldShowUrlError = Visibility.Visible; + ShouldShowUrlError = true; InitiateAddAccountUserExperienceAsync(provider, loginFrame); return null; @@ -999,7 +998,7 @@ private CloningInformation GetCloningInformationFromUrl(RepositoryProvider provi // Because DevHome cannot tell if a repo is private, or does not exist, prompt the user to log in. // Only ask if DevHome hasn't asked already. UrlParsingError = _stringResource.GetLocalized(StringResourceKey.UrlNoAccountsHaveAccess); - ShouldShowUrlError = Visibility.Visible; + ShouldShowUrlError = true; IsLoggingIn = true; InitiateAddAccountUserExperienceAsync(provider, loginFrame); return null; diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs index 8d79426213..7c7babe437 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs @@ -57,10 +57,7 @@ public AddRepoDialog( this.InitializeComponent(); _previouslySelectedRepos = previouslySelectedRepos; - var userFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); - var defaultClonePath = Path.Join(userFolder, "source", "repos"); - - AddRepoViewModel = new AddRepoViewModel(stringResource, previouslySelectedRepos, host, activityId, defaultClonePath, this, devDriveManager); + AddRepoViewModel = new AddRepoViewModel(stringResource, previouslySelectedRepos, host, activityId, this, devDriveManager); // Changing view to account so the selection changed event for Segment correctly shows URL. AddRepoViewModel.CurrentPage = PageKind.AddViaAccount; @@ -229,7 +226,7 @@ private async void AddRepoContentDialog_PrimaryButtonClick(ContentDialog sender, // On the first run, ignore any warnings. // If this is set to visible and the user needs to log in they'll see an error message after the log-in // prompt exits even if they logged in successfully. - AddRepoViewModel.ShouldShowUrlError = Visibility.Collapsed; + AddRepoViewModel.ShouldShowUrlError = false; // Get deferral to prevent the dialog from closing when awaiting operations. var deferral = args.GetDeferral(); @@ -268,7 +265,7 @@ private async void AddRepoContentDialog_PrimaryButtonClick(ContentDialog sender, AddRepoViewModel.AddRepositoryViaUri(AddRepoViewModel.Url, AddRepoViewModel.FolderPickerViewModel.CloneLocation); } - if (AddRepoViewModel.ShouldShowUrlError == Visibility.Visible) + if (AddRepoViewModel.ShouldShowUrlError) { AddRepoViewModel.ShouldEnablePrimaryButton = false; args.Cancel = true; From 40199f2396d0493017b378dd7e6fe66cb2ff7276 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Tue, 20 Feb 2024 10:45:00 -0800 Subject: [PATCH 04/16] More changes --- common/DevHome.Common.csproj | 2 +- .../ViewModels/AddRepoViewModel.cs | 26 ++++++++++++++++- .../Views/AddRepoDialog.xaml | 16 ++++++++-- .../Views/AddRepoDialog.xaml.cs | 29 ------------------- .../Views/RepoConfigView.xaml.cs | 2 +- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/common/DevHome.Common.csproj b/common/DevHome.Common.csproj index c394c4260b..7220843fc7 100644 --- a/common/DevHome.Common.csproj +++ b/common/DevHome.Common.csproj @@ -27,7 +27,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index acbe22041c..8c0f054f36 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -418,6 +418,13 @@ public void SortRepos(string sortMethod) Repositories = new IncrementalLoadingCollection(indexer); } + [RelayCommand] + private async Task OpenFolderPicker() + { + await FolderPickerViewModel.ChooseCloneLocation(); + ToggleCloneButton(); + } + /// /// Makes the MenuFlyout object used to display multple accounts in the repo tool. /// @@ -651,7 +658,6 @@ public void ChangeToAccountPage() CurrentPage = PageKind.AddViaAccount; PrimaryButtonText = _stringResource.GetLocalized(StringResourceKey.RepoAccountPagePrimaryButtonText); ShouldShowLoginUi = false; - ToggleCloneButton(); } @@ -1004,6 +1010,24 @@ private CloningInformation GetCloningInformationFromUrl(RepositoryProvider provi return null; } + /// + /// Sets up the UI for dev drives. + /// + public async Task SetupDevDrivesAsync() + { + await Task.Run(() => + { + EditDevDriveViewModel.SetUpStateIfDevDrivesIfExists(); + + if (EditDevDriveViewModel.DevDrive != null && + EditDevDriveViewModel.DevDrive.State == DevDriveState.ExistsOnSystem) + { + FolderPickerViewModel.InDevDriveScenario = true; + EditDevDriveViewModel.ClonePathUpdated(); + } + }); + } + /// /// Launches the login experience for the provided provider. /// diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index e7fffe37d1..c8e83875a2 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -65,7 +65,13 @@ - + @@ -183,7 +189,13 @@ - diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs index 7c7babe437..8374760cef 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs @@ -3,11 +3,9 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using DevHome.Common.Extensions; -using DevHome.Common.Models; using DevHome.Common.Services; using DevHome.SetupFlow.Models; using DevHome.SetupFlow.Services; @@ -105,33 +103,6 @@ public void DeveloperIdChangedEventHandler(object sender, IDeveloperId developer } } - /// - /// Sets up the UI for dev drives. - /// - public async Task SetupDevDrivesAsync() - { - await Task.Run(() => - { - AddRepoViewModel.EditDevDriveViewModel.SetUpStateIfDevDrivesIfExists(); - - if (AddRepoViewModel.EditDevDriveViewModel.DevDrive != null && - AddRepoViewModel.EditDevDriveViewModel.DevDrive.State == DevDriveState.ExistsOnSystem) - { - AddRepoViewModel.FolderPickerViewModel.InDevDriveScenario = true; - AddRepoViewModel.EditDevDriveViewModel.ClonePathUpdated(); - } - }); - } - - /// - /// Open up the folder picker for choosing a clone location. - /// - private async void ChooseCloneLocationButton_Click(object sender, RoutedEventArgs e) - { - await AddRepoViewModel.FolderPickerViewModel.ChooseCloneLocation(); - AddRepoViewModel.ToggleCloneButton(); - } - /// /// Validate the user put in a rooted, non-null path. /// diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/RepoConfigView.xaml.cs b/tools/SetupFlow/DevHome.SetupFlow/Views/RepoConfigView.xaml.cs index a236cf9c35..9d76b21125 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/RepoConfigView.xaml.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/RepoConfigView.xaml.cs @@ -68,7 +68,7 @@ private async Task AddRepoAsync() _addRepoDialog = new AddRepoDialog(ViewModel.DevDriveManager, ViewModel.LocalStringResource, ViewModel.RepoReviewItems.ToList(), ActivityId, ViewModel.Host); var getExtensionsTask = _addRepoDialog.GetExtensionsAsync(); - var setupDevDrivesTask = _addRepoDialog.SetupDevDrivesAsync(); + var setupDevDrivesTask = _addRepoDialog.AddRepoViewModel.SetupDevDrivesAsync(); _addRepoDialog.XamlRoot = RepoConfigGrid.XamlRoot; _addRepoDialog.RequestedTheme = ActualTheme; From d9e5151c68959ece5515dd6943ee53b2298804df Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Tue, 20 Feb 2024 10:57:20 -0800 Subject: [PATCH 05/16] Account combobox is reset. --- .../DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs | 6 ++++++ tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 8c0f054f36..433fb45b1a 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -378,6 +378,9 @@ private void CancelButtonPressed() [ObservableProperty] private Frame _loginUiContent; + [ObservableProperty] + private int _accountIndex; + /// /// Switches the repos shown to the account selected. /// @@ -546,6 +549,7 @@ public AddRepoViewModel( UrlParsingError = string.Empty; ShouldShowUrlError = false; ShowErrorTextBox = false; + _accountIndex = -1; } /// @@ -619,6 +623,8 @@ public void ChangeToUrlPage() public void ChangeToAccountPage() { + AccountIndex = -1; + // List of extensions needs to be refreshed before accessing GetExtensions(); if (ProviderNames.Count == 1) diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index c8e83875a2..36d6bafa84 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -70,7 +70,7 @@ HorizontalAlignment="Stretch" x:Uid="ms-resource:///DevHome.SetupFlow/Resources/RepositoryDisplay" ItemsSource="{x:Bind AddRepoViewModel.ProviderNames}" - SelectedItem="{x:Bind AddRepoViewModel.SelectedRepoProvider, Mode=TwoWay}" + SelectedIndex="{x:Bind AddRepoViewModel.AccountIndex, Mode=TwoWay}" Margin="0, 20, 0, 0" > From cc25daeede3ad75ba592380d73992d5512f5ecf5 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Tue, 20 Feb 2024 11:02:24 -0800 Subject: [PATCH 06/16] Adding some comments. --- .../ViewModels/AddRepoViewModel.cs | 15 ++++++++++++++- .../DevHome.SetupFlow/Views/AddRepoDialog.xaml | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 433fb45b1a..b9127335af 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -12,7 +12,6 @@ using CommunityToolkit.Mvvm.Input; using CommunityToolkit.WinUI.Collections; using CommunityToolkit.WinUI.Controls; -using DevHome.Common.Contracts; using DevHome.Common.Extensions; using DevHome.Common.Models; using DevHome.Common.Services; @@ -210,12 +209,20 @@ public List EverythingToClone [ObservableProperty] private bool _isCancelling; + /// + /// Used to figure out what button is pressed for the split button. + /// This determines the UI elements shown/hidden. + /// private enum SegmentedItemTag { Account, URL, } + /// + /// Hidex/Shows UI elements for the selected button. + /// + /// The button the user clicked on. [RelayCommand] public void ChangePage(SegmentedItem selectedItem) { @@ -375,9 +382,15 @@ private void CancelButtonPressed() [ObservableProperty] private MenuFlyout _accountsToShow; + /// + /// Used to show the login UI. + /// [ObservableProperty] private Frame _loginUiContent; + /// + /// Soley used to reset the account drop down when the account page is navigated to. + /// [ObservableProperty] private int _accountIndex; diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index 36d6bafa84..d5de4d6d74 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -65,6 +65,8 @@ + Date: Tue, 20 Feb 2024 11:31:26 -0800 Subject: [PATCH 07/16] Combobox placeholder --- .../Strings/en-us/Resources.resw | 12 ++++++ .../ViewModels/AddRepoViewModel.cs | 39 +++++++++++-------- .../Views/AddRepoDialog.xaml | 8 ++-- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw b/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw index 0215395b2c..014ea755a2 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw +++ b/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw @@ -1348,4 +1348,16 @@ This configuration unit was not run because an assert failed or was false. + + Sort + Placeholder for the sort combo box + + + Name Ascending + Shown as a repo sort option + + + Name Descending + Shown as a repo sort option + \ No newline at end of file diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index b9127335af..9a56b8b385 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -28,6 +28,7 @@ using Microsoft.UI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.Windows.DevHome.SDK; using Windows.Foundation; using WinUIEx; @@ -219,6 +220,16 @@ private enum SegmentedItemTag URL, } + /// + /// Compres against the tags in the sort order combo box. + /// Determines how to sort the repos. + /// + private enum SortMethod + { + NameAscending, + NameDescending, + } + /// /// Hidex/Shows UI elements for the selected button. /// @@ -411,26 +422,26 @@ private void MenuItemClick(string selectedItemName) } [RelayCommand] - public void SortRepos(string sortMethod) + public void SortRepos(ComboBox selectedItem) { - var repositories = new List(); - if (sortMethod.Equals("Name asending", StringComparison.OrdinalIgnoreCase)) + IEnumerable repositories = new List(); + var sortMethod = Enum.Parse(selectedItem.Tag.ToString()); + + if (sortMethod.Equals(SortMethod.NameAscending)) { repositories = _repositoriesForAccount - .OrderBy(x => Path.Join(x.OwningAccountName, x.DisplayName)) - .Select(x => new RepoViewListItem(x)) - .ToList(); + .OrderBy(x => Path.Join(x.OwningAccountName, x.DisplayName)); } - if (sortMethod.Equals("Name desending", StringComparison.OrdinalIgnoreCase)) + if (sortMethod.Equals(SortMethod.NameDescending)) { repositories = _repositoriesForAccount - .OrderByDescending(x => Path.Join(x.OwningAccountName, x.DisplayName)) - .Select(x => new RepoViewListItem(x)) - .ToList(); + .OrderByDescending(x => Path.Join(x.OwningAccountName, x.DisplayName)); } - var indexer = new IncrementalRepoViewItemViewModel(repositories); + var reposToShow = repositories.Select(x => new RepoViewListItem(x)).ToList(); + + var indexer = new IncrementalRepoViewItemViewModel(reposToShow); Repositories = new IncrementalLoadingCollection(indexer); } @@ -661,12 +672,6 @@ public void ChangeToAccountPage() return; } - /* - *Don't know why this is here. Remove if not needed. - * This was here in case they logged in. - SwitchViewsSegmentedView.IsEnabled = true; - */ - Log.Logger?.ReportInfo(Log.Component.RepoConfig, "Changing to Account page"); ShouldShowUrlError = false; ShowUrlPage = false; diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index d5de4d6d74..def5d5efad 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -65,7 +65,7 @@ - - + - Name asending - Name desending + + From 43f78f1087d8c7f4d3922a16569256d78c252905 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Tue, 20 Feb 2024 11:55:43 -0800 Subject: [PATCH 08/16] Final touches --- .../DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs | 3 +-- tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 9a56b8b385..2fc2ae5df4 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -28,7 +28,6 @@ using Microsoft.UI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.Windows.DevHome.SDK; using Windows.Foundation; using WinUIEx; @@ -422,7 +421,7 @@ private void MenuItemClick(string selectedItemName) } [RelayCommand] - public void SortRepos(ComboBox selectedItem) + public void SortRepos(TextBlock selectedItem) { IEnumerable repositories = new List(); var sortMethod = Enum.Parse(selectedItem.Tag.ToString()); diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index def5d5efad..398d631b37 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -27,6 +27,7 @@ + @@ -110,9 +111,9 @@ - + - + From 10ea64828027ba101ccce28921c832b6d9db05e7 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Tue, 20 Feb 2024 12:03:35 -0800 Subject: [PATCH 09/16] Fixing a comment. --- .../SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 2fc2ae5df4..3c726ac1c2 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -52,7 +52,7 @@ public partial class AddRepoViewModel : ObservableObject /// /// Because logic is split between the back-end and the view model, migrating code from the view - /// to the view model is impossible. + /// in one PR to the view model is too much work. /// This member is here to support this partial migration. Once all the code-behind logic is out of the view /// _addRepoDialog can be removed. /// From f777b279ed6464adc50fc66ceb7a963e2fcfe970 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Tue, 20 Feb 2024 12:06:59 -0800 Subject: [PATCH 10/16] Fixing SDk version --- common/DevHome.Common.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/DevHome.Common.csproj b/common/DevHome.Common.csproj index 2ab8c7f579..5ca7cc2426 100644 --- a/common/DevHome.Common.csproj +++ b/common/DevHome.Common.csproj @@ -27,7 +27,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From d4cbcd2df382102d963dca64b5c018b610f3bfb0 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Tue, 20 Feb 2024 12:30:29 -0800 Subject: [PATCH 11/16] Ignoring a test --- .../AddRepoDialogTests.cs | 17 +++++++++-------- .../BaseSetupFlowTest.cs | 3 +++ .../ViewModels/AddRepoViewModel.cs | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs index b5f6d63758..269fb6db83 100644 --- a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs +++ b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/AddRepoDialogTests.cs @@ -31,22 +31,23 @@ public void SwitchToUrlScreenTest() { var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), null, TestHost.GetService()); addRepoViewModel.ChangeToUrlPage(); - Assert.AreEqual(Visibility.Visible, addRepoViewModel.ShowUrlPage); - Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowAccountPage); - Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowRepoPage); + Assert.AreEqual(true, addRepoViewModel.ShowUrlPage); + Assert.AreEqual(false, addRepoViewModel.ShowAccountPage); + Assert.AreEqual(false, addRepoViewModel.ShowRepoPage); Assert.IsTrue(addRepoViewModel.IsUrlAccountButtonChecked); Assert.IsFalse(addRepoViewModel.IsAccountToggleButtonChecked); Assert.IsFalse(addRepoViewModel.ShouldShowLoginUi); } [TestMethod] - public void SwitchToRepoScreenTest() + [Ignore("IextensionService uses Application.Current and tests break when Application.Current is used. Ignore until fixed.")] + public void SwitchToAccountScreenTest() { var addRepoViewModel = new AddRepoViewModel(TestHost.GetService(), new List(), TestHost, Guid.NewGuid(), null, TestHost.GetService()); - addRepoViewModel.ChangeToRepoPage().Wait(); - Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowUrlPage); - Assert.AreEqual(Visibility.Collapsed, addRepoViewModel.ShowAccountPage); - Assert.AreEqual(Visibility.Visible, addRepoViewModel.ShowRepoPage); + addRepoViewModel.ChangeToAccountPage(); + Assert.AreEqual(false, addRepoViewModel.ShowUrlPage); + Assert.AreEqual(true, addRepoViewModel.ShowAccountPage); + Assert.AreEqual(false, addRepoViewModel.ShowRepoPage); Assert.IsFalse(addRepoViewModel.ShouldShowLoginUi); } } diff --git a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs index 717be7e0b8..6cfcab344d 100644 --- a/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs +++ b/tools/SetupFlow/DevHome.SetupFlow.UnitTest/BaseSetupFlowTest.cs @@ -3,6 +3,7 @@ using DevHome.Common.Services; using DevHome.Contracts.Services; +using DevHome.Services; using DevHome.SetupFlow.Common.WindowsPackageManager; using DevHome.SetupFlow.Services; using DevHome.SetupFlow.ViewModels; @@ -58,12 +59,14 @@ private IHost CreateTestHost() services.AddSingleton(ThemeSelectorService!.Object); services.AddSingleton(StringResource.Object); services.AddSingleton(new SetupFlowOrchestrator()); + services.AddSingleton(new ExtensionService()); // App-management view models services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); // App-management services services.AddSingleton(WindowsPackageManager.Object); diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 3c726ac1c2..7fdf63a065 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -604,7 +604,7 @@ public void ToggleCloneButton() public void GetExtensions() { Log.Logger?.ReportInfo(Log.Component.RepoConfig, "Getting installed extensions with Repository and DevId providers"); - var extensionService = Application.Current.GetService(); + var extensionService = _host.GetService(); var extensionWrappers = extensionService.GetInstalledExtensionsAsync().Result; var extensions = extensionWrappers.Where( From a2f1cde24acbcfb43213b8aeae1d05e72e44ea58 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Wed, 21 Feb 2024 12:13:31 -0800 Subject: [PATCH 12/16] Update tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs Co-authored-by: Kristen Schau <47155823+krschau@users.noreply.github.com> --- .../SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 7fdf63a065..44fda9d9db 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -399,7 +399,7 @@ private void CancelButtonPressed() private Frame _loginUiContent; /// - /// Soley used to reset the account drop down when the account page is navigated to. + /// Solely used to reset the account drop down when the account page is navigated to. /// [ObservableProperty] private int _accountIndex; From aaa51050779fc62b199bf664278e39ab4b26ed98 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Wed, 21 Feb 2024 12:24:49 -0800 Subject: [PATCH 13/16] Update tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs Co-authored-by: Kristen Schau <47155823+krschau@users.noreply.github.com> --- .../SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 44fda9d9db..11085f326c 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -684,7 +684,7 @@ public void ChangeToAccountPage() ToggleCloneButton(); } - public async Task ChangeToRepoPage() + public async Task ChangeToRepoPageAsync() { await GetAccountsAsync(_selectedRepoProvider, LoginUiContent); if (Accounts.Any()) From 576c0f3dfb1aedfc8332f590329930532076cf52 Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Wed, 21 Feb 2024 12:40:16 -0800 Subject: [PATCH 14/16] Update tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml Co-authored-by: Kristen Schau <47155823+krschau@users.noreply.github.com> --- tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index 398d631b37..31541820fb 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -71,7 +71,7 @@ From d7c3363ddcf325128c495f906ab9c34cc929bcbf Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Wed, 21 Feb 2024 12:40:56 -0800 Subject: [PATCH 15/16] Changes --- .../Strings/en-us/Resources.resw | 2 +- .../ViewModels/AddRepoViewModel.cs | 24 +++++++++++++++---- .../IncrementalRepoViewItemViewModel.cs | 22 +++++++---------- .../Views/AddRepoDialog.xaml | 4 ++-- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw b/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw index 014ea755a2..49c4bcffce 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw +++ b/tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw @@ -1349,7 +1349,7 @@ This configuration unit was not run because an assert failed or was false. - Sort + Sort by Placeholder for the sort combo box diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index 7fdf63a065..3e62444739 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -220,7 +220,7 @@ private enum SegmentedItemTag } /// - /// Compres against the tags in the sort order combo box. + /// Compares against the tags in the sort order combo box. /// Determines how to sort the repos. /// private enum SortMethod @@ -230,13 +230,21 @@ private enum SortMethod } /// - /// Hidex/Shows UI elements for the selected button. + /// Hides/Shows UI elements for the selected button. /// /// The button the user clicked on. [RelayCommand] public void ChangePage(SegmentedItem selectedItem) { - var pageToGoTo = Enum.Parse(selectedItem.Tag.ToString()); + if (selectedItem.Tag == null) + { + return; + } + + if (!Enum.TryParse(selectedItem.Tag.ToString(), out var pageToGoTo)) + { + return; + } if (pageToGoTo == SegmentedItemTag.Account) { @@ -423,8 +431,16 @@ private void MenuItemClick(string selectedItemName) [RelayCommand] public void SortRepos(TextBlock selectedItem) { + if (selectedItem.Tag == null) + { + return; + } + IEnumerable repositories = new List(); - var sortMethod = Enum.Parse(selectedItem.Tag.ToString()); + if (!Enum.TryParse(selectedItem.Tag.ToString(), out var sortMethod)) + { + return; + } if (sortMethod.Equals(SortMethod.NameAscending)) { diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/IncrementalRepoViewItemViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/IncrementalRepoViewItemViewModel.cs index 1a560a867c..2632cd2312 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/IncrementalRepoViewItemViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/IncrementalRepoViewItemViewModel.cs @@ -29,21 +29,15 @@ public IncrementalRepoViewItemViewModel(List items) public async Task> GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default) { // Gets items from the collection according to pageIndex and pageSize parameters. - var result = (from p in _items - select p).Skip(pageIndex * pageSize).Take(pageSize); - - // Simulates a longer request... - // Make sure the list is still in order after a refresh, - // even if the first page takes longer to load - if (pageIndex == 0) - { - await Task.Delay(200, cancellationToken); - } - else + IEnumerable reposToReturn = new List(); + await Task.Run( + () => { - await Task.Delay(100, cancellationToken); - } + reposToReturn = (from p in _items + select p).Skip(pageIndex * pageSize).Take(pageSize); + }, + cancellationToken); - return result; + return reposToReturn; } } diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index 398d631b37..c05691e2a1 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -112,7 +112,7 @@ - + @@ -132,7 +132,7 @@ into the command. I tried converting this to use a command on SelectionChanged and pass SelectedItems into the command. I ran into issues because the viewmodel expects one repository at a time. Not a list. Another issue is .SelectRange() needs to be called to "select" repos when the dialog is opened more than once. --> - + From 608f3bfc20d4d4f256239a91a7d50ca8e30fc37d Mon Sep 17 00:00:00 2001 From: Darren Hoehna Date: Wed, 21 Feb 2024 12:44:59 -0800 Subject: [PATCH 16/16] Removing prefixes for uid --- .../ViewModels/AddRepoViewModel.cs | 4 +-- .../Views/AddRepoDialog.xaml | 36 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs index b374be000c..3e62444739 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs @@ -407,7 +407,7 @@ private void CancelButtonPressed() private Frame _loginUiContent; /// - /// Solely used to reset the account drop down when the account page is navigated to. + /// Soley used to reset the account drop down when the account page is navigated to. /// [ObservableProperty] private int _accountIndex; @@ -700,7 +700,7 @@ public void ChangeToAccountPage() ToggleCloneButton(); } - public async Task ChangeToRepoPageAsync() + public async Task ChangeToRepoPage() { await GetAccountsAsync(_selectedRepoProvider, LoginUiContent); if (Accounts.Any()) diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml index 54105ce64e..970d5c1c64 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml @@ -10,7 +10,7 @@ xmlns:ctControls="using:CommunityToolkit.WinUI.Controls" xmlns:models="using:DevHome.SetupFlow.Models" mc:Ignorable="d" - x:Uid="ms-resource:///DevHome.SetupFlow/Resources/CloneRepoDialog" + x:Uid="CloneRepoDialog" x:Name="AddRepoContentDialog" PrimaryButtonClick="AddRepoContentDialog_PrimaryButtonClick" IsPrimaryButtonEnabled="{x:Bind AddRepoViewModel.ShouldEnablePrimaryButton, Mode=OneWay}" @@ -52,13 +52,13 @@ - - + + - - + + - - + + @@ -132,9 +132,9 @@ into the command. I tried converting this to use a command on SelectionChanged and pass SelectedItems into the command. I ran into issues because the viewmodel expects one repository at a time. Not a list. Another issue is .SelectRange() needs to be called to "select" repos when the dialog is opened more than once. --> - + - + @@ -159,7 +159,7 @@ - + @@ -171,7 +171,7 @@ Grid.Column="0" Spacing="7"> + x:Uid="ClonePathForTextBlock" /> - - + -