Skip to content

Commit

Permalink
fix(search): 馃悰 handle multiple redirect key in Action Search Client
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair3149 committed Aug 4, 2023
1 parent 0c84c9d commit 0dd3a82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions resources/skins.citizen.search/searchClients/mwActionApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,20 @@ function adaptApiResponse( config, query, response, showDescription ) {
// Merge redirects array into pages array if avaliable
// So the from key can be used for matched title
if ( response.redirects ) {
const pageCount = response.pages.length;

response.pages = Object.values(
[ ...response.redirects, ...response.pages ].reduce( ( acc, curr ) => {
const index = curr.index;
acc[ index ] = { ...acc[ index ], ...curr };
return acc;
}, [] )
);

// Sometimes there can be multiple redirect object for the same page, only take the one with lower index
if ( response.pages.length !== pageCount ) {
response.pages = response.pages.filter( ( obj ) => { return obj.hasOwnProperty( 'title' ); } );
}
}

// Sort pages by index key instead of page id
Expand Down
4 changes: 1 addition & 3 deletions resources/skins.citizen.search/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ function getSuggestions( placeholder ) {
title: highlightTitle( result.title ),
desc: result.description
};
if ( result.label ) {
data.label = getRedirectLabel( result.title, result.label );
}
data.label = getRedirectLabel( result.title, result.label );
if ( result.thumbnail ) {
data.thumbnail = result.thumbnail.url;
} else {
Expand Down

0 comments on commit 0dd3a82

Please sign in to comment.