-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Productize QuickGrid #46573
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
Merged
Merged
Productize QuickGrid #46573
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ce24e6c
Add QuickGrid source
Nick-Stanton 9896766
Partially fix build warnings
Nick-Stanton 9cb44d7
stamp out last build warnings
Nick-Stanton 2215524
Appease invalid IDE0051 errors
Nick-Stanton 5d5f38a
Implement IDE suggestions for perf and simplicity
Nick-Stanton ce7dfec
Resolve missing references and manually validate basic example
Nick-Stanton baa07bf
Resolve incorrect project ref path
Nick-Stanton 2034bbc
Fix project structure
Nick-Stanton ee5a838
Add E2E Tests
Nick-Stanton 5f02747
Merge branch 'main' into QuickGrid
Nick-Stanton fab0dbf
Add error suppression
Nick-Stanton f000993
Seal what can be sealed. Add EditorBrowsable attributes to infra classes
Nick-Stanton 0c09e02
Address (most of) API feedback
Nick-Stanton b50de62
Address aspnet-build feedback
Nick-Stanton a4dae27
Remove ISortBuilderColumn
Nick-Stanton b9d762a
Update src/Components/QuickGrid/Microsoft.AspNetCore.Components.Quick…
Nick-Stanton 59cbe15
Simplify ApplySorting, GetSortByProperties
Nick-Stanton 3b3ee06
Update Align.cs
Nick-Stanton 482fcbb
Update src/Components/QuickGrid/Microsoft.AspNetCore.Components.Quick…
Nick-Stanton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...QuickGrid.EntityFrameworkAdapter/src/EntityFrameworkAdapterServiceCollectionExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Components.QuickGrid; | ||
using Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
/// <summary> | ||
/// Provides extension methods to configure <see cref="IAsyncQueryExecutor"/> on a <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
public static class EntityFrameworkAdapterServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Registers an Entity Framework aware implementation of <see cref="IAsyncQueryExecutor"/>. | ||
/// </summary> | ||
/// <param name="services">The <see cref="IServiceCollection"/>.</param> | ||
public static void AddQuickGridEntityFrameworkAdapter(this IServiceCollection services) | ||
{ | ||
services.AddSingleton<IAsyncQueryExecutor, EntityFrameworkAsyncQueryExecutor>(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...Core.Components.QuickGrid.EntityFrameworkAdapter/src/EntityFrameworkAsyncQueryExecutor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Linq; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Query; | ||
|
||
namespace Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter; | ||
|
||
internal sealed class EntityFrameworkAsyncQueryExecutor : IAsyncQueryExecutor | ||
{ | ||
public bool IsSupported<T>(IQueryable<T> queryable) | ||
=> queryable.Provider is IAsyncQueryProvider; | ||
|
||
public Task<int> CountAsync<T>(IQueryable<T> queryable) | ||
=> queryable.CountAsync(); | ||
|
||
public Task<T[]> ToArrayAsync<T>(IQueryable<T> queryable) | ||
=> queryable.ToArrayAsync(); | ||
} |
15 changes: 15 additions & 0 deletions
15
...meworkAdapter/src/Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
<Description>Provides an Entity Framework Core adapter for the <a href="https://www.nuget.org/packages/Microsoft.AspNetCore.Components.QuickGrid">Microsoft.AspNetCore.Components.QuickGrid</a> package.</Description> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<IsTrimmable>true</IsTrimmable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Microsoft.EntityFrameworkCore" /> | ||
<Reference Include="Microsoft.AspNetCore.Components.QuickGrid" /> | ||
</ItemGroup> | ||
|
||
</Project> |
1 change: 1 addition & 0 deletions
1
...icrosoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter/src/PublicAPI.Shipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#nullable enable |
3 changes: 3 additions & 0 deletions
3
...rosoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter/src/PublicAPI.Unshipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#nullable enable | ||
Microsoft.Extensions.DependencyInjection.EntityFrameworkAdapterServiceCollectionExtensions | ||
static Microsoft.Extensions.DependencyInjection.EntityFrameworkAdapterServiceCollectionExtensions.AddQuickGridEntityFrameworkAdapter(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> void |
35 changes: 35 additions & 0 deletions
35
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Columns/Align.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components.QuickGrid; | ||
|
||
/// <summary> | ||
/// Describes alignment for a <see cref="QuickGrid{TGridItem}"/> column. | ||
/// </summary> | ||
public enum Align | ||
{ | ||
/// <summary> | ||
/// Justifies the content against the start of the container | ||
/// </summary> | ||
Start, | ||
|
||
/// <summary> | ||
/// Justifies the content at the center of the container. | ||
/// </summary> | ||
Center, | ||
|
||
/// <summary> | ||
/// Justifies the content at the end of the container | ||
/// </summary> | ||
End, | ||
|
||
/// <summary> | ||
/// Justifies the content against the left of the container. | ||
/// </summary> | ||
Left, | ||
|
||
/// <summary> | ||
/// Justifies the content at the right of the container. | ||
/// </summary> | ||
Right, | ||
} |
54 changes: 54 additions & 0 deletions
54
...mponents/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Columns/ColumnBase.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@using Microsoft.AspNetCore.Components.Rendering | ||
@using Microsoft.AspNetCore.Components.Web | ||
@using Microsoft.AspNetCore.Components.Web.Virtualization | ||
@namespace Microsoft.AspNetCore.Components.QuickGrid | ||
@typeparam TGridItem | ||
@{ | ||
InternalGridContext.Grid.AddColumn(this, InitialSortDirection, IsDefaultSortColumn); | ||
} | ||
|
||
@code | ||
{ | ||
private void RenderDefaultHeaderContent(RenderTreeBuilder __builder) | ||
{ | ||
@if (HeaderTemplate is not null) | ||
{ | ||
@HeaderTemplate(this) | ||
} | ||
else | ||
{ | ||
@if (ColumnOptions is not null && (Align != Align.Right || Align != Align.End)) | ||
{ | ||
<button class="col-options-button" @onclick="@(() => Grid.ShowColumnOptionsAsync(this))"></button> | ||
} | ||
|
||
if (Sortable.HasValue ? Sortable.Value : IsSortableByDefault()) | ||
{ | ||
<button class="col-title" @onclick="@(() => Grid.SortByColumnAsync(this))"> | ||
<div class="col-title-text">@Title</div> | ||
<div class="sort-indicator" aria-hidden="true"></div> | ||
</button> | ||
} | ||
else | ||
{ | ||
<div class="col-title"> | ||
<div class="col-title-text">@Title</div> | ||
</div> | ||
} | ||
|
||
@if (ColumnOptions is not null && (Align == Align.Right || Align == Align.End)) | ||
{ | ||
<button class="col-options-button" @onclick="@(() => Grid.ShowColumnOptionsAsync(this))"></button> | ||
} | ||
} | ||
} | ||
|
||
internal void RenderPlaceholderContent(RenderTreeBuilder __builder, PlaceholderContext placeholderContext) | ||
{ | ||
// Blank if no placeholder template was supplied, as it's enough to style with CSS by default | ||
if (PlaceholderTemplate is not null) | ||
{ | ||
@PlaceholderTemplate(placeholderContext) | ||
} | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...nents/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Columns/ColumnBase.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Components.QuickGrid.Infrastructure; | ||
using Microsoft.AspNetCore.Components.Rendering; | ||
using Microsoft.AspNetCore.Components.Web.Virtualization; | ||
|
||
namespace Microsoft.AspNetCore.Components.QuickGrid; | ||
|
||
/// <summary> | ||
/// An abstract base class for columns in a <see cref="QuickGrid{TGridItem}"/>. | ||
/// </summary> | ||
/// <typeparam name="TGridItem">The type of data represented by each row in the grid.</typeparam> | ||
public abstract partial class ColumnBase<TGridItem> | ||
{ | ||
[CascadingParameter] internal InternalGridContext<TGridItem> InternalGridContext { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// Title text for the column. This is rendered automatically if <see cref="HeaderTemplate" /> is not used. | ||
/// </summary> | ||
[Parameter] public string? Title { get; set; } | ||
|
||
/// <summary> | ||
/// An optional CSS class name. If specified, this is included in the class attribute of table header and body cells | ||
/// for this column. | ||
/// </summary> | ||
[Parameter] public string? Class { get; set; } | ||
|
||
/// <summary> | ||
/// If specified, controls the justification of table header and body cells for this column. | ||
/// </summary> | ||
[Parameter] public Align Align { get; set; } | ||
|
||
/// <summary> | ||
/// An optional template for this column's header cell. If not specified, the default header template | ||
/// includes the <see cref="Title" /> along with any applicable sort indicators and options buttons. | ||
/// </summary> | ||
[Parameter] public RenderFragment<ColumnBase<TGridItem>>? HeaderTemplate { get; set; } | ||
|
||
/// <summary> | ||
/// If specified, indicates that this column has this associated options UI. A button to display this | ||
/// UI will be included in the header cell by default. | ||
/// | ||
/// If <see cref="HeaderTemplate" /> is used, it is left up to that template to render any relevant | ||
/// "show options" UI and invoke the grid's <see cref="QuickGrid{TGridItem}.ShowColumnOptionsAsync(ColumnBase{TGridItem})" />). | ||
/// </summary> | ||
[Parameter] public RenderFragment? ColumnOptions { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates whether the data should be sortable by this column. | ||
/// | ||
/// The default value may vary according to the column type (for example, a <see cref="TemplateColumn{TGridItem}" /> | ||
/// is sortable by default if any <see cref="TemplateColumn{TGridItem}.SortBy" /> parameter is specified). | ||
/// </summary> | ||
[Parameter] public bool? Sortable { get; set; } | ||
|
||
/// <summary> | ||
/// Specifies sorting rules for a column. | ||
/// </summary> | ||
public abstract GridSort<TGridItem>? SortBy { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates which direction to sort in | ||
/// if <see cref="IsDefaultSortColumn"/> is true. | ||
/// </summary> | ||
[Parameter] public SortDirection InitialSortDirection { get; set; } = default; | ||
|
||
/// <summary> | ||
/// Indicates whether this column should be sorted by default. | ||
/// </summary> | ||
[Parameter] public bool IsDefaultSortColumn { get; set; } = false; | ||
|
||
/// <summary> | ||
/// If specified, virtualized grids will use this template to render cells whose data has not yet been loaded. | ||
/// </summary> | ||
[Parameter] public RenderFragment<PlaceholderContext>? PlaceholderTemplate { get; set; } | ||
|
||
/// <summary> | ||
/// Gets a reference to the enclosing <see cref="QuickGrid{TGridItem}" />. | ||
/// </summary> | ||
public QuickGrid<TGridItem> Grid => InternalGridContext.Grid; | ||
|
||
/// <summary> | ||
/// Overridden by derived components to provide rendering logic for the column's cells. | ||
/// </summary> | ||
/// <param name="builder">The current <see cref="RenderTreeBuilder" />.</param> | ||
/// <param name="item">The data for the row being rendered.</param> | ||
protected internal abstract void CellContent(RenderTreeBuilder builder, TGridItem item); | ||
|
||
/// <summary> | ||
/// Gets or sets a <see cref="RenderFragment" /> that will be rendered for this column's header cell. | ||
/// This allows derived components to change the header output. However, derived components are then | ||
/// responsible for using <see cref="HeaderTemplate" /> within that new output if they want to continue | ||
/// respecting that option. | ||
/// </summary> | ||
protected internal RenderFragment HeaderContent { get; protected set; } | ||
|
||
/// <summary> | ||
/// Get a value indicating whether this column should act as sortable if no value was set for the | ||
/// <see cref="ColumnBase{TGridItem}.Sortable" /> parameter. The default behavior is not to be | ||
/// sortable unless <see cref="ColumnBase{TGridItem}.Sortable" /> is true. | ||
/// | ||
/// Derived components may override this to implement alternative default sortability rules. | ||
/// </summary> | ||
/// <returns>True if the column should be sortable by default, otherwise false.</returns> | ||
protected virtual bool IsSortableByDefault() => false; | ||
|
||
/// <summary> | ||
/// Constructs an instance of <see cref="ColumnBase{TGridItem}" />. | ||
/// </summary> | ||
public ColumnBase() | ||
{ | ||
HeaderContent = RenderDefaultHeaderContent; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ents/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Columns/ColumnBase.razor.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* Contains the title text and sort indicator, and expands to fill as much of the col width as it can */ | ||
.col-title { | ||
display: flex; /* So that we can make col-title-text expand as much as possible, and still hide overflow with ellipsis */ | ||
min-width: 0px; | ||
flex-grow: 1; | ||
padding: 0; | ||
} | ||
|
||
/* If the column is sortable, its title is rendered as a button element for accessibility and to support navigation by tab */ | ||
button.col-title { | ||
border: none; | ||
background: none; | ||
position: relative; | ||
cursor: pointer; | ||
} | ||
|
||
.col-justify-center .col-title { | ||
justify-content: center; | ||
} | ||
|
||
.col-justify-end .col-title { | ||
flex-direction: row-reverse; /* For end-justified cols, the sort indicator should appear before the title text */ | ||
} | ||
|
||
/* We put the column title text in its own element primarily so that it can use text-overflow: ellipsis */ | ||
.col-title-text { | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.