Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Update (#156)
Browse files Browse the repository at this point in the history
Updated Null handling to fix Bug #146
Fixed Bug #152 (Thanks @conficient)
NuGet Update

Co-authored-by: Howard Richards <[email protected]>
  • Loading branch information
IvanJosipovic and conficient authored Jul 29, 2020
1 parent 626a154 commit c043117
Show file tree
Hide file tree
Showing 21 changed files with 393 additions and 329 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.202
dotnet-version: 3.1.x

- name: Dotnet Build
run: dotnet build -c Release
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.202
dotnet-version: 3.1.x

- name: Dotnet Build
run: dotnet build -c Release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.202
dotnet-version: 3.1.x

- name: Dotnet Pack
working-directory: src/BlazorTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable.Sample.Shared/Bugs/135.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
private PersonData[] data;

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
data = new PersonData[]
{
Expand Down
59 changes: 59 additions & 0 deletions src/BlazorTable.Sample.Shared/Bugs/146.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@page "/146"

@using BlazorTable

<Table TableItem="Root" Items="data" ShowSearchBar="true">
<Column TableItem="Root" Title="Data" Field="@(x => x.Child.Data)" Sortable="true" Filterable="true">
<Template>
@(context.Child != null ? context.Child.Data : string.Empty)
</Template>
</Column>
<Column TableItem="Root" Title="Data" Field="@(x => x.Child.Data)" Sortable="true" Filterable="true">
<Template>
@(context.Child != null ? context.Child.Data : string.Empty)
</Template>
</Column>
<Column TableItem="Root" Title="Data2" Field="@(x => x.Child.Data)" Sortable="true" Filterable="true" />
</Table>

@code
{
private Root[] data;

protected override void OnInitialized()
{
data = new Root[]
{
new Root()
{
Child = new Child(){ Data = "test1" }
},
new Root()
{
Child = new Child(){ Data = "test2" }
},
new Root()
{
Child = new Child(){ Data = "test3" }
},
new Root()
{
Child = new Child()
},
new Root()
{
Child = null
}
};
}

public class Root
{
public Child Child { get; set; }
}

public class Child
{
public string Data { get; set; }
}
}
31 changes: 31 additions & 0 deletions src/BlazorTable.Sample.Shared/Bugs/152.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@page "/152"

@using BlazorTable

<Table TableItem="PersonData" Items="data" ShowSearchBar="true" ShowFooter="true">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.ShortId)" Sortable="false" Filterable="true" SetFooterValue="Count" />
<DetailTemplate TableItem="PersonData">
@context.ShortId
</DetailTemplate>
</Table>

@code
{
private PersonData[] data;

protected override void OnInitialized()
{
data = new PersonData[]
{
new PersonData()
{
ShortId = 5
}
};
}

public class PersonData
{
public int ShortId { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/BlazorTable.Sample.Wasm/BlazorTable.Sample.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
77 changes: 77 additions & 0 deletions src/BlazorTable.Tests/AddNullChecks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Xunit;

namespace BlazorTable.Tests
{
public class AddNullChecks
{
[Fact]
public void AddToSingle()
{
Expression<Func<Parent, object>> Field = x => x.Child;
var exp = Field.Body.CreateNullChecks();
exp.ToString().ShouldBe("(x.Child != null)");
}

[Fact]
public void AddToMulti()
{
Expression<Func<Parent, object>> Field = x => x.Child.Name;
var exp = Field.Body.CreateNullChecks();
exp.ToString().ShouldBe("((x.Child != null) AndAlso (x.Child.Name != null))");
}

[Fact]
public void AddToMulti2()
{
Expression<Func<Parent, object>> Field = x => x.Child.GrandChild.Name;
var exp = Field.Body.CreateNullChecks();
exp.ToString().ShouldBe("(((x.Child != null) AndAlso (x.Child.GrandChild != null)) AndAlso (x.Child.GrandChild.Name != null))");
}

[Fact]
public void Skip()
{
Expression<Func<Parent, object>> Field = x => x.Child;
var exp = Field.Body.CreateNullChecks(true);
exp.ToString().ShouldBe("(x.Child != null)");
}

[Fact]
public void Skip2()
{
Expression<Func<Parent, object>> Field = x => x.Child.Name;
var exp = Field.Body.CreateNullChecks(true);
exp.ToString().ShouldBe("(x.Child != null)");
}

[Fact]
public void Skip3()
{
Expression<Func<Parent, object>> Field = x => x.Child.GrandChild.Name;
var exp = Field.Body.CreateNullChecks(true);
exp.ToString().ShouldBe("((x.Child != null) AndAlso (x.Child.GrandChild != null))");
}

private class Parent
{
public Child Child { get; set; }
}

private class Child
{
public string Name { get; set; }

public GrandChild GrandChild { get; set; }
}

private class GrandChild
{
public string Name { get; set; }
}
}
}
72 changes: 0 additions & 72 deletions src/BlazorTable.Tests/Bug104.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/BlazorTable/BlazorTable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

<ItemGroup>
<PackageReference Include="LINQKit.Core" Version="1.1.17" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.6" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
8 changes: 7 additions & 1 deletion src/BlazorTable/Components/Column.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,13 @@ public string Render(TableItem data)
if (renderCompiled == null)
renderCompiled = Field.Compile();

var value = renderCompiled.Invoke(data);
object value = null;

try
{
value = renderCompiled.Invoke(data);
}
catch (NullReferenceException){}

if (value == null) return string.Empty;

Expand Down
4 changes: 4 additions & 0 deletions src/BlazorTable/Components/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@
{
<tfoot class="@TableFooterClass">
<tr>
@if (_detailTemplate != null)
{
<td style="width: 1%"></td>
}
@foreach (IColumn<TableItem> column in Columns)
{
<td @key="column" style="@(column.Align > 0 ? $"text-align: {column.Align};" : "")" class="@(column.ColumnFooterClass)">
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorTable/Components/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private IEnumerable<TableItem> GetData()
{
if (item.Filter != null)
{
ItemsQueryable = ItemsQueryable.Where(item.Filter.AddNullChecks());
ItemsQueryable = ItemsQueryable.Where(item.Filter);
}
}

Expand Down Expand Up @@ -427,7 +427,7 @@ private Expression<Func<TableItem, bool>> GlobalSearchQuery(string value)
{
var newQuery = Expression.Lambda<Func<TableItem, bool>>(
Expression.AndAlso(
Expression.NotEqual(column.Field.Body, Expression.Constant(null)),
column.Field.Body.CreateNullChecks(),
Expression.GreaterThanOrEqual(
Expression.Call(
Expression.Call(column.Field.Body, "ToString", Type.EmptyTypes),
Expand Down
12 changes: 8 additions & 4 deletions src/BlazorTable/Filters/BooleanFilter.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,29 @@ public Expression<Func<TableItem, bool>> GetFilter()
BooleanCondition.True =>
Expression.Lambda<Func<TableItem, bool>>(
Expression.AndAlso(
Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Column.Field.Body.CreateNullChecks(),
Expression.IsTrue(Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()))),
Column.Field.Parameters),

BooleanCondition.False =>
Expression.Lambda<Func<TableItem, bool>>(
Expression.AndAlso(
Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Column.Field.Body.CreateNullChecks(),
Expression.IsFalse(Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()))),
Column.Field.Parameters),

BooleanCondition.IsNull =>
Expression.Lambda<Func<TableItem, bool>>(
Expression.Equal(Column.Field.Body, Expression.Constant(null)),
Expression.AndAlso(
Column.Field.Body.CreateNullChecks(true),
Expression.Equal(Column.Field.Body, Expression.Constant(null))),
Column.Field.Parameters),

BooleanCondition.IsNotNull =>
Expression.Lambda<Func<TableItem, bool>>(
Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.AndAlso(
Column.Field.Body.CreateNullChecks(true),
Expression.NotEqual(Column.Field.Body, Expression.Constant(null))),
Column.Field.Parameters),

_ => null,
Expand Down
Loading

0 comments on commit c043117

Please sign in to comment.