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

Fix search title #1825

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Changes from all commits
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
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