Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactoring RepositoryForm Validators#2395
base:essentials-publish
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Unit, ProgressState> PublishRepository { get; private set; } | ||
| @@ -173,20 +173,22 @@ IObservable<ProgressState> 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) | ||
jcansdale marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .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; | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -25,8 +25,8 @@ public interface IRepositoryForm : IViewModel | ||
| /// dashes. | ||
| /// </summary> | ||
| string SafeRepositoryName { get; } | ||
| ReactivePropertyValidator<string> RepositoryNameValidator { get; } | ||
| ReactivePropertyValidator<string> SafeRepositoryNameWarningValidator { get; } | ||
| ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> RepositoryNameValidator { get; } | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the code, I can't see where we're using the I think we might be able to simplify this to use just the | ||
| ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> SafeRepositoryNameWarningValidator { get; } | ||
| string Description { get; set; } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should delete these comments!