Skip to content

Commit

Permalink
refac: apply PR review 2 - DataGrid
Browse files Browse the repository at this point in the history
- ListEventDetailsComponent 에서 <table> 대신 DataGrid를 사용하는 방식으로 변경
  • Loading branch information
praivesi committed Aug 26, 2024
1 parent b482324 commit 96f49f6
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="$(AzureOpenAIVersion)" />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="$(FluentUIVersion)" />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.DataGrid.EntityFrameworkAdapter" Version="4.9.3" />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Emoji" Version="$(FluentUIVersion)" />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="$(FluentUIVersion)" />
</ItemGroup>
Expand Down
65 changes: 30 additions & 35 deletions src/AzureOpenAIProxy.PlaygroundApp/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">Azure OpenAI Proxy Playground</a>
</div>
</div>

<input type="checkbox" title="Navigation menu" class="navbar-toggler" />

<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="events">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Events
</NavLink>
</div>
</nav>
</div>
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">Azure OpenAI Proxy Playground</a>
</div>
</div>

<input type="checkbox" title="Navigation menu" class="navbar-toggler" />

<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
</NavLink>
</div>
</nav>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@page "/events"

@using AzureOpenAIProxy.PlaygroundApp.Components.UI.Admin

<PageTitle>AdminEvents</PageTitle>

<h1>AdminEvents</h1>

<p>This component demonstrates showing admin events.</p>

<AdminListEventDetailsComponent @rendermode="InteractiveServer" />
11 changes: 0 additions & 11 deletions src/AzureOpenAIProxy.PlaygroundApp/Components/Pages/Events.razor

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
flex-direction: column;
justify-content: center;
align-items: center;
height: 100px;
@*height:100px;*@
}
.activated {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
@using AzureOpenAIProxy.PlaygroundApp.Components.UI.Admin

@using AzureOpenAIProxy.ApiApp.Models

<div id="evt-detail-comp">
@if (eventDetails == null)
{
<p><em>Loading...</em></p>
}
else
{
<div id="evt-detail-tbl">
<FluentDataGrid Items="@eventDetails" Pagination="@pagination" >
<PropertyColumn Class="fluent-datagrid-cell" Property="@(p => p.Title)" Align="@Align.Center" Sortable="true" />
<PropertyColumn Class="fluent-datagrid-cell" Property="@(p => p.DateStart)" Format="yyyy-MM-dd" Align="@Align.Center" Sortable="true" />
<PropertyColumn Class="fluent-datagrid-cell" Property="@(p => p.DateEnd)" Format="yyyy-MM-dd" Align="@Align.Center" Sortable="true" />
<PropertyColumn Class="fluent-datagrid-cell" Property="@(p => p.TimeZone)" Align="@Align.Center" Sortable="true" />
<PropertyColumn Class="fluent-datagrid-cell" Property="@(p => p.OrganizerName)" Align="@Align.Center" Sortable="true" />
<PropertyColumn Class="fluent-datagrid-cell" Property="@(p => p.CoorganizerName)" Align="@Align.Center" Sortable="true" />
<PropertyColumn Class="fluent-datagrid-cell" Property="@(p => p.MaxTokenCap)" Align="@Align.Center" Sortable="true" />
<PropertyColumn Class="fluent-datagrid-cell" Property="@(p => p.DailyRequestCap)" Align="@Align.Center" Sortable="true" />
<TemplateColumn Class="fluent-datagrid-cell" Title="Active" Align="@Align.Center">
<AdminEventDetailElemActiveComponent
IsActive="@(((AdminEventDetails)@context).IsActive.HasValue &&
((AdminEventDetails)@context).IsActive.Value)" />
</TemplateColumn>
<TemplateColumn Class="fluent-datagrid-cell" Title="Actions" Align="@Align.Center">
<FluentButton aria-label="Edit item" IconEnd="@(new Icons.Regular.Size16.Edit())" />
<FluentButton aria-label="Delete item" IconEnd="@(new Icons.Regular.Size16.Delete())" />
</TemplateColumn>
</FluentDataGrid>
</div>

<div class="page-button-box">
@if (pagination.TotalItemCount.HasValue)
{
for (var pageIndex = 0; pageIndex <= pagination.LastPageIndex; pageIndex++)
{
var capturedIndex = pageIndex;
<FluentButton class="page-button" @onclick="@(() => GoToPageAsync(capturedIndex))" Appearance="@PageButtonAppearance(capturedIndex)"
aria-current="@AriaCurrentValue(capturedIndex)">
@(capturedIndex + 1)
</FluentButton>
}
}
</div>
}
</div>

<style>
.fluent-datagrid-cell {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.page-button-box {
display: flex;
justify-content: center;
align-items: center;
margin-top: 20px;
}
.page-button {
margin-left: 10px;
}
</style>

@code {
IQueryable<AdminEventDetails>? eventDetails;
PaginationState pagination = new PaginationState { ItemsPerPage = 10 };

protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate streaming rendering
await Task.Delay(100);

var startDate = DateOnly.FromDateTime(DateTime.Now);

// make dummy data
eventDetails = Enumerable.Range(1, 150).Select(index => new AdminEventDetails
{
EventId = Guid.NewGuid().ToString(),
Title = $"event title #{index}",
Summary = "dummy summary",
Description = "dummy description",
DateStart = DateTimeOffset.Now,
DateEnd = DateTimeOffset.Now.AddDays(7 + index),
TimeZone = "KST",
IsActive = index % 3 == 0,
OrganizerName = $"Charlie_{index}",
OrganizerEmail = $"user_{index}@gmail.com",
CoorganizerName = $"Bravo_{index}",
CoorganizerEmail = $"support_{index}@gmail.com",
MaxTokenCap = (100 + index) * 100,
DailyRequestCap = index * 10
}).AsQueryable();

pagination.TotalItemCountChanged += (sender, eventArgs) => StateHasChanged();
}

private async Task GoToPageAsync(int pageIndex)
{
await pagination.SetCurrentPageIndexAsync(pageIndex);
}

private Appearance PageButtonAppearance(int pageIndex)
=> pagination.CurrentPageIndex == pageIndex ? Appearance.Accent : Appearance.Neutral;

private string? AriaCurrentValue(int pageIndex)
=> pagination.CurrentPageIndex == pageIndex ? "page" : null;
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 96f49f6

Please sign in to comment.