Collapse expanded campaign on step change

This commit is contained in:
2025-11-05 16:40:32 +09:00
parent 0e8616fb1e
commit 05e24d4eae

View File

@ -24,7 +24,7 @@
</RadzenRow>
<RadzenRow>
<RadzenColumn SizeMD="12">
<RadzenDataGrid TItem="Campaign" Data="@campaigns" RowExpand="@RowExpandAsync" IsLoading="@(state != CampaignsPageState.Idle)" AllowFiltering="true" AllowPaging="true" ShowPagingSummary="true" PageSizeOptions=@(new int[] { 5, 10, 20, 30 }) AllowSorting="true" AllowColumnResize="true" ExpandMode="DataGridExpandMode.Single">
<RadzenDataGrid @ref="@dataGrid" TItem="Campaign" Data="@campaigns" RowExpand="@RowExpandAsync" IsLoading="@(state != CampaignsPageState.Idle)" AllowFiltering="true" AllowPaging="true" ShowPagingSummary="true" PageSizeOptions=@(new int[] { 5, 10, 20, 30 }) AllowSorting="true" AllowColumnResize="true" ExpandMode="DataGridExpandMode.Single">
<Template Context="campaign">
<RadzenDataGrid Data="@campaign.Operations" AllowFiltering="true" AllowPaging="true" ShowPagingSummary="true" PageSizeOptions=@(new int[] { 5, 10, 20, 30 }) AllowSorting="true" AllowColumnResize="true">
<Columns>
@ -67,7 +67,9 @@
}
CampaignsPageState state;
IEnumerable<Campaign> campaigns;
RadzenDataGrid<Campaign> dataGrid;
IEnumerable<Campaign>? campaigns;
Campaign? expandedCampaign;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
@ -80,12 +82,12 @@
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (state.User.IsInRole(AppRole.ADMINISTRATOR_TYPE) || state.User.IsInRole(AppRole.OPERATOR_TYPE))
{
campaigns = await HeadquartersService.GetCampaignsAsync();
CampaignManagementState.OnCampaignCreated += OnCampaignCreated;
CampaignManagementState.OnCampaignStarted += OnCampaignStarted;
CampaignManagementState.OnCampaignProgressStep += OnCampaignProgressStep;
CampaignManagementState.OnCampaignEnded += OnCampaignEnded;
campaigns = await HeadquartersService.GetCampaignsAsync();
}
ChangeState(CampaignsPageState.Idle);
@ -94,6 +96,8 @@
async Task RowExpandAsync(Campaign campaign)
{
expandedCampaign = campaign;
if (campaign.Operations == null)
{
campaign.Operations = await HeadquartersService.GetOperationsAsync(campaign.Id);
@ -118,11 +122,18 @@
{
InvokeAsync(() =>
{
var targetCampaign = campaigns.FirstOrDefault(x => x.Id == campaign.Id);
var targetCampaign = campaigns?.FirstOrDefault(x => x.Id == campaign.Id);
if (targetCampaign != null)
{
targetCampaign.StartedAt = campaign.StartedAt;
}
if (expandedCampaign != null && expandedCampaign.Id == campaign.Id)
{
dataGrid.CollapseAll();
expandedCampaign.Operations = null;
}
});
}
@ -130,11 +141,18 @@
{
InvokeAsync(() =>
{
var targetCampaign = campaigns.FirstOrDefault(x => x.Id == campaign.Id);
var targetCampaign = campaigns?.FirstOrDefault(x => x.Id == campaign.Id);
if (targetCampaign != null)
{
targetCampaign.Step = campaign.Step;
targetCampaign.Progress = campaign.Progress;
if (expandedCampaign != null && expandedCampaign.Id == campaign.Id)
{
dataGrid.CollapseAll();
expandedCampaign.Operations = null;
}
}
});
}
@ -153,6 +171,7 @@
await InvokeAsync(() =>
{
campaigns = refreshedCampaigns;
expandedCampaign = null;
ChangeState(CampaignsPageState.Idle);
});