Skip to content

Commit

Permalink
Merge pull request #21863 from Yoast/535-make-score-endpoints-work-in…
Browse files Browse the repository at this point in the history
…-plain-permalinks

Make score endpoints work in plain permalinks
  • Loading branch information
igorschoester authored Nov 27, 2024
2 parents 589303a + edefefe commit 20cac14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions packages/js/src/dashboard/scores/components/scores.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ import { TermFilter } from "./term-filter";
* @returns {URL} The URL to get scores.
*/
const createScoresUrl = ( endpoint, contentType, term ) => {
const searchParams = new URLSearchParams( { contentType: contentType.name } );
const url = new URL( endpoint );

url.searchParams.set( "contentType", contentType.name );

if ( contentType.taxonomy?.name && term?.name ) {
searchParams.set( "taxonomy", contentType.taxonomy.name );
searchParams.set( "term", term.name );
url.searchParams.set( "taxonomy", contentType.taxonomy.name );
url.searchParams.set( "term", term.name );
}
return new URL( "?" + searchParams, endpoint );

return url;
};

// Added dummy space as content to prevent children prop warnings in the console.
Expand Down
12 changes: 8 additions & 4 deletions packages/js/src/dashboard/scores/components/term-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import { useFetch } from "../../fetch/use-fetch";
* @param {string} query The query.
* @returns {URL} The URL to query for the terms.
*/
const createQueryUrl = ( endpoint, query ) => new URL( "?" + new URLSearchParams( {
search: query,
_fields: [ "id", "name" ],
} ), endpoint );
const createQueryUrl = ( endpoint, query ) => {
const url = new URL( endpoint );

url.searchParams.set( "search", query );
url.searchParams.set( "_fields", [ "id", "name" ] );

return url;
};

/**
* @param {{id: number, name: string}} term The term from the response.
Expand Down

0 comments on commit 20cac14

Please sign in to comment.