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

Commit

Permalink
1.8.0 (#107)
Browse files Browse the repository at this point in the history
Improve component accessibility with aria attributes (#106) @LeonarddeR
Fix for colspan with DetailTemplate (#105) @smokedlinq
Fix for Filtering nullable inner object throws NRE [WASM] (#104)
Updated Sample to Blazor 3.2.0 Preview 4
  • Loading branch information
IvanJosipovic authored Apr 18, 2020
1 parent 60c070c commit 879b5f2
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ jobs:
dotnet-version: 3.1.201

- name: Dotnet Build
run: dotnet build --configuration Release
run: dotnet build -c Release

- name: Dotnet Test
run: dotnet test -c Release
7 changes: 5 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
- name: Dotnet Build
run: dotnet build -c Release

- name: Dotnet Test
run: dotnet test -c Release

- name: Dotnet Publish
working-directory: src/BlazorTable.Sample.Wasm
run: dotnet publish -c Release
Expand All @@ -42,7 +45,7 @@ jobs:

- name: Deploy to Test
id: netlify
uses: ivanjosipovic/actions/cli@master
uses: netlify/actions/cli@master
with:
args: deploy --json -d src/BlazorTable.Sample.Wasm/bin/Release/netstandard2.1/publish/wwwroot
env:
Expand All @@ -51,6 +54,6 @@ jobs:

- name: Get Test Address
run: |
$url = $(ConvertFrom-Json '${{ steps.netlify.outputs.output }}').deploy_url;
$url = '${{ steps.netlify.outputs.NETLIFY_URL }}';
Write-Output $url;
shell: pwsh
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
working-directory: src/BlazorTable
run: dotnet pack -c Release -p:Version=${{ steps.version.outputs.new_tag }}

- name: Dotnet Test
run: dotnet test --configuration Release

- name: Dotnet Nuget Push
if: "!contains(github.event.head_commit.message, '#skip')"
working-directory: src/BlazorTable/bin/Release
Expand Down
6 changes: 6 additions & 0 deletions BlazorTable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorTable.Sample.Server",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorTable.Sample.Shared", "src\BlazorTable.Sample.Shared\BlazorTable.Sample.Shared.csproj", "{25E8AB75-2F08-463E-8499-0C5BBB20BC50}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorTable.Tests", "src\BlazorTable.Tests\BlazorTable.Tests.csproj", "{64B71D26-A307-4541-9B17-BD6709211F21}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,6 +44,10 @@ Global
{25E8AB75-2F08-463E-8499-0C5BBB20BC50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25E8AB75-2F08-463E-8499-0C5BBB20BC50}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25E8AB75-2F08-463E-8499-0C5BBB20BC50}.Release|Any CPU.Build.0 = Release|Any CPU
{64B71D26-A307-4541-9B17-BD6709211F21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64B71D26-A307-4541-9B17-BD6709211F21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64B71D26-A307-4541-9B17-BD6709211F21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64B71D26-A307-4541-9B17-BD6709211F21}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-preview3.20175.8" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-preview5.20210.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorTable\BlazorTable.csproj" />
</ItemGroup>

<ItemGroup>
<Watch Include="..\**\*.razor" />
</ItemGroup>

</Project>
53 changes: 53 additions & 0 deletions src/BlazorTable.Sample.Shared/Bugs/104.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@page "/104"

@using BlazorTable

<h1>Issue #104</h1>

<Table TableItem="Parent" Items="items">
<Column TableItem="Parent" Title="Inner value" Field="@(x => x.Child.Name)" Sortable="true" Filterable="true">
<Template>
@if (@context?.Child?.Name == null)
{
<text>N/A</text>
}
else
{
@context.Child.Name
}
</Template>
</Column>
</Table>

@code
{
private List<Parent> items = new List<Parent>();

protected override void OnInitialized()
{
for (int i = 0; i < 5; i++)
{
items.Add(new Parent() { Name = i.ToString(), Child = new Child() { Name = i.ToString() } });
items.Add(new Parent() { Name = i.ToString() });
}
}

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

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; }
}
}
10 changes: 7 additions & 3 deletions src/BlazorTable.Sample.Wasm/BlazorTable.Sample.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview4.20210.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorTable.Sample.Shared\BlazorTable.Sample.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<Watch Include="..\**\*.razor" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion src/BlazorTable.Sample.Wasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http;
using System;

namespace BlazorTable.Sample.Wasm
{
Expand All @@ -10,9 +12,10 @@ public class Program
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.RootComponents.Add<App>("app");

builder.Services.AddBaseAddressHttpClient();
builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();
}
Expand Down
27 changes: 27 additions & 0 deletions src/BlazorTable.Tests/BlazorTable.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorTable\BlazorTable.csproj" />
</ItemGroup>

</Project>
72 changes: 72 additions & 0 deletions src/BlazorTable.Tests/Bug104.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Shouldly;
using System;
using System.Linq.Expressions;
using Xunit;

namespace BlazorTable.Tests
{
public class Bug104
{
[Fact]
public void AddToExisting()
{
Expression<Func<Parent, bool>> query = x => ((x.Child.Name != null) && (x.Child.Name == "bob"));

Expression<Func<Parent, bool>> queryfixed = x => ((x.Child != null) &&((x.Child.Name != null) && (x.Child.Name == "bob")));

query.AddNullChecks().ToString().ShouldBe(queryfixed.ToString());
}


[Fact]
public void NoParent()
{
Expression<Func<Parent, bool>> query = x => x.Name != null;

Expression<Func<Parent, bool>> queryfixed = x => x.Name != null;

query.AddNullChecks().ToString().ShouldBe(queryfixed.ToString());
}

[Fact]
public void SingleParent()
{
Expression<Func<Parent, bool>> query = x => x.Child.Name != null;

Expression<Func<Parent, bool>> queryfixed = x => x.Child != null
&& x.Child.Name != null;

query.AddNullChecks().ToString().ShouldBe(queryfixed.ToString());
}

[Fact]
public void MultiParent()
{
Expression<Func<Parent, bool>> query1 = x => x.Child.GrandChild.Name != null;

Expression<Func<Parent, bool>> query1fixed = x => ((x.Child != null)
&& ((x.Child.GrandChild != null) && (x.Child.GrandChild.Name != null)));

query1.AddNullChecks().ToString().ShouldBe("x => ((x.Child != null) AndAlso ((x.Child.GrandChild != null) AndAlso (x.Child.GrandChild.Name != null)))");
}

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

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; }
}
}
}
4 changes: 4 additions & 0 deletions src/BlazorTable/BlazorTable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Watch Include="..\**\*.razor" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/BlazorTable/Components/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private IEnumerable<TableItem> GetData()
{
if (item.Filter != null)
{
ItemsQueryable = ItemsQueryable.Where(item.Filter);
ItemsQueryable = ItemsQueryable.Where(item.Filter.AddNullChecks());
}
}

