File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed
apps/demo-app/src/components Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 11import { Outlet , useNavigate } from 'react-router-dom' ;
2- import { getEnvOrThrow , MonkProvider } from '@monkvision/common' ;
2+ import {
3+ getEnvOrThrow ,
4+ MonkProvider ,
5+ MonkSearchParam ,
6+ useMonkSearchParams ,
7+ } from '@monkvision/common' ;
38import { useTranslation } from 'react-i18next' ;
49import { LiveConfigAppProvider } from '@monkvision/common-ui-web' ;
510import { LiveConfig } from '@monkvision/types' ;
@@ -17,10 +22,14 @@ const localConfig =
1722export function App ( ) {
1823 const navigate = useNavigate ( ) ;
1924 const { i18n } = useTranslation ( ) ;
25+ const monkSearchParams = useMonkSearchParams ( ) ;
2026
2127 return (
2228 < LiveConfigAppProvider
23- id = { getEnvOrThrow ( 'REACT_APP_LIVE_CONFIG_ID' ) }
29+ id = {
30+ monkSearchParams . get ( MonkSearchParam . LIVE_CONFIG ) ??
31+ getEnvOrThrow ( 'REACT_APP_LIVE_CONFIG_ID' )
32+ }
2433 localConfig = { localConfig }
2534 apiDomain = { getAuthConfig ( authConfigs ) ?. apiDomain }
2635 thumbnailDomain = { getAuthConfig ( authConfigs ) ?. thumbnailDomain }
Original file line number Diff line number Diff line change @@ -53,6 +53,10 @@ export enum MonkSearchParam {
5353 * Search parameter used to specify the Auth0 Client ID.
5454 */
5555 CLIENT_ID = 'c' ,
56+ /**
57+ * Search parameter used to specify the live configuration to use.
58+ */
59+ LIVE_CONFIG = 'lc' ,
5660}
5761
5862/**
@@ -65,6 +69,7 @@ export type MonkSearchParamsGetter = {
6569 ( param : MonkSearchParam . STEERING_WHEEL ) : SteeringWheelPosition | null ;
6670 ( param : MonkSearchParam . LANGUAGE ) : MonkLanguage | null ;
6771 ( param : MonkSearchParam . CLIENT_ID ) : string | null ;
72+ ( param : MonkSearchParam . LIVE_CONFIG ) : string | null ;
6873} ;
6974
7075function validateParamValue < T extends string > (
@@ -115,6 +120,8 @@ export function useMonkSearchParams({ availableVehicleTypes }: UseMonkSearchPara
115120 return validateParamValue ( value , monkLanguages ) ;
116121 case MonkSearchParam . CLIENT_ID :
117122 return value ;
123+ case MonkSearchParam . LIVE_CONFIG :
124+ return value ;
118125 default :
119126 return null ;
120127 }
Original file line number Diff line number Diff line change @@ -180,5 +180,23 @@ describe('MonkSearchParams utils', () => {
180180
181181 unmount ( ) ;
182182 } ) ;
183+
184+ it ( 'should return a null live config ID if it is not found in the search params' , ( ) => {
185+ const { result, unmount } = renderHook ( useMonkSearchParams ) ;
186+
187+ expect ( result . current . get ( MonkSearchParam . LIVE_CONFIG ) ) . toBeNull ( ) ;
188+
189+ unmount ( ) ;
190+ } ) ;
191+
192+ it ( 'should return the live config ID if it is found in the search params' , ( ) => {
193+ const liveConfigId = 'test-id-test' ;
194+ mockSearchParams ( { [ MonkSearchParam . LIVE_CONFIG ] : liveConfigId } ) ;
195+ const { result, unmount } = renderHook ( useMonkSearchParams ) ;
196+
197+ expect ( result . current . get ( MonkSearchParam . LIVE_CONFIG ) ) . toEqual ( liveConfigId ) ;
198+
199+ unmount ( ) ;
200+ } ) ;
183201 } ) ;
184202} ) ;
You can’t perform that action at this time.
0 commit comments