Skip to content

Commit e41c32d

Browse files
author
Binon
committed
Fixed the issue with filter combos
1 parent e08288a commit e41c32d

3 files changed

Lines changed: 54 additions & 27 deletions

File tree

LearningHub.Nhs.WebUI/Helpers/UtilityHelper.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,26 +408,23 @@ public static string GetFormattedAuthoredDate(string authoredDate)
408408
"MM/dd/yyyy HH:mm:ss",
409409
"yyyyMMdd",
410410
"yyyyMMdd HH:mm:ss",
411+
"M/d/yyyy",
412+
"M/d/yyyy h:mm:ss tt",
413+
"M/d/yyyy h:mm tt",
411414
};
412415

413416
if (string.IsNullOrWhiteSpace(authoredDate))
414417
{
415418
return string.Empty;
416419
}
417420

418-
string displayDate = authoredDate;
419-
420-
if (DateTime.TryParseExact(
421-
authoredDate,
422-
dateFormats,
423-
CultureInfo.InvariantCulture,
424-
DateTimeStyles.None,
425-
out DateTime parsedDate))
421+
if (DateTime.TryParse(authoredDate, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out var date) ||
422+
DateTime.TryParseExact(authoredDate, dateFormats, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out date))
426423
{
427-
displayDate = parsedDate.ToString("dd MMM yyyy");
424+
return date.ToString("dd MMM yyyy");
428425
}
429426

430-
return displayDate;
427+
return authoredDate;
431428
}
432429

433430
/// <summary>

OpenAPI/LearningHub.Nhs.OpenApi.Services/Helpers/Search/AzureSearchFacetHelper.cs

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,54 @@ public static Facet[] MergeFacets(
115115
? filteredFacets[facetKey].ToDictionary(f => f.Value?.ToString()?.ToLower() ?? "", f => (int)f.Count)
116116
: new Dictionary<string, int>();
117117

118-
facets[index++] = new Facet
118+
var filters = facetGroup.Value.Select(f =>
119119
{
120-
Id = facetKey,
121-
Filters = facetGroup.Value.Select(f =>
120+
var displayName = f.Value?.ToString()?.ToLower() ?? "";
121+
var isSelected = appliedValues.Any(av => av.Equals(f.Value?.ToString(), StringComparison.OrdinalIgnoreCase));
122+
123+
// Default to the unfiltered count. This is used when:
124+
// - no filtered search has been performed, OR
125+
// - the filter value is selected (keep count so the option remains visible for deselection), OR
126+
// - this facet group itself has an applied filter (multi-select pattern: a group's own
127+
// counts are not narrowed down by its own selections so the user can still pick other values).
128+
// Only update counts using the filtered results when a filter from a DIFFERENT group
129+
// is driving the narrowing of this group.
130+
var count = (int)f.Count;
131+
if (!isSelected && filteredFacets != null && !hasAppliedFilter)
132+
{
133+
count = filteredFacetValues.TryGetValue(displayName, out var filteredCount) ? filteredCount : 0;
134+
}
135+
136+
return new Filter
122137
{
123-
var displayName = f.Value?.ToString()?.ToLower() ?? "";
124-
var isSelected = appliedValues.Any(av => av.Equals(f.Value?.ToString(), StringComparison.OrdinalIgnoreCase));
138+
DisplayName = displayName,
139+
Count = count,
140+
Selected = isSelected
141+
};
142+
}).ToList();
125143

126-
// Use filtered count if available and filter is not selected, otherwise use unfiltered count
127-
var count = !isSelected && filteredFacetValues.ContainsKey(displayName)
128-
? filteredFacetValues[displayName]
129-
: (int)f.Count;
144+
// Ensure all selected filter values remain visible even if absent from the unfiltered
145+
// baseline (e.g. a resource selected under a resource-level filter that yields no results).
146+
foreach (var selectedValue in appliedValues)
147+
{
148+
var alreadyPresent = filters.Any(f =>
149+
f.DisplayName.Equals(selectedValue, StringComparison.OrdinalIgnoreCase));
130150

131-
return new Filter
151+
if (!alreadyPresent)
152+
{
153+
filters.Add(new Filter
132154
{
133-
DisplayName = displayName,
134-
Count = count,
135-
Selected = isSelected
136-
};
137-
}).ToArray()
155+
DisplayName = selectedValue.ToLower(),
156+
Count = 0,
157+
Selected = true,
158+
});
159+
}
160+
}
161+
162+
facets[index++] = new Facet
163+
{
164+
Id = facetKey,
165+
Filters = filters.ToArray()
138166
};
139167
}
140168

OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/AzureSearch/AzureSearchService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,12 +866,14 @@ private string MapToResourceType(string resourceType)
866866
private async Task<IDictionary<string, IList<FacetResult>>> GetUnfilteredFacetsAsync(
867867
string searchText,
868868
IDictionary<string, IList<FacetResult>> facets,
869-
string? resourceAccessLevel,
869+
string? resourceAccessLevel,
870870
CancellationToken cancellationToken)
871871
{
872872
var normalizedSearch = searchText?.ToLowerInvariant() ?? "*";
873873
var accessLevelKey = resourceAccessLevel?.ToString() ?? "null";
874-
var cacheKey = $"AllFacets_{normalizedSearch}_ral_{accessLevelKey}";
874+
var cacheKey = $"Facets_{normalizedSearch}";
875+
if (!string.IsNullOrWhiteSpace(accessLevelKey))
876+
cacheKey += $"_{accessLevelKey.Replace("=", "_")}";
875877

876878
var cacheResponse = await this.cachingService.GetAsync<IDictionary<string, IList<CacheableFacetResult>>>(cacheKey);
877879

0 commit comments

Comments
 (0)