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