Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validations system refactor. #2223

Merged
merged 24 commits into from Sep 10, 2019
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Serialize then Deserialize via Converter the ErrorDescriptor as a wor…

…karound. Remove this hack when we update to Avalonia 0.9.
  • Loading branch information...
jmacato committed Sep 9, 2019
commit 11bad9dd8858a2dcaad4bd3f5937923ace7571c3
@@ -0,0 +1,31 @@
using Avalonia;
using Avalonia.Data.Converters;
using NBitcoin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using WalletWasabi.Models;

namespace WalletWasabi.Gui.Converters
{
public class ErrorDescriptorsJsonConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is IEnumerable<Exception> jsonStr)
{
return JsonConvert.DeserializeObject<ErrorDescriptors>(jsonStr.First().Message);
This conversation was marked as resolved by jmacato

This comment has been minimized.

Copy link
@danwalmsley

danwalmsley Sep 9, 2019

Collaborator

Why first? Could be more than 1 error / warning?

Shouldnt it convert them to a multiline string?

This comment has been minimized.

Copy link
@nopara73

nopara73 Sep 10, 2019

Collaborator

I think this was guiding his decision: #2204 (comment)

This comment has been minimized.

Copy link
@molnard

molnard Sep 10, 2019

Collaborator

IMO it is because of the Avalonia bug. Currently, @jmacato did a workaround to make it work but he has to follow the "old" solution where an array was passed and only the first element was passed to the View.

This comment has been minimized.

Copy link
@jmacato

jmacato Sep 10, 2019

Author Collaborator

I covered all my bases and processed all the exceptions instead of processing only the first one :)

}

return ErrorDescriptors.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}
@@ -1,7 +1,8 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dock="clr-namespace:Dock.Avalonia.Controls;assembly=Dock.Avalonia"
xmlns:shell="clr-namespace:AvalonStudio.Shell.Controls;assembly=AvalonStudio.Shell"
xmlns:shell="clr-namespace:AvalonStudio.Shell.Controls;assembly=AvalonStudio.Shell"
xmlns:converters="clr-namespace:WalletWasabi.Gui.Converters;assembly=WalletWasabi.Gui"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:controls="clr-namespace:WalletWasabi.Gui.Controls;assembly=WalletWasabi.Gui">
<Style>
@@ -20,6 +21,7 @@
<x:Uri>resm:WalletWasabi.Gui.Assets.*.ttf?assembly=WalletWasabi.Gui</x:Uri>
</x:Arguments>
</FontFamily>
<converters:ErrorDescriptorsJsonConverter x:Key="ErrorDescriptorsJsonConverter" />
</Style.Resources>
</Style>
<Style Selector="shell|MetroWindow /template/ Button#minimiseButton">
@@ -139,7 +141,7 @@
DockPanel.Dock="Bottom"
ContentTemplate="{TemplateBinding ErrorTemplate}"
DataContext="{TemplateBinding Owner}"
Content="{Binding (DataValidationErrors.Errors)}"
Content="{Binding (DataValidationErrors.Errors), Converter={StaticResource ErrorDescriptorsJsonConverter}}"
IsVisible="{Binding (DataValidationErrors.HasErrors)}" />
<ContentPresenter
Name="PART_ContentPresenter"
@@ -1,3 +1,4 @@
using Newtonsoft.Json;
using ReactiveUI;
using System;
using System.Collections;
@@ -30,12 +31,11 @@ public IEnumerable GetErrors(string propertyName)
{
var error = Validator.ValidateProperty(this, propertyName, ValidationMethodCache);

This conversation was marked as resolved by jmacato

This comment has been minimized.

Copy link
@yahiheb

yahiheb Sep 9, 2019

Collaborator

Empty line can be removed.

Suggested change
if (error.HasErrors)
{
return error.Select(p => p.Message);
}
if (!error.HasErrors) return null;

return ErrorDescriptors.Empty;
// HACK: Need to serialize this in order to pass through IndeiValidationPlugin on Avalonia 0.8.2.
// Should be removed when Avalonia has the hotfix update.
return new List<string>() { JsonConvert.SerializeObject(error) };
}

protected void NotifyErrorsChanged(string propertyName)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.