@@ -17,6 +17,7 @@ const emptySearch = {
1717 params : {
1818 terms : '' ,
1919 facets : { } ,
20+ external : '' ,
2021 page : 1 ,
2122 preset_search : undefined ,
2223 order : undefined
@@ -74,6 +75,15 @@ export function useContextStudySearch() {
7475 return useContext ( StudySearchContext )
7576}
7677
78+ /** Merges the external parameter into the searchParams object */
79+ export function mergeExternalParam ( searchParams , newParams ) {
80+ if ( Object . keys ( newParams ) . length === 1 && Object . keys ( newParams ) [ 0 ] === 'external' ) {
81+ return newParams . external
82+ } else {
83+ return searchParams . external
84+ }
85+ }
86+
7787/**
7888 * renders a StudySearchContext tied to its props,
7989 * fires route navigate on changes to params
@@ -97,6 +107,7 @@ export function PropsStudySearchProvider(props) {
97107 // reset the page to 1 for new searches, unless otherwise specified
98108 search . page = newParams . page ? newParams . page : 1
99109 search . preset = undefined // for now, exclude preset from the page URL--it's in the component props instead
110+ search . external = mergeExternalParam ( searchParams , newParams )
100111 const mergedParams = Object . assign ( buildGeneParamsFromQuery ( window . location . search ) , search )
101112 const queryString = buildSearchQueryString ( 'study' , mergedParams )
102113 navigate ( `?${ queryString } ` )
@@ -153,6 +164,7 @@ export function buildParamsFromQuery(query, preset) {
153164 page : queryParams . page ? parseInt ( queryParams . page ) : 1 ,
154165 terms : queryParams . terms ? queryParams . terms : '' ,
155166 facets : buildFacetsFromQueryString ( queryParams . facets ) ,
167+ external : queryParams . external ? queryParams . external : '' ,
156168 preset : preset ? preset : queryString . preset_search ,
157169 order : queryParams . order
158170 }
0 commit comments