From 4679b52f4af2b4bf4ac6993e302e246a1e9e951c Mon Sep 17 00:00:00 2001 From: alan-wu Date: Mon, 9 Nov 2026 10:31:34 +1300 Subject: [PATCH] Fix a crash caused by childless category. --- src/components/SearchFilters.vue | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/SearchFilters.vue b/src/components/SearchFilters.vue index 2da6e2c1..f7394566 100644 --- a/src/components/SearchFilters.vue +++ b/src/components/SearchFilters.vue @@ -361,6 +361,9 @@ export default { this.options = data; this.processOptions(); }) + .catch((error) => { + console.error('Failed to populate search filters:', error); + }) .finally(() => { resolve(); }); @@ -513,15 +516,24 @@ export default { */ countTotalFacet: function (facet) { if (['anatomy.organ.category.name'].includes(facet.key)) { - const count = facet.children.reduce((total, num) => { - // The first 'total' will be an object - total = typeof total == 'number' ? total : total.children.length; - return total + num.children.length; - }); - return count; + const childless = facet.children.filter((child) => !child.children?.length); + if (childless.length) { + this.warnChildlessCategories(facet, childless); + } + // A childless category is itself a leaf in the cascader, so count it as one + return facet.children.reduce((total, child) => total + (child.children?.length || 1), 0); } return facet.children.length; }, + /** + * Warn when a category has no sub-categories, which usually indicates + * an indexing/curation error in the Algolia data. + */ + warnChildlessCategories: function (facet, childless) { + const names = childless.map((child) => child.label).join(', '); + const message = `${facet.label}: category without sub-categories found (${names}). This may indicate an indexing issue.`; + console.warn(message); + }, /** * When check/uncheck all child items, automatically check "Show all" */