Skip to content

Commit

Permalink
Merge pull request #993 from DFE-Digital/remove-filter-status
Browse files Browse the repository at this point in the history
Add feature flag for project filter status and fix issues with filtering
  • Loading branch information
dangood84 authored Jan 23, 2025
2 parents ecf5d4e + a2efc05 commit 9d08631
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ public enum ProjectStatus

[Description("Cancelled")]
Cancelled,


//Possible legacy value
[Description("Cancelled during pre-opening")]
CancelledDuringPreOpening,

[Description("Withdrawn in pre-opening")]
WithdrawnInPreOpening,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ private static IQueryable<Kpi> ApplyFilters(IQueryable<Kpi> query, GetDashboardP
{
if (projectStatuses.Exists(x => x == ProjectStatus.WithdrawnInPreOpening.ToDescription()))
projectStatuses.Add(ProjectStatus.WithdrawnDuringPreOpening.ToDescription());

if (projectStatuses.Exists(x => x == ProjectStatus.Preopening.ToDescription()))
projectStatuses.Add(null);

if (projectStatuses.Exists(x => x == ProjectStatus.Cancelled.ToDescription()))
projectStatuses.Add(ProjectStatus.CancelledDuringPreOpening.ToDescription());

query = query.Where(kpi => projectStatuses.Any(projectStatus => kpi.ProjectStatusProjectStatus == projectStatus));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ protected async Task LoadDashboard(LoadDashboardParameters loadDashboardParamete
var allowCentralRoute = await featureManager.IsEnabledAsync("AllowCentralRoute");
if (!allowCentralRoute)
getDashboardServiceParameters.Wave = "FS - Presumption";


var allowProjectStatusFilter = await featureManager.IsEnabledAsync("AllowProjectStatusFilter");
ProjectStatusSearchTerm = allowProjectStatusFilter ? ProjectStatusSearchTerm : new List<string>();

var filterCache = dashboardFiltersCache.Get();

if (!string.IsNullOrWhiteSpace(ProjectSearchTerm)
Expand All @@ -94,7 +97,7 @@ protected async Task LoadDashboard(LoadDashboardParameters loadDashboardParamete
var response = await GetDashboardService.Execute(getDashboardServiceParameters);

var paginationModel = PaginationMapping.ToModel(response.Paging);
var query = BuildPaginationQuery();
var query = await BuildPaginationQuery();
paginationModel.Url = $"{loadDashboardParameters.Url}{query}";

Dashboard = new DashboardModel
Expand All @@ -113,24 +116,26 @@ protected async Task LoadDashboard(LoadDashboardParameters loadDashboardParamete
};
}

private string BuildPaginationQuery()
private async Task<string> BuildPaginationQuery()
{
var query = new QueryString("?handler=movePage");

if (!string.IsNullOrEmpty(ProjectSearchTerm))
query = query.Add("search-by-project", ProjectSearchTerm);

if (RegionSearchTerm.Count != 0)
RegionSearchTerm.ForEach((r => query = query.Add("search-by-region", r)));
RegionSearchTerm.ForEach(r => query = query.Add("search-by-region", r));

if (LocalAuthoritySearchTerm.Count != 0)
LocalAuthoritySearchTerm.ForEach(l => query = query.Add("search-by-local-authority", l));

if (ProjectManagedBySearchTerm.Count > 0)
ProjectManagedBySearchTerm.ForEach(m => query = query.Add("search-by-pmb", m));

if (ProjectStatusSearchTerm.Count > 0)
ProjectStatusSearchTerm.ForEach((m => query = query.Add("search-by-project-status", m)));
var allowProjectStatusFilter = await featureManager.IsEnabledAsync("AllowProjectStatusFilter");

if (ProjectStatusSearchTerm.Count > 0 && allowProjectStatusFilter)
ProjectStatusSearchTerm.ForEach(m => query = query.Add("search-by-project-status", m));

return query.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
@using Dfe.ManageFreeSchoolProjects.API.Contracts.Project;
@using Dfe.ManageFreeSchoolProjects.Constants;
@inject Microsoft.FeatureManagement.IFeatureManager _featureManager;
@model Dfe.ManageFreeSchoolProjects.Pages.Dashboard.DashboardModel;

@{
var regions = Enum.GetValues(typeof(ProjectRegion));
var regions = Enum.GetValues<ProjectRegion>();
var regionLabels = (from object region in regions select region.ToDescription()).ToList();

var projectStatuses = Enum.GetValues(typeof(ProjectStatus));
var projectStatuses = Enum.GetValues<ProjectStatus>().Except(new[] { ProjectStatus.CancelledDuringPreOpening, ProjectStatus.WithdrawnDuringPreOpening });
var projectStatusLabels = (from ProjectStatus status in projectStatuses select status.ToDescription()).ToList();

projectStatusLabels.Sort();

var projectManagerLabels = Model.ProjectManagers;
Expand All @@ -27,6 +29,8 @@
var noResults = (Model.Projects == null || Model.Projects.Count == 0);
var noFilteredResults = (isFilterActive && Model.Projects.Count == 0);
var projectIds= string.Join(",", Model.TotalProjectIds);

var allowProjectStatusFilter = await _featureManager.IsEnabledAsync("AllowProjectStatusFilter");

}

Expand Down Expand Up @@ -176,44 +180,50 @@
}
}
</div>
<div class="=govuk-grid-row">
<div class="govuk-grid-column-one-quarter">
@{
if (allowProjectStatusFilter)
{
<div class="=govuk-grid-row">
<div class="govuk-grid-column-one-quarter">

<div class="govuk-form-group">
<div class="govuk-form-group">

<fieldset class="govuk-fieldset" aria-describedby="filter-project-status-hint">
<fieldset class="govuk-fieldset" aria-describedby="filter-project-status-hint">

<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">

Project status
Project status

</legend>
</legend>

<div id="filter-project-status-hint" class="govuk-hint">
Select all that apply.
</div>
<div id="filter-project-status-hint" class="govuk-hint">
Select all that apply.
</div>

<div id="search-by-project-status-container" class="govuk-checkboxes govuk-checkboxes--small mfsp-project-listing__filter" data-module="govuk-checkboxes">

@foreach (var status in projectStatusLabels)
{
var checkedStatus = Model.ProjectStatusSearchTerm.Contains(status) ? "checked" : "";
<div id="search-by-project-status-container" class="govuk-checkboxes govuk-checkboxes--small mfsp-project-listing__filter" data-module="govuk-checkboxes">

<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="@status" data-testid="@status-option" name="search-by-project-status" type="checkbox" value="@status" @checkedStatus>
<label class="govuk-label govuk-checkboxes__label" for="@status">
@status
</label>
@foreach (var status in projectStatusLabels)
{
var checkedStatus = Model.ProjectStatusSearchTerm.Contains(status) ? "checked" : "";

</div>
}
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="@status" data-testid="@status-option" name="search-by-project-status" type="checkbox" value="@status" @checkedStatus>
<label class="govuk-label govuk-checkboxes__label" for="@status">
@status
</label>

</div>
}

</div>
</fieldset>
</div>
</fieldset>
</div>

</div>
</div>
</div>
</div>
}
}

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
Expand Down

0 comments on commit 9d08631

Please sign in to comment.