@monkvision/common 4.0.12 → 4.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,10 @@ export interface MonkAppState {
28
28
  * which car 360 wireframes to use for the inspection report.
29
29
  */
30
30
  vehicleType: VehicleType | null;
31
+ /**
32
+ * The list of available vehicle types in the app based on the sights in the app config.
33
+ */
34
+ availableVehicleTypes: VehicleType[];
31
35
  /**
32
36
  * The position of the steering wheel.
33
37
  */
@@ -44,6 +44,11 @@ function getSights(config, vehicleType, steeringWheel) {
44
44
  return sights_1.sights[id];
45
45
  });
46
46
  }
47
+ function getAvailableVehicleTypes(config) {
48
+ return (config.enableSteeringWheelPosition
49
+ ? Object.keys(config.sights.left)
50
+ : Object.keys(config.sights));
51
+ }
47
52
  /**
48
53
  * A React context provider that declares the state for the common parameters used by Monk applications. The parameters
49
54
  * are described in the `MonkAppState` interface. Using options available in the App config (`config` prop), this
@@ -60,7 +65,8 @@ function MonkAppStateProvider(_a) {
60
65
  var _c = (0, react_1.useState)(null), inspectionId = _c[0], setInspectionId = _c[1];
61
66
  var _d = (0, react_1.useState)(null), vehicleType = _d[0], setVehicleType = _d[1];
62
67
  var _e = (0, react_1.useState)(null), steeringWheel = _e[0], setSteeringWheel = _e[1];
63
- var monkSearchParams = (0, searchParams_1.useMonkSearchParams)();
68
+ var availableVehicleTypes = (0, react_1.useMemo)(function () { return getAvailableVehicleTypes(config); }, [config]);
69
+ var monkSearchParams = (0, searchParams_1.useMonkSearchParams)({ availableVehicleTypes: availableVehicleTypes });
64
70
  (0, monitoring_1.useAppStateMonitoring)({ authToken: authToken, inspectionId: inspectionId, vehicleType: vehicleType, steeringWheel: steeringWheel });
65
71
  (0, analytics_1.useAppStateAnalytics)({ inspectionId: inspectionId });
66
72
  (0, react_1.useEffect)(function () {
@@ -89,6 +95,7 @@ function MonkAppStateProvider(_a) {
89
95
  authToken: authToken,
90
96
  inspectionId: inspectionId,
91
97
  vehicleType: vehicleType,
98
+ availableVehicleTypes: availableVehicleTypes,
92
99
  steeringWheel: steeringWheel,
93
100
  getCurrentSights: getCurrentSights,
94
101
  setAuthToken: setAuthToken,
@@ -50,11 +50,22 @@ export type MonkSearchParamsGetter = {
50
50
  (param: MonkSearchParam.STEERING_WHEEL): SteeringWheelPosition | null;
51
51
  (param: MonkSearchParam.LANGUAGE): MonkLanguage | null;
52
52
  };
53
+ /**
54
+ * Options accepted by the useMonkSearchParams hook.
55
+ */
56
+ export interface UseMonkSearchParamsOptions {
57
+ /**
58
+ * The list of available vehicle types to allow.
59
+ *
60
+ * @default Object.values(VehicleType)
61
+ */
62
+ availableVehicleTypes?: VehicleType[];
63
+ }
53
64
  /**
54
65
  * Custom hook used to return a getter function used to fetch the value of different MonkSearchParams.
55
66
  *
56
67
  * @see MonkSearchParam
57
68
  */
58
- export declare function useMonkSearchParams(): {
69
+ export declare function useMonkSearchParams({ availableVehicleTypes }?: UseMonkSearchParamsOptions): {
59
70
  get: MonkSearchParamsGetter;
60
71
  };
@@ -56,7 +56,8 @@ function validateParamValue(value, validValues) {
56
56
  *
57
57
  * @see MonkSearchParam
58
58
  */
59
- function useMonkSearchParams() {
59
+ function useMonkSearchParams(_a) {
60
+ var _b = _a === void 0 ? {} : _a, availableVehicleTypes = _b.availableVehicleTypes;
60
61
  var searchParams = (0, hooks_1.useSearchParams)();
61
62
  var get = (0, react_1.useCallback)(function (param) {
62
63
  var value = searchParams.get(param);
@@ -66,7 +67,7 @@ function useMonkSearchParams() {
66
67
  case MonkSearchParam.INSPECTION_ID:
67
68
  return value;
68
69
  case MonkSearchParam.VEHICLE_TYPE:
69
- return validateParamValue(value, types_1.VehicleType);
70
+ return validateParamValue(value, availableVehicleTypes !== null && availableVehicleTypes !== void 0 ? availableVehicleTypes : types_1.VehicleType);
70
71
  case MonkSearchParam.STEERING_WHEEL:
71
72
  return validateParamValue(value, types_1.SteeringWheelPosition);
72
73
  case MonkSearchParam.LANGUAGE:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkvision/common",
3
- "version": "4.0.12",
3
+ "version": "4.0.14",
4
4
  "license": "BSD-3-Clause-Clear",
5
5
  "packageManager": "yarn@3.2.4",
6
6
  "description": "MonkJs common logic package",
@@ -28,10 +28,10 @@
28
28
  "lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
29
29
  },
30
30
  "dependencies": {
31
- "@monkvision/analytics": "4.0.12",
32
- "@monkvision/monitoring": "4.0.12",
33
- "@monkvision/sights": "4.0.12",
34
- "@monkvision/types": "4.0.12",
31
+ "@monkvision/analytics": "4.0.14",
32
+ "@monkvision/monitoring": "4.0.14",
33
+ "@monkvision/sights": "4.0.14",
34
+ "@monkvision/types": "4.0.14",
35
35
  "i18next": "^23.4.5",
36
36
  "jsonwebtoken": "^9.0.2",
37
37
  "jwt-decode": "^4.0.0",
@@ -47,13 +47,13 @@
47
47
  "react-router-dom": "^6.22.3"
48
48
  },
49
49
  "devDependencies": {
50
- "@monkvision/eslint-config-base": "4.0.12",
51
- "@monkvision/eslint-config-typescript": "4.0.12",
52
- "@monkvision/eslint-config-typescript-react": "4.0.12",
53
- "@monkvision/jest-config": "4.0.12",
54
- "@monkvision/prettier-config": "4.0.12",
55
- "@monkvision/test-utils": "4.0.12",
56
- "@monkvision/typescript-config": "4.0.12",
50
+ "@monkvision/eslint-config-base": "4.0.14",
51
+ "@monkvision/eslint-config-typescript": "4.0.14",
52
+ "@monkvision/eslint-config-typescript-react": "4.0.14",
53
+ "@monkvision/jest-config": "4.0.14",
54
+ "@monkvision/prettier-config": "4.0.14",
55
+ "@monkvision/test-utils": "4.0.14",
56
+ "@monkvision/typescript-config": "4.0.14",
57
57
  "@testing-library/react": "^12.1.5",
58
58
  "@testing-library/react-hooks": "^8.0.1",
59
59
  "@types/jest": "^29.2.2",
@@ -96,5 +96,5 @@
96
96
  "url": "https://github.com/monkvision/monkjs/issues"
97
97
  },
98
98
  "homepage": "https://github.com/monkvision/monkjs",
99
- "gitHead": "ea97b32b05c280175bbeda6b6af10f1cf1a192bf"
99
+ "gitHead": "ef206bab4a5ad0e8a8f94dee02ea4315ba1d9c7c"
100
100
  }