Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent TermsFilter from having to deal with empty strings #8727

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public void ApplyFilter(dynamic context) {
var termIds = (string)context.State.TermIds;

if (!String.IsNullOrEmpty(termIds)) {
var ids = termIds.Split(new[] { ',' }).Select(Int32.Parse).ToArray();
var ids = termIds.Split(new[] { ',' })
MatteoPiovanelli-Laser marked this conversation as resolved.
Show resolved Hide resolved
// Int32.Parse throws for empty strings
.Where(x => !string.IsNullOrWhiteSpace(x))
.Select(Int32.Parse).ToArray();

if (ids.Length == 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ public void Describe(dynamic context) {
);

foreach (var taxonomy in _taxonomyService.GetTaxonomies()) {
f._Terms.Add(new SelectListItem { Value = String.Empty, Text = taxonomy.Name });
var tGroup = new SelectListGroup { Name = taxonomy.Name };
f._Terms.Add(tGroup);
foreach (var term in _taxonomyService.GetTerms(taxonomy.Id)) {
var gap = new string('-', term.GetLevels());

if (gap.Length > 0) {
gap += " ";
}

f._Terms.Add(new SelectListItem { Value = term.Id.ToString(), Text = gap + term.Name });
f._Terms.Add(new SelectListItem {
Value = term.Id.ToString(),
Text = gap + term.Name,
Group = tGroup
});
}
}

Expand Down