From b457c95c070aa118e18c6d66e0057f2480b69d76 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 27 Jun 2019 13:10:01 -0400 Subject: [PATCH] Checking to see if the validators could be the problem --- src/GitHub.App/SampleData/SampleViewModels.cs | 4 +- .../Dialog/RepositoryCreationViewModel.cs | 29 ++++++----- .../ViewModels/RepositoryFormViewModel.cs | 4 +- .../RepositoryPublishViewModel.cs | 50 ++++++++++--------- .../ViewModels/IRepositoryForm.cs | 4 +- 5 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/GitHub.App/SampleData/SampleViewModels.cs b/src/GitHub.App/SampleData/SampleViewModels.cs index 77b36dc9c0..a20585e765 100644 --- a/src/GitHub.App/SampleData/SampleViewModels.cs +++ b/src/GitHub.App/SampleData/SampleViewModels.cs @@ -109,7 +109,7 @@ public string RepositoryName set; } - public ReactivePropertyValidator RepositoryNameValidator + public ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> SafeRepositoryNameWarningValidator { get; private set; @@ -127,7 +127,7 @@ public string SafeRepositoryName private set; } - public ReactivePropertyValidator SafeRepositoryNameWarningValidator + public ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> RepositoryNameValidator { get; private set; diff --git a/src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs b/src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs index e31758de75..4e89f9c653 100644 --- a/src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs +++ b/src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs @@ -72,22 +72,21 @@ public RepositoryCreationViewModel( .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters) .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid); - var nonNullRepositoryName = this.WhenAny( - x => x.RepositoryName, - x => x.BaseRepositoryPath, - (x, y) => x.Value) - .WhereNotNull(); - - RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName) - .IfNullOrEmpty(Resources.RepositoryNameValidatorEmpty) - .IfTrue(x => x.Length > 100, Resources.RepositoryNameValidatorTooLong) - .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists); - - SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName) - .Add(repoName => + var nameValidationConditions = this.WhenAny( + model => model.RepositoryName, + model => model.SelectedAccount, + (repositoryName, account) => (repositoryName: repositoryName.Value, connection: (IConnection) null, account: account.Value)) + .Where(tuple => tuple.repositoryName != null); + + RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nameValidationConditions) + .IfTrue(tuple => string.IsNullOrEmpty(tuple.repositoryName), Resources.RepositoryNameValidatorEmpty) + .IfTrue(tuple => tuple.repositoryName.Length > 100, Resources.RepositoryNameValidatorTooLong); + + SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nameValidationConditions) + .Add(tuple => { - var parsedReference = GetSafeRepositoryName(repoName); - return parsedReference != repoName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null; + var parsedReference = GetSafeRepositoryName(tuple.repositoryName); + return parsedReference != tuple.repositoryName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null; }); CreateRepository = InitializeCreateRepositoryCommand(); diff --git a/src/GitHub.App/ViewModels/RepositoryFormViewModel.cs b/src/GitHub.App/ViewModels/RepositoryFormViewModel.cs index bd69c9b141..2e2b1ef6ff 100644 --- a/src/GitHub.App/ViewModels/RepositoryFormViewModel.cs +++ b/src/GitHub.App/ViewModels/RepositoryFormViewModel.cs @@ -52,7 +52,7 @@ public string RepositoryName set { this.RaiseAndSetIfChanged(ref repositoryName, value); } } - public ReactivePropertyValidator RepositoryNameValidator { get; protected set; } + public ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> RepositoryNameValidator { get; protected set; } /// /// Name of the repository after fixing it to be safe (dashes instead of spaces, etc) @@ -62,7 +62,7 @@ public string SafeRepositoryName get { return safeRepositoryName.Value; } } - public ReactivePropertyValidator SafeRepositoryNameWarningValidator { get; protected set; } + public ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> SafeRepositoryNameWarningValidator { get; protected set; } IAccount selectedAccount; /// diff --git a/src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs b/src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs index 3ad6d48e30..120b25db43 100644 --- a/src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs +++ b/src/GitHub.App/ViewModels/TeamExplorer/RepositoryPublishViewModel.cs @@ -93,17 +93,17 @@ public RepositoryPublishViewModel( if (!string.IsNullOrEmpty(defaultRepositoryName)) RepositoryName = defaultRepositoryName; - this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount, - (a,b) => true) - .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null) - .Subscribe(async _ => - { - var name = RepositoryName; - RepositoryName = null; - await RepositoryNameValidator.ResetAsync(); - await SafeRepositoryNameWarningValidator.ResetAsync(); - RepositoryName = name; - }); +// this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount, +// (a,b) => true) +// .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null) +// .Subscribe(async _ => +// { +// var name = RepositoryName; +// RepositoryName = null; +// await RepositoryNameValidator.ResetAsync(); +// await SafeRepositoryNameWarningValidator.ResetAsync(); +// RepositoryName = name; +// }); } public ReactiveCommand PublishRepository { get; private set; } @@ -173,20 +173,22 @@ IObservable OnPublishRepository() void InitializeValidation() { - var nonNullRepositoryName = this.WhenAny( - x => x.RepositoryName, - x => x.Value) - .WhereNotNull(); - - RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName) - .IfNullOrEmpty(Resources.RepositoryNameValidatorEmpty) - .IfTrue(x => x.Length > 100, Resources.RepositoryNameValidatorTooLong); - - SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName) - .Add(repoName => + var nameValidationConditions = this.WhenAny(model => model.RepositoryName, + model => model.SelectedConnection, + model => model.SelectedAccount, + (repositoryName, connection, account) => (repositoryName: repositoryName.Value, + connection: connection.Value, account: account.Value)) + .Where(tuple => tuple.repositoryName != null); + + RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nameValidationConditions) + .IfTrue(tuple => string.IsNullOrEmpty(tuple.repositoryName), Resources.RepositoryNameValidatorEmpty) + .IfTrue(tuple => tuple.repositoryName.Length > 100, Resources.RepositoryNameValidatorTooLong); + + SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nameValidationConditions) + .Add(tuple => { - var parsedReference = GetSafeRepositoryName(repoName); - return parsedReference != repoName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null; + var parsedReference = GetSafeRepositoryName(tuple.repositoryName); + return parsedReference != tuple.repositoryName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null; }); } } diff --git a/src/GitHub.Exports.Reactive/ViewModels/IRepositoryForm.cs b/src/GitHub.Exports.Reactive/ViewModels/IRepositoryForm.cs index efb15369e7..5c351706a2 100644 --- a/src/GitHub.Exports.Reactive/ViewModels/IRepositoryForm.cs +++ b/src/GitHub.Exports.Reactive/ViewModels/IRepositoryForm.cs @@ -25,8 +25,8 @@ public interface IRepositoryForm : IViewModel /// dashes. /// string SafeRepositoryName { get; } - ReactivePropertyValidator RepositoryNameValidator { get; } - ReactivePropertyValidator SafeRepositoryNameWarningValidator { get; } + ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> RepositoryNameValidator { get; } + ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> SafeRepositoryNameWarningValidator { get; } string Description { get; set; }