Expand Down
53 changes: 51 additions & 2 deletions src/BlazorTable/Utillities.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using LinqKit;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
Expand All @@ -8,7 +9,7 @@

namespace BlazorTable
{
internal static class Utillities
public static class Utillities
{
public static IEnumerable<T> OrEmptyIfNull<T>(this IEnumerable<T> source)
{
Expand Down Expand Up @@ -114,5 +115,53 @@ public static string ToDescriptionString(this Enum val)
var attributes = (DescriptionAttribute[])val.GetType().GetField(val.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
return attributes.Length > 0 ? attributes[0].Description : string.Empty;
}

/// <summary>
/// Recursively walks up the tree and adds null checks
/// </summary>
/// <param name="expression"></param>
/// <returns></returns>
public static Expression<Func<T, bool>> AddNullChecks<T>(this Expression<Func<T, bool>> expression)
{
var parents = new Queue<MemberExpression>();
Expression<Func<T, bool>> tempExpression = expression;

if (expression?.Body is BinaryExpression binary)
{
if (binary.Left is MemberExpression member)
{
// From here we're looking at parents
Recurse(member.Expression);
}
else if (expression?.Body is BinaryExpression binary2)
{
if (binary2.Left is BinaryExpression binary3 && binary3.Left is MemberExpression member2)
{
// From here we're looking at parents
Recurse(member2.Expression);
}
}
}

while (parents.Count > 0)
{
var nullCheck = Expression.NotEqual(parents.Dequeue(), Expression.Constant(null));

var newQuery = Expression.Lambda<Func<T, bool>>(nullCheck, expression.Parameters);

tempExpression = newQuery.And(tempExpression);
}

return tempExpression;

void Recurse(object expression)
{
if (expression is MemberExpression member)
{
parents.Enqueue(member);
Recurse(member.Expression);
}
}
}
}
}

0 comments on commit 879b5f2

Please sign in to comment.