Skip to content

Commit 9c2f83a

Browse files
authored
Added multi live config through URL param ('lc' for LiveConfig) (#959)
1 parent 30d140f commit 9c2f83a

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

apps/demo-app/src/components/App.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { 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';
38
import { useTranslation } from 'react-i18next';
49
import { LiveConfigAppProvider } from '@monkvision/common-ui-web';
510
import { LiveConfig } from '@monkvision/types';
@@ -17,10 +22,14 @@ const localConfig =
1722
export 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}

packages/common/src/apps/searchParams.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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

7075
function 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
}

packages/common/test/apps/searchParams.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)