@balena/ui-shared-components 5.4.0 → 5.4.1

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.
@@ -9,7 +9,7 @@ type AnalyticsActionPayload = {
9
9
  } | null;
10
10
  type Action = {
11
11
  type: AnalyticsStoreActions.setAnalyticsData;
12
- payload: AnalyticsActionPayload;
12
+ payload: AnalyticsActionPayload | AnalyticsContext;
13
13
  };
14
14
  type Dispatch = (action: Action) => void;
15
15
  type AnalyticsContext = {
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { AnalyticsUrlParams, createWebTracker, } from 'analytics-client';
3
- import { createContext, useContext, useReducer } from 'react';
3
+ import { createContext, useContext, useEffect, useReducer } from 'react';
4
4
  export var AnalyticsStoreActions;
5
5
  (function (AnalyticsStoreActions) {
6
6
  AnalyticsStoreActions["setAnalyticsData"] = "set_analytics_data";
@@ -36,10 +36,14 @@ const contextReducer = (state, { type, payload }) => {
36
36
  const newUrl = window.location.pathname + (!!newQuery ? `?${newQuery}` : '');
37
37
  window.history.replaceState(null, '', newUrl);
38
38
  }
39
- const analyticsClient = payload.createAnalyticsClient(urlParamsHandler);
40
- const webTracker = analyticsClient && payload && 'trackerName' in payload
41
- ? createWebTracker(analyticsClient, payload.trackerName)
42
- : null;
39
+ const analyticsClient = 'analyticsClient' in payload
40
+ ? payload.analyticsClient
41
+ : payload.createAnalyticsClient(urlParamsHandler);
42
+ const webTracker = 'webTracker' in payload
43
+ ? payload.webTracker
44
+ : analyticsClient && payload && 'trackerName' in payload
45
+ ? createWebTracker(analyticsClient, payload.trackerName)
46
+ : null;
43
47
  if (analyticsClient) {
44
48
  urlParamsHandler.setClient(analyticsClient);
45
49
  }
@@ -54,7 +58,15 @@ const contextReducer = (state, { type, payload }) => {
54
58
  }
55
59
  };
56
60
  export const AnalyticsContextProvider = ({ initialState, children }) => {
57
- const [state, dispatch] = useReducer(contextReducer, initialState !== null && initialState !== void 0 ? initialState : initialContext);
61
+ const [state, dispatch] = useReducer(contextReducer, initialContext);
62
+ useEffect(() => {
63
+ if (initialState) {
64
+ dispatch({
65
+ type: AnalyticsStoreActions.setAnalyticsData,
66
+ payload: initialState,
67
+ });
68
+ }
69
+ }, [initialState]);
58
70
  const value = { state, dispatch };
59
71
  return (_jsx(AnalyticsStateContext.Provider, Object.assign({ value: value }, { children: children })));
60
72
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balena/ui-shared-components",
3
- "version": "5.4.0",
3
+ "version": "5.4.1",
4
4
  "main": "./dist/index.js",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -110,6 +110,6 @@
110
110
  },
111
111
  "homepage": "https://github.com/balena-io/ui-shared-components#readme",
112
112
  "versionist": {
113
- "publishedAt": "2024-04-18T17:04:07.206Z"
113
+ "publishedAt": "2024-04-19T15:47:47.163Z"
114
114
  }
115
115
  }