diff --git a/lib/helpers/search-results-to-template-data/title-page.js b/lib/helpers/search-results-to-template-data/title-page.js index 8dbea49f..92992843 100644 --- a/lib/helpers/search-results-to-template-data/title-page.js +++ b/lib/helpers/search-results-to-template-data/title-page.js @@ -20,6 +20,7 @@ const nameFromFilter = function (selectedFilters) { 'gallery', 'occupation', 'type', + 'places', 'object_type', 'material', 'makers', @@ -42,7 +43,6 @@ const nameFromFilter = function (selectedFilters) { } // no other filters - if (otherFilters.length === 0) { const filterKeys = Object.keys(selectedFilters); if (filterKeys.length >= 2) { @@ -52,7 +52,6 @@ const nameFromFilter = function (selectedFilters) { ); if (filterType.length > 0) { - const firstFilterType = filterType[0]; const museum = selectedFilters.museum && Object.keys(selectedFilters.museum)[0]; const gallery = @@ -71,10 +70,12 @@ const nameFromFilter = function (selectedFilters) { } else if (museum && gallery) { name += handleFilter('museumAndGallery', { museum, gallery }); } else { - const filterValue = - selectedFilters[firstFilterType] && - Object.keys(selectedFilters[firstFilterType])[0]; - name += handleFilter(firstFilterType, filterValue); // single case + // builds and layers multiple filters + const [firstFilterType, ...rest] = filterType ?? []; + name += handleMultipleFilters( + [firstFilterType, ...rest], + selectedFilters + ); } } } @@ -83,7 +84,6 @@ const nameFromFilter = function (selectedFilters) { // if category not define "on display..." is converted to "On display..." name = name.charAt(0).toUpperCase() + name.slice(1); } - return name; }; @@ -92,6 +92,8 @@ function handleFilter (filterType, filterValue) { if (filterValue === 'all') { return ''; } + + // handle case for multiple filtertypes, also need to handle or ensure there can be multiple filtervalues i think ? if (filterValue) { switch (filterType) { case 'museum': @@ -134,6 +136,17 @@ function handleFilter (filterType, filterValue) { return ''; } +function handleMultipleFilters (filterTypes, selectedFilters) { + return filterTypes + .slice(0, 3) + .map((filterType) => { + const filterValue = + selectedFilters[filterType] && Object.keys(selectedFilters[filterType]); + return handleFilter(filterType, filterValue); + }) + .join('+ '); +} + module.exports = function (q, selectedFilters) { const name = nameFromFilter(selectedFilters); if (!q && name) {