Skip to content

Commit

Permalink
Adding automation properties. Moving some code to the view model. (#3103
Browse files Browse the repository at this point in the history
)

* Adding automation properties.  Moving some code to the view model.

* Removing an unused addition

* Forgot to remove the comments

* Even more
  • Loading branch information
dhoehna authored Jun 5, 2024
1 parent 1822be5 commit 8a6ff56
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,8 @@
<value>More Options</value>
<comment>The text narrator should say for the ... button</comment>
</data>
<data name="SyncEnvironmentsButton.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Sync</value>
<comment>Accessible name for the button to sync environments.</comment>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@
</i:Interaction.Behaviors>
</ComboBox>
<!-- Sync button -->
<Button Command="{x:Bind ViewModel.SyncButtonCommand}" Margin="0 3 0 0">
<Button
x:Uid="SyncEnvironmentsButton"
Command="{x:Bind ViewModel.SyncButtonCommand}"
Margin="0 3 0 0">
<StackPanel Orientation="Horizontal" Padding="20 0" Spacing="8">
<FontIcon FontSize="16" FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE72C;"/>
<TextBlock x:Uid="SyncButtonTextBlock" />
Expand Down
55 changes: 55 additions & 0 deletions tools/SetupFlow/DevHome.SetupFlow/ViewModels/AddRepoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,52 @@ public AddRepoViewModel(
_accountIndex = -1;
}

/// <summary>
/// Handles logic when the primary button is clicked. Actions change depending on the screen
/// then user is on.
/// </summary>
/// <param name="searchTerms">The search terms for repositories.</param>
/// <returns>True if the close should be canceled. Otherwise false and the dialog will close.</returns>
public async Task<bool> PrimaryButtonClick(Dictionary<string, string> searchTerms)
{
if (CurrentPage == PageKind.AddViaUrl)
{
// 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 = EverythingToClone.Count;

await AddRepositoryViaUri(Url, FolderPickerViewModel.CloneLocation);

// If the repo was not added.
if (numberOfReposToCloneCount == EverythingToClone.Count)
{
ShouldEnablePrimaryButton = false;
return true;
}

return false;
}
else if (CurrentPage == PageKind.AddViaAccount)
{
if (!string.IsNullOrEmpty(_selectedRepoProvider))
{
await ChangeToRepoPageAsync();
}

return true;
}
else if (CurrentPage == PageKind.SearchFields)
{
// switching to the repo page causes repos to be queried.
await ChangeToRepoPageAsync();
SearchForRepos(searchTerms);

return true;
}

return false;
}

/// <summary>
/// Toggles the clone button. Make sure other view models have correct information.
/// </summary>
Expand Down Expand Up @@ -1019,9 +1065,18 @@ private async Task LogUserIn(string repositoryProviderName)
ShouldShowLoginUi = true;
IsCancelling = false;

// Store the close button text because it will change.
// The text of the secondary button of the content dialog changes to notify users
// to press the "X" button to cancel the login prompt.
// This is needed because the secondary button does not listen to events because
// the content dialog is in the middle of the Primary Button click event.
var closeButtonText = _addRepoDialog.CloseButtonText;
_addRepoDialog.CloseButtonText = _host.GetService<ISetupFlowStringResource>().GetLocalized(StringResourceKey.UrlCancelButtonText);

await InitiateAddAccountUserExperienceAsync(_providers.GetProvider(repositoryProviderName), LoginUiContent);

_addRepoDialog.CloseButtonText = closeButtonText;

ShouldShowLoginUi = false;
IsLoggingIn = false;
IsCancelling = true;
Expand Down
63 changes: 9 additions & 54 deletions tools/SetupFlow/DevHome.SetupFlow/Views/AddRepoDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,66 +160,21 @@ private void RepositoriesListView_SelectionChanged(object sender, SelectionChang
/// </summary>
private async void AddRepoContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
if (AddRepoViewModel.CurrentPage == PageKind.AddViaUrl)
{
// 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;

// If the user is logging in, the close button text will change.
// Keep a copy of the original to revert when this button click is done.
var originalCloseButtonText = AddRepoContentDialog.CloseButtonText;

var deferral = args.GetDeferral();
await AddRepoViewModel.AddRepositoryViaUri(AddRepoViewModel.Url, AddRepoViewModel.FolderPickerViewModel.CloneLocation);

AddRepoContentDialog.CloseButtonText = originalCloseButtonText;
var deferral = args.GetDeferral();

// If the repo was not added.
if (numberOfReposToCloneCount == AddRepoViewModel.EverythingToClone.Count)
{
AddRepoViewModel.ShouldEnablePrimaryButton = false;
args.Cancel = true;
deferral.Complete();
return;
}

deferral.Complete();
}
else if (AddRepoViewModel.CurrentPage == PageKind.AddViaAccount)
// Collect search inputs.
Dictionary<string, string> searchInput = new();
foreach (var searchBox in ShowingSearchTermsGrid.Children)
{
args.Cancel = true;
var repositoryProviderName = (string)RepositoryProviderComboBox.SelectedItem;
if (!string.IsNullOrEmpty(repositoryProviderName))
if (searchBox is AutoSuggestBox suggestBox)
{
var originalCloseButtonText = AddRepoContentDialog.CloseButtonText;

var deferral = args.GetDeferral();
await AddRepoViewModel.ChangeToRepoPageAsync();

AddRepoContentDialog.CloseButtonText = originalCloseButtonText;

deferral.Complete();
searchInput.Add(suggestBox.Header as string, suggestBox.Text);
}
}
else if (AddRepoViewModel.CurrentPage == PageKind.SearchFields)
{
args.Cancel = true;
Dictionary<string, string> searchInput = new();
foreach (var searchBox in ShowingSearchTermsGrid.Children)
{
if (searchBox is AutoSuggestBox suggestBox)
{
searchInput.Add(suggestBox.Header as string, suggestBox.Text);
}
}

// switching to the repo page causes repos to be queried.
var deferral = args.GetDeferral();
await AddRepoViewModel.ChangeToRepoPageAsync();
AddRepoViewModel.SearchForRepos(searchInput);
deferral.Complete();
}
args.Cancel = await AddRepoViewModel.PrimaryButtonClick(searchInput);

deferral.Complete();
}

/// <summary>
Expand Down

0 comments on commit 8a6ff56

Please sign in to comment.