Skip to content

Commit

Permalink
Merge pull request #1825 from TheScienceMuseum/fix-search-title
Browse files Browse the repository at this point in the history
Fix search title
  • Loading branch information
jamieu authored Sep 9, 2024
2 parents 293da85 + 692e05d commit bd7aec3
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/helpers/search-results-to-template-data/title-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const nameFromFilter = function (selectedFilters) {
'gallery',
'occupation',
'type',
'places',
'object_type',
'material',
'makers',
Expand All @@ -42,7 +43,6 @@ const nameFromFilter = function (selectedFilters) {
}

// no other filters

if (otherFilters.length === 0) {
const filterKeys = Object.keys(selectedFilters);
if (filterKeys.length >= 2) {
Expand All @@ -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 =
Expand All @@ -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
);
}
}
}
Expand All @@ -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;
};

Expand All @@ -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':
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bd7aec3

Please sign in to comment.