Skip to content

Commit ac6ad7c

Browse files
Enhanced Location Search dropdown- All screens (#1001)
* Hub and Wing Induction Search Location dropdown -Replaced location lookup with LocationSelectComponent -Added Location filter to LocationSelectComponent -Added new attributes for filtering, validation etc. * Activity Search Location dropdown -Replaced location lookup with LocationSelectComponent * Assessment Location Search dropdown -Replaced location lookup with LocationSelectComponent * Pathway Plan Review Location Search dropdown -Replaced location lookup with LocationSelectComponent * Risk Review Location Search dropdown -Replaced location lookup with LocationSelectComponent * Activity/ETE history for task Location Search dropdown -Replaced location lookup with LocationSelectComponent * QA Enrolment Results Location Search dropdown -Replaced location lookup with LocationSelectComponent * QA Activities Results Location Search dropdown -Replaced location lookup with LocationSelectComponent * Update src/Server.UI/Pages/Participants/Components/AddWingInductionDialog.razor Co-authored-by: Carl Sixsmith <carl.sixsmith1@justice.gov.uk> * Accepted suggested changes --------- Co-authored-by: Carl Sixsmith <carl.sixsmith1@justice.gov.uk>
1 parent 9897a4c commit ac6ad7c

20 files changed

Lines changed: 331 additions & 413 deletions

src/Server.UI/Components/Locations/LocationSelectComponent.razor

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@using Cfo.Cats.Application.Features.Delius.DTOs
44
@using Cfo.Cats.Application.Features.Locations.DTOs
55
@using DocumentFormat.OpenXml.Office2013.PowerPoint.Roaming
6+
@using System.Linq.Expressions
67

78
@inject ILocationService LocationService
89

@@ -11,12 +12,16 @@
1112
ItemCollection="@_locations"
1213
Value="Value"
1314
ValueChanged="HandleValueChanged"
15+
Label="@Label"
1416
Placeholder="Select a location"
1517
Required="false"
18+
Disabled="@Disabled"
19+
For="@For"
1620
Variant="Variant.Outlined"
1721
SearchBox="true"
1822
SearchBoxAutoFocus="true"
1923
SearchBoxClearable="true"
24+
Clearable="true"
2025
SearchFunc="@(new Func<LocationDto?, string, bool>(Search))"
2126
ToStringFunc="@GetDisplayName">
2227

@@ -33,6 +38,18 @@
3338
[Parameter, EditorRequired]
3439
public EventCallback<LocationDto?> ValueChanged { get; set; }
3540

41+
[Parameter]
42+
public Func<LocationDto, bool>? LocationFilter { get; set; }
43+
44+
[Parameter]
45+
public bool Disabled { get; set; }
46+
47+
[Parameter]
48+
public string? Label { get; set; }
49+
50+
[Parameter]
51+
public Expression<Func<LocationDto?>>? For { get; set; }
52+
3653
private LocationDto[] _locations = [];
3754

3855
private async Task HandleValueChanged(LocationDto? locationDto)
@@ -44,9 +61,10 @@
4461
private string GetDisplayName(LocationDto? locationDto) => locationDto?.Name ?? string.Empty;
4562

4663
protected override void OnInitialized()
47-
=> _locations = LocationService.GetVisibleLocations(TenantId)
48-
.OrderBy(l =>l.Name)
49-
.ToArray();
64+
{
65+
var locations = LocationService.GetVisibleLocations(TenantId).OrderBy(l => l.Name);
66+
_locations = (LocationFilter is not null ? locations.Where(LocationFilter) : locations).ToArray();
67+
}
5068

5169
private bool Search(LocationDto? location, string searchText)
5270
{

src/Server.UI/Pages/Activities/ActivitiesDialog.razor

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
@using Cfo.Cats.Application.Common.Interfaces.Locations
2-
@using Cfo.Cats.Application.Features.Activities.DTOs
1+
@using Cfo.Cats.Application.Features.Activities.DTOs
2+
@using Cfo.Cats.Server.UI.Components.Locations
33
@using Cfo.Cats.Domain.Common.Enums
44
@using Humanizer
55

66
@inherits CatsComponentBase
77

8-
@inject ILocationService Locations;
98
@inject ICurrentUserService CurrentUser;
109

1110
<style>
@@ -42,15 +41,12 @@
4241
MaxDate="DateTime.Today" />
4342
</MudItem>
4443
<MudItem xs="12">
45-
<MudSelect @bind-Value="Model.Location"
46-
@bind-Value:after="OnLocationChanged"
47-
Label="Location"
48-
Clearable="true">
49-
@foreach (var location in _locations)
50-
{
51-
<MudSelectItem Value="location">@location.Name</MudSelectItem>
52-
}
53-
</MudSelect>
44+
<LocationSelectComponent
45+
TenantId="@(CurrentUser.TenantId!)"
46+
Label="@Model.GetMemberDescription(x => x.Location)"
47+
@bind-Value="Model.Location"
48+
@bind-Value:after="OnRefresh"
49+
For="() => Model.Location"/>
5450
</MudItem>
5551
<MudItem xs="12">
5652
<MudChipSet T="ActivityType"

src/Server.UI/Pages/Activities/ActivitiesDialog.razor.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Cfo.Cats.Application.Features.Activities.Commands;
22
using Cfo.Cats.Application.Features.Activities.DTOs;
33
using Cfo.Cats.Application.Features.Activities.Queries;
4-
using Cfo.Cats.Application.Features.Locations.DTOs;
54
using Cfo.Cats.Application.Features.PathwayPlans.DTOs;
65
using Cfo.Cats.Domain.Common.Enums;
76
using Cfo.Cats.Server.UI.Pages.Activities.Components;
@@ -10,7 +9,6 @@ namespace Cfo.Cats.Server.UI.Pages.Activities;
109

1110
public partial class ActivitiesDialog
1211
{
13-
private IEnumerable<LocationDto> _locations = [];
1412
private PaginatedData<ActivitySummaryDto>? _activities;
1513

1614
[Parameter, EditorRequired] public required ActivitiesWithPagination.Query Model { get; set; }
@@ -23,12 +21,7 @@ public partial class ActivitiesDialog
2321

2422
protected override async Task OnInitializedAsync()
2523
{
26-
_locations = Locations
27-
.GetVisibleLocations(CurrentUser.TenantId!)
28-
.ToList();
29-
3024
await OnRefresh();
31-
3225
await base.OnInitializedAsync();
3326
}
3427

@@ -54,8 +47,6 @@ private Task OnDateRangeChanged(DateRange range)
5447
return OnRefresh();
5548
}
5649

57-
private Task OnLocationChanged() => OnRefresh();
58-
5950
private Task OnActivityTypesChanged(IReadOnlyCollection<ActivityType>? types)
6051
{
6152
Model.IncludeTypes = types?.ToList();

src/Server.UI/Pages/Activities/ActivityForm.razor

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
@using Cfo.Cats.Application.Common.Interfaces.Locations
22
@using Cfo.Cats.Application.Common.Validators
33
@using Cfo.Cats.Domain.Common.Enums
4+
@using Cfo.Cats.Server.UI.Components.Locations
45
@using Cfo.Cats.Server.UI.Pages.Activities.Components
56

67
@inherits CatsComponentBase
78

8-
@inject ILocationService Locations;
99
@inject ICurrentUserService CurrentUser;
1010

1111
<MudGrid>
1212
<MudItem xs="12">
13-
<MudSelect @bind-Value="Model.Location"
14-
@bind-Value:after="LocationChanged"
15-
Label="@Model.GetMemberDescription(x => x.Location)"
16-
For="() => Model.Location"
17-
Clearable="true"
18-
ToStringFunc="location => location?.Name"
19-
Disabled="Model.CanChangeLocation is false">
20-
@foreach (var location in _locations)
21-
{
22-
<MudSelectItem Value="location">@location.Name</MudSelectItem>
23-
}
24-
</MudSelect>
13+
<LocationSelectComponent
14+
TenantId="@(CurrentUser.TenantId!)"
15+
Label="@Model.GetMemberDescription(x => x.Location)"
16+
Value="@Model.Location"
17+
ValueChanged="OnLocationChanged"
18+
For="() => Model.Location"
19+
Disabled="@(Model.CanChangeLocation is false)" />
2520
</MudItem>
2621
<MudItem xs="12">
2722
<MudChipSet @bind-SelectedValues="_filteredTypes"

src/Server.UI/Pages/Activities/ActivityForm.razor.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,29 @@ public partial class ActivityForm
1313
private MudAutocomplete<ActivityDefinition?> _activityDropdown = new();
1414
private readonly bool _uploading = false;
1515
private IReadOnlyCollection<ActivityType> _filteredTypes = [];
16-
private IEnumerable<LocationDto> _locations = [];
1716
private bool _hasSelectedActivityAlreadyBeenAddedOnThisDate;
1817
private bool Disabled => Model.Location is null;
1918
private bool _hasParticipantBeenAtThisLocationOnThisDate = true;
20-
2119
[Parameter, EditorRequired] public required AddActivity.Command Model { get; set; }
2220

2321
[Parameter] public string ParticipantId { get; set; } = string.Empty;
2422

2523
protected override void OnInitialized()
2624
{
2725
SetActivities();
28-
29-
_locations = Locations
30-
.GetVisibleLocations(CurrentUser.TenantId!)
31-
.ToList();
32-
3326
base.OnInitialized();
3427
}
3528

3629
private void SetActivities() => _activities = Model.Location is null
3730
? []
3831
: ActivityDefinition.GetActivitiesForLocation(Model.Location.LocationType);
3932

33+
private async Task OnLocationChanged(LocationDto? location)
34+
{
35+
Model.Location = location;
36+
LocationChanged();
37+
}
38+
4039
private void LocationChanged()
4140
{
4241
SetActivities();

src/Server.UI/Pages/Participants/Components/AddAssessmentDialog.razor

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@using Cfo.Cats.Application.Features.Assessments.Commands
33
@using Cfo.Cats.Application.Features.Locations.DTOs
44
@using Cfo.Cats.Domain.Common.Enums
5+
@using Cfo.Cats.Server.UI.Components.Locations
56
@using Cfo.Cats.Server.UI.Pages.Activities.Components
67

78
@inherits CatsComponentBase
@@ -16,16 +17,11 @@
1617
<MudForm @ref="form" Model="Model" Validation="@(Validator.ValidateValue(Model))">
1718
<MudGrid>
1819
<MudItem xs="12">
19-
<MudSelect @bind-Value="Model.Location"
20-
Label="@Model.GetMemberDescription(x => x.Location)"
21-
For="() => Model.Location"
22-
Clearable="true"
23-
ToStringFunc="location => location?.Name">
24-
@foreach (var location in locations)
25-
{
26-
<MudSelectItem Value="location">@location.Name</MudSelectItem>
27-
}
28-
</MudSelect>
20+
<LocationSelectComponent
21+
TenantId="@(CurrentUser.TenantId!)"
22+
Label="@Model.GetMemberDescription(x => x.Location)"
23+
@bind-Value="Model.Location"
24+
For="() => Model.Location"/>
2925
</MudItem>
3026
</MudGrid>
3127
</MudForm>
@@ -37,57 +33,3 @@
3733
</DialogActions>
3834
</MudDialog>
3935

40-
@code {
41-
MudForm form = new();
42-
bool saving;
43-
44-
[CascadingParameter]
45-
public required IMudDialogInstance Dialog { get; set; }
46-
47-
[Parameter, EditorRequired]
48-
public required BeginAssessment.Command Model { get; set; }
49-
50-
IEnumerable<LocationDto> locations = [];
51-
52-
protected override void OnInitialized()
53-
{
54-
locations = Locations
55-
.GetVisibleLocations(CurrentUser.TenantId!)
56-
.ToList();
57-
58-
base.OnInitialized();
59-
}
60-
61-
async Task Submit()
62-
{
63-
try
64-
{
65-
saving = true;
66-
67-
await form.ValidateAsync();
68-
69-
if (form.IsValid is false)
70-
{
71-
return;
72-
}
73-
74-
var result = await GetNewMediator().Send(Model);
75-
76-
if (result.Succeeded)
77-
{
78-
Dialog.Close(DialogResult.Ok(result.Data));
79-
Snackbar.Add(ConstantString.SaveSuccess, Severity.Info);
80-
}
81-
else
82-
{
83-
Snackbar.Add(result.ErrorMessage, Severity.Error);
84-
}
85-
86-
}
87-
finally
88-
{
89-
saving = false;
90-
}
91-
}
92-
93-
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Cfo.Cats.Application.Features.Assessments.Commands;
2+
using Cfo.Cats.Infrastructure.Constants;
3+
4+
namespace Cfo.Cats.Server.UI.Pages.Participants.Components;
5+
6+
public partial class AddAssessmentDialog
7+
{
8+
private MudForm form = new();
9+
private bool saving;
10+
11+
[CascadingParameter]
12+
public required IMudDialogInstance Dialog { get; set; }
13+
14+
[Parameter, EditorRequired]
15+
public required BeginAssessment.Command Model { get; set; }
16+
17+
private async Task Submit()
18+
{
19+
try
20+
{
21+
saving = true;
22+
23+
await form.ValidateAsync();
24+
25+
if (form.IsValid is false)
26+
{
27+
return;
28+
}
29+
30+
var result = await GetNewMediator().Send(Model);
31+
32+
if (result.Succeeded)
33+
{
34+
Dialog.Close(DialogResult.Ok(result.Data));
35+
Snackbar.Add(ConstantString.SaveSuccess, Severity.Info);
36+
}
37+
else
38+
{
39+
Snackbar.Add(result.ErrorMessage, Severity.Error);
40+
}
41+
42+
}
43+
finally
44+
{
45+
saving = false;
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)