From 9b09966e8af147a7378d18f70581f02f660d93ab Mon Sep 17 00:00:00 2001 From: Evan Parker <65721884+evancp87@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:21:37 +0100 Subject: [PATCH 1/2] refactor: added multiple filters in title el --- .../title-page.js | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) 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..8aee994d 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) { @@ -50,9 +50,7 @@ const nameFromFilter = function (selectedFilters) { const filterType = filterKeys.filter( (k) => k !== '' && k !== 'search' && k !== 'type' ); - if (filterType.length > 0) { - const firstFilterType = filterType[0]; const museum = selectedFilters.museum && Object.keys(selectedFilters.museum)[0]; const gallery = @@ -71,10 +69,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 +83,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 +91,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 +135,18 @@ function handleFilter (filterType, filterValue) { return ''; } +function handleMultipleFilters (filterTypes, selectedFilters) { + return filterTypes + .slice(0, 3) + .map((filterType) => { + const filterValue = + selectedFilters[filterType] && + Object.keys(selectedFilters[filterType])[0]; + return handleFilter(filterType, filterValue); + }) + .join('+ '); +} + module.exports = function (q, selectedFilters) { const name = nameFromFilter(selectedFilters); if (!q && name) { From 692e05d62bcccfb82ecb79c335e555872b7e2ffb Mon Sep 17 00:00:00 2001 From: Evan Parker <65721884+evancp87@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:46:40 +0100 Subject: [PATCH 2/2] feat: multiples of same filter type now can be added to page title --- lib/helpers/search-results-to-template-data/title-page.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 8aee994d..92992843 100644 --- a/lib/helpers/search-results-to-template-data/title-page.js +++ b/lib/helpers/search-results-to-template-data/title-page.js @@ -50,6 +50,7 @@ const nameFromFilter = function (selectedFilters) { const filterType = filterKeys.filter( (k) => k !== '' && k !== 'search' && k !== 'type' ); + if (filterType.length > 0) { const museum = selectedFilters.museum && Object.keys(selectedFilters.museum)[0]; @@ -140,8 +141,7 @@ function handleMultipleFilters (filterTypes, selectedFilters) { .slice(0, 3) .map((filterType) => { const filterValue = - selectedFilters[filterType] && - Object.keys(selectedFilters[filterType])[0]; + selectedFilters[filterType] && Object.keys(selectedFilters[filterType]); return handleFilter(filterType, filterValue); }) .join('+ ');