@trackunit/react-core-hooks 0.2.64 → 0.2.66
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.
- package/index.cjs +387 -387
- package/index.js +387 -387
- package/package.json +5 -5
- package/src/analytics/AnalyticsProvider.d.ts +23 -23
- package/src/assetSorting/AssetSortingProvider.d.ts +36 -36
- package/src/environment/EnvironmentContextProvider.d.ts +23 -23
- package/src/global-selection/GlobalSelectionProvider.d.ts +26 -26
- package/src/index.d.ts +16 -16
- package/src/irisOemApp/IrisOemAppContextProvider.d.ts +24 -24
- package/src/runtimes/navigation/index.d.ts +1 -1
- package/src/runtimes/navigation/useDeeplink.d.ts +4 -4
- package/src/runtimes/navigation/useNavigationRuntime.d.ts +17 -17
- package/src/runtimes/navigation/useURLSynchronization.d.ts +4 -4
- package/src/runtimes/useAssetRuntime.d.ts +22 -22
- package/src/runtimes/useCustomFieldRuntime.d.ts +9 -9
- package/src/runtimes/useCustomFieldRuntimeForEntity.d.ts +23 -23
- package/src/runtimes/useRestRuntime.d.ts +10 -10
- package/src/runtimes/useSiteRuntime.d.ts +23 -23
- package/src/subscription/UserSubscriptionProvider.d.ts +24 -24
- package/src/toast/ToastProvider.d.ts +29 -29
- package/src/token/TokenProvider.d.ts +22 -22
- package/src/user/CurrentUserProvider.d.ts +27 -27
package/index.cjs
CHANGED
|
@@ -30,187 +30,187 @@ function _interopNamespace(e) {
|
|
|
30
30
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
31
31
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
32
32
|
|
|
33
|
-
const AnalyticsContext = React.createContext(null);
|
|
34
|
-
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
35
|
-
/**
|
|
36
|
-
* Hook to get the analytics context.
|
|
37
|
-
*
|
|
38
|
-
* @requires AnalyticsProvider
|
|
39
|
-
* @example
|
|
40
|
-
* import { useAnalytics, useEnvironment } from "@trackunit/react-core-hooks";
|
|
41
|
-
* const { logPageView, logEvent } = useAnalytics(AllEvents);
|
|
42
|
-
*
|
|
43
|
-
* // log page view event
|
|
44
|
-
* useEffect(() => {
|
|
45
|
-
* logPageView({ pageName: "login" });
|
|
46
|
-
* }, [logPageView]);
|
|
47
|
-
*
|
|
48
|
-
* // log event when appropriate
|
|
49
|
-
* logEvent("Login", { loginPage: "New Manager" });
|
|
50
|
-
*
|
|
51
|
-
* @see {@link IAnalyticsContext}
|
|
52
|
-
*/
|
|
53
|
-
const useAnalytics = (type) => {
|
|
54
|
-
const context = React.useContext(AnalyticsContext);
|
|
55
|
-
if (!context) {
|
|
56
|
-
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
57
|
-
}
|
|
58
|
-
return context;
|
|
33
|
+
const AnalyticsContext = React.createContext(null);
|
|
34
|
+
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
35
|
+
/**
|
|
36
|
+
* Hook to get the analytics context.
|
|
37
|
+
*
|
|
38
|
+
* @requires AnalyticsProvider
|
|
39
|
+
* @example
|
|
40
|
+
* import { useAnalytics, useEnvironment } from "@trackunit/react-core-hooks";
|
|
41
|
+
* const { logPageView, logEvent } = useAnalytics(AllEvents);
|
|
42
|
+
*
|
|
43
|
+
* // log page view event
|
|
44
|
+
* useEffect(() => {
|
|
45
|
+
* logPageView({ pageName: "login" });
|
|
46
|
+
* }, [logPageView]);
|
|
47
|
+
*
|
|
48
|
+
* // log event when appropriate
|
|
49
|
+
* logEvent("Login", { loginPage: "New Manager" });
|
|
50
|
+
*
|
|
51
|
+
* @see {@link IAnalyticsContext}
|
|
52
|
+
*/
|
|
53
|
+
const useAnalytics = (type) => {
|
|
54
|
+
const context = React.useContext(AnalyticsContext);
|
|
55
|
+
if (!context) {
|
|
56
|
+
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
57
|
+
}
|
|
58
|
+
return context;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
const AssetSortingContext = React.createContext(null);
|
|
62
|
-
/**
|
|
63
|
-
* This is a provider for the AssetSortingContext.
|
|
64
|
-
*/
|
|
65
|
-
const AssetSortingProvider = AssetSortingContext.Provider;
|
|
66
|
-
/**
|
|
67
|
-
* This is a hook to use the AssetSortingContext.
|
|
68
|
-
*
|
|
69
|
-
* @requires AssetSortingProvider
|
|
70
|
-
* @example
|
|
71
|
-
* import { useAssetSorting } from "@trackunit/react-core-hooks";
|
|
72
|
-
* const { sortingState, setSortBy } = useAssetSorting();
|
|
73
|
-
*
|
|
74
|
-
* const initialSort = useMemo(
|
|
75
|
-
* () => ({
|
|
76
|
-
* property: {
|
|
77
|
-
* label: sortingState.sortBy,
|
|
78
|
-
* value: sortingState.sortBy,
|
|
79
|
-
* },
|
|
80
|
-
* order: sortingState.order,
|
|
81
|
-
* }),
|
|
82
|
-
* [sortingState]
|
|
83
|
-
* );
|
|
84
|
-
*
|
|
85
|
-
* return (
|
|
86
|
-
* <Table
|
|
87
|
-
* ...
|
|
88
|
-
* headerOnSort={setSortBy}
|
|
89
|
-
* headerInitialSort={initialSort}
|
|
90
|
-
* />
|
|
91
|
-
* );
|
|
92
|
-
*
|
|
93
|
-
* @see {@link IAssetSortingContext}
|
|
94
|
-
*/
|
|
95
|
-
const useAssetSorting = () => {
|
|
96
|
-
const context = React.useContext(AssetSortingContext);
|
|
97
|
-
if (!context) {
|
|
98
|
-
throw new Error("useAssetSorting must be used within a AssetSortingProvider");
|
|
99
|
-
}
|
|
100
|
-
return context;
|
|
61
|
+
const AssetSortingContext = React.createContext(null);
|
|
62
|
+
/**
|
|
63
|
+
* This is a provider for the AssetSortingContext.
|
|
64
|
+
*/
|
|
65
|
+
const AssetSortingProvider = AssetSortingContext.Provider;
|
|
66
|
+
/**
|
|
67
|
+
* This is a hook to use the AssetSortingContext.
|
|
68
|
+
*
|
|
69
|
+
* @requires AssetSortingProvider
|
|
70
|
+
* @example
|
|
71
|
+
* import { useAssetSorting } from "@trackunit/react-core-hooks";
|
|
72
|
+
* const { sortingState, setSortBy } = useAssetSorting();
|
|
73
|
+
*
|
|
74
|
+
* const initialSort = useMemo(
|
|
75
|
+
* () => ({
|
|
76
|
+
* property: {
|
|
77
|
+
* label: sortingState.sortBy,
|
|
78
|
+
* value: sortingState.sortBy,
|
|
79
|
+
* },
|
|
80
|
+
* order: sortingState.order,
|
|
81
|
+
* }),
|
|
82
|
+
* [sortingState]
|
|
83
|
+
* );
|
|
84
|
+
*
|
|
85
|
+
* return (
|
|
86
|
+
* <Table
|
|
87
|
+
* ...
|
|
88
|
+
* headerOnSort={setSortBy}
|
|
89
|
+
* headerInitialSort={initialSort}
|
|
90
|
+
* />
|
|
91
|
+
* );
|
|
92
|
+
*
|
|
93
|
+
* @see {@link IAssetSortingContext}
|
|
94
|
+
*/
|
|
95
|
+
const useAssetSorting = () => {
|
|
96
|
+
const context = React.useContext(AssetSortingContext);
|
|
97
|
+
if (!context) {
|
|
98
|
+
throw new Error("useAssetSorting must be used within a AssetSortingProvider");
|
|
99
|
+
}
|
|
100
|
+
return context;
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
const EnvironmentContext = React.createContext(null);
|
|
104
|
-
/**
|
|
105
|
-
* This is a provider for the EnvironmentContext.
|
|
106
|
-
*/
|
|
107
|
-
const EnvironmentContextProvider = (props) => {
|
|
108
|
-
return jsxRuntime.jsx(EnvironmentContext.Provider, Object.assign({}, props));
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* This is a hook to use the EnvironmentContext.
|
|
112
|
-
*
|
|
113
|
-
* @requires EnvironmentContext
|
|
114
|
-
* @example
|
|
115
|
-
* import { useEnvironment } from "@trackunit/react-core-hooks";
|
|
116
|
-
* const { googleMapsApiKey } = useEnvironment();
|
|
117
|
-
* // use api key for something...
|
|
118
|
-
*
|
|
119
|
-
* @see (@link IEnvironmentContext)
|
|
120
|
-
*/
|
|
121
|
-
const useEnvironment = () => {
|
|
122
|
-
const context = React.useContext(EnvironmentContext);
|
|
123
|
-
if (!context) {
|
|
124
|
-
throw new Error("useEnvironment must be used within an EnvironmentContext");
|
|
125
|
-
}
|
|
126
|
-
return context;
|
|
103
|
+
const EnvironmentContext = React.createContext(null);
|
|
104
|
+
/**
|
|
105
|
+
* This is a provider for the EnvironmentContext.
|
|
106
|
+
*/
|
|
107
|
+
const EnvironmentContextProvider = (props) => {
|
|
108
|
+
return jsxRuntime.jsx(EnvironmentContext.Provider, Object.assign({}, props));
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* This is a hook to use the EnvironmentContext.
|
|
112
|
+
*
|
|
113
|
+
* @requires EnvironmentContext
|
|
114
|
+
* @example
|
|
115
|
+
* import { useEnvironment } from "@trackunit/react-core-hooks";
|
|
116
|
+
* const { googleMapsApiKey } = useEnvironment();
|
|
117
|
+
* // use api key for something...
|
|
118
|
+
*
|
|
119
|
+
* @see (@link IEnvironmentContext)
|
|
120
|
+
*/
|
|
121
|
+
const useEnvironment = () => {
|
|
122
|
+
const context = React.useContext(EnvironmentContext);
|
|
123
|
+
if (!context) {
|
|
124
|
+
throw new Error("useEnvironment must be used within an EnvironmentContext");
|
|
125
|
+
}
|
|
126
|
+
return context;
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
-
const GlobalSelectionContext = React__namespace.createContext(null);
|
|
130
|
-
/**
|
|
131
|
-
* This is a hook to use the GlobalSelectionContext.
|
|
132
|
-
*
|
|
133
|
-
* @requires GlobalSelectionProvider
|
|
134
|
-
* @example
|
|
135
|
-
* import { useGlobalSelection } from "@trackunit/react-core-hooks";
|
|
136
|
-
*
|
|
137
|
-
* export const useActiveGlobalGroupIdFilter = () => {
|
|
138
|
-
* const { selection } = useGlobalSelection();
|
|
139
|
-
* return (selection?.type === "group") ? selection.groupId : undefined;
|
|
140
|
-
* };
|
|
141
|
-
*
|
|
142
|
-
* @see {@link IGlobalSelectionContext}
|
|
143
|
-
*/
|
|
144
|
-
const useGlobalSelection = () => {
|
|
145
|
-
const context = React__namespace.useContext(GlobalSelectionContext);
|
|
146
|
-
if (!context) {
|
|
147
|
-
throw new Error("useGlobalSelection must be used within the GlobalSelectionContext");
|
|
148
|
-
}
|
|
149
|
-
return context;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* This is a provider for the GlobalSelectionContext.
|
|
153
|
-
*/
|
|
129
|
+
const GlobalSelectionContext = React__namespace.createContext(null);
|
|
130
|
+
/**
|
|
131
|
+
* This is a hook to use the GlobalSelectionContext.
|
|
132
|
+
*
|
|
133
|
+
* @requires GlobalSelectionProvider
|
|
134
|
+
* @example
|
|
135
|
+
* import { useGlobalSelection } from "@trackunit/react-core-hooks";
|
|
136
|
+
*
|
|
137
|
+
* export const useActiveGlobalGroupIdFilter = () => {
|
|
138
|
+
* const { selection } = useGlobalSelection();
|
|
139
|
+
* return (selection?.type === "group") ? selection.groupId : undefined;
|
|
140
|
+
* };
|
|
141
|
+
*
|
|
142
|
+
* @see {@link IGlobalSelectionContext}
|
|
143
|
+
*/
|
|
144
|
+
const useGlobalSelection = () => {
|
|
145
|
+
const context = React__namespace.useContext(GlobalSelectionContext);
|
|
146
|
+
if (!context) {
|
|
147
|
+
throw new Error("useGlobalSelection must be used within the GlobalSelectionContext");
|
|
148
|
+
}
|
|
149
|
+
return context;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* This is a provider for the GlobalSelectionContext.
|
|
153
|
+
*/
|
|
154
154
|
const GlobalSelectionProvider = (props) => jsxRuntime.jsx(GlobalSelectionContext.Provider, Object.assign({}, props));
|
|
155
155
|
|
|
156
|
-
const OemBrandingContext = React.createContext(null);
|
|
157
|
-
/**
|
|
158
|
-
* This is a hook to use the IOemBrandingContext.
|
|
159
|
-
*
|
|
160
|
-
* @requires OemBrandingContextProvider
|
|
161
|
-
* @example
|
|
162
|
-
* import { useOemBrandingContext } from "@trackunit/react-core-hooks";
|
|
163
|
-
* const { getOemBranding, getImageByBrand } = useOemBrandingContext();
|
|
164
|
-
* // use oem branding
|
|
165
|
-
* const branding = getOemBranding("some brand")
|
|
166
|
-
*
|
|
167
|
-
* @see {@link IOemBrandingContext}
|
|
168
|
-
*/
|
|
169
|
-
const useOemBrandingContext = () => {
|
|
170
|
-
const context = React.useContext(OemBrandingContext);
|
|
171
|
-
if (!context) {
|
|
172
|
-
throw new Error("useOemBranding must be used within an OemBrandingContextProvider");
|
|
173
|
-
}
|
|
174
|
-
return context;
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
177
|
-
* This is a provider for the IOemBrandingContext.
|
|
178
|
-
*/
|
|
179
|
-
const OemBrandingContextProvider = (props) => {
|
|
180
|
-
return jsxRuntime.jsx(OemBrandingContext.Provider, Object.assign({}, props));
|
|
156
|
+
const OemBrandingContext = React.createContext(null);
|
|
157
|
+
/**
|
|
158
|
+
* This is a hook to use the IOemBrandingContext.
|
|
159
|
+
*
|
|
160
|
+
* @requires OemBrandingContextProvider
|
|
161
|
+
* @example
|
|
162
|
+
* import { useOemBrandingContext } from "@trackunit/react-core-hooks";
|
|
163
|
+
* const { getOemBranding, getImageByBrand } = useOemBrandingContext();
|
|
164
|
+
* // use oem branding
|
|
165
|
+
* const branding = getOemBranding("some brand")
|
|
166
|
+
*
|
|
167
|
+
* @see {@link IOemBrandingContext}
|
|
168
|
+
*/
|
|
169
|
+
const useOemBrandingContext = () => {
|
|
170
|
+
const context = React.useContext(OemBrandingContext);
|
|
171
|
+
if (!context) {
|
|
172
|
+
throw new Error("useOemBranding must be used within an OemBrandingContextProvider");
|
|
173
|
+
}
|
|
174
|
+
return context;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* This is a provider for the IOemBrandingContext.
|
|
178
|
+
*/
|
|
179
|
+
const OemBrandingContextProvider = (props) => {
|
|
180
|
+
return jsxRuntime.jsx(OemBrandingContext.Provider, Object.assign({}, props));
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
-
/**
|
|
184
|
-
* A react hook for notifying host about location changes
|
|
185
|
-
*/
|
|
186
|
-
const useURLSynchronization = () => {
|
|
187
|
-
const location = reactRouterDom.useLocation();
|
|
188
|
-
React__default["default"].useEffect(() => {
|
|
189
|
-
const deepLink = {
|
|
190
|
-
path: location.pathname,
|
|
191
|
-
search: location.search,
|
|
192
|
-
hash: location.hash,
|
|
193
|
-
pathname: "",
|
|
194
|
-
};
|
|
195
|
-
irisAppRuntimeCore.NavigationRuntime.setDeepLink(deepLink);
|
|
196
|
-
}, [location]);
|
|
183
|
+
/**
|
|
184
|
+
* A react hook for notifying host about location changes
|
|
185
|
+
*/
|
|
186
|
+
const useURLSynchronization = () => {
|
|
187
|
+
const location = reactRouterDom.useLocation();
|
|
188
|
+
React__default["default"].useEffect(() => {
|
|
189
|
+
const deepLink = {
|
|
190
|
+
path: location.pathname,
|
|
191
|
+
search: location.search,
|
|
192
|
+
hash: location.hash,
|
|
193
|
+
pathname: "",
|
|
194
|
+
};
|
|
195
|
+
irisAppRuntimeCore.NavigationRuntime.setDeepLink(deepLink);
|
|
196
|
+
}, [location]);
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
/**
|
|
200
|
-
* A hook to expose navigation runtime for React components
|
|
201
|
-
*
|
|
202
|
-
* @requires NavigationRuntime
|
|
203
|
-
* @returns {UseNavigationRuntime} navigationRuntime
|
|
204
|
-
* @example
|
|
205
|
-
* import { useNavigationRuntime } from "@trackunit/react-core-hooks";
|
|
206
|
-
* const { navigateTo } = useNavigationRuntime();
|
|
207
|
-
* // ...
|
|
208
|
-
* <Link onClick={() => gotoAssetHome(asset.id)} to="">
|
|
209
|
-
* {asset.name}
|
|
210
|
-
* </Link>
|
|
211
|
-
*/
|
|
212
|
-
const useNavigationRuntime = () => {
|
|
213
|
-
return irisAppRuntimeCore.NavigationRuntime;
|
|
199
|
+
/**
|
|
200
|
+
* A hook to expose navigation runtime for React components
|
|
201
|
+
*
|
|
202
|
+
* @requires NavigationRuntime
|
|
203
|
+
* @returns {UseNavigationRuntime} navigationRuntime
|
|
204
|
+
* @example
|
|
205
|
+
* import { useNavigationRuntime } from "@trackunit/react-core-hooks";
|
|
206
|
+
* const { navigateTo } = useNavigationRuntime();
|
|
207
|
+
* // ...
|
|
208
|
+
* <Link onClick={() => gotoAssetHome(asset.id)} to="">
|
|
209
|
+
* {asset.name}
|
|
210
|
+
* </Link>
|
|
211
|
+
*/
|
|
212
|
+
const useNavigationRuntime = () => {
|
|
213
|
+
return irisAppRuntimeCore.NavigationRuntime;
|
|
214
214
|
};
|
|
215
215
|
|
|
216
216
|
/******************************************************************************
|
|
@@ -238,240 +238,240 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
/**
|
|
242
|
-
* A hook to expose asset runtime for React components
|
|
243
|
-
*
|
|
244
|
-
* @requires AssetRuntime
|
|
245
|
-
* @returns {UseAssetRuntime} assetRuntime
|
|
246
|
-
* @example
|
|
247
|
-
* import { useAssetRuntime } from "@trackunit/react-core-hooks";
|
|
248
|
-
* const { assetInfo } = useAssetRuntime();
|
|
249
|
-
* useEffect(() => {
|
|
250
|
-
* (async () => {
|
|
251
|
-
* if (assetInfo) {
|
|
252
|
-
* getAssetLocation({ variables: { id: assetInfo.assetId } });
|
|
253
|
-
* }
|
|
254
|
-
* })();
|
|
255
|
-
* }, [assetInfo, getAssetLocation]);
|
|
256
|
-
*
|
|
257
|
-
*/
|
|
258
|
-
const useAssetRuntime = () => {
|
|
259
|
-
const [assetInfo, setAssetInfo] = React.useState();
|
|
260
|
-
React.useEffect(() => {
|
|
261
|
-
const getAssetInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
-
const updatedAssetInfo = yield irisAppRuntimeCore.AssetRuntime.getAssetInfo();
|
|
263
|
-
setAssetInfo(updatedAssetInfo);
|
|
264
|
-
});
|
|
265
|
-
getAssetInfo();
|
|
266
|
-
}, []);
|
|
267
|
-
return { assetInfo };
|
|
241
|
+
/**
|
|
242
|
+
* A hook to expose asset runtime for React components
|
|
243
|
+
*
|
|
244
|
+
* @requires AssetRuntime
|
|
245
|
+
* @returns {UseAssetRuntime} assetRuntime
|
|
246
|
+
* @example
|
|
247
|
+
* import { useAssetRuntime } from "@trackunit/react-core-hooks";
|
|
248
|
+
* const { assetInfo } = useAssetRuntime();
|
|
249
|
+
* useEffect(() => {
|
|
250
|
+
* (async () => {
|
|
251
|
+
* if (assetInfo) {
|
|
252
|
+
* getAssetLocation({ variables: { id: assetInfo.assetId } });
|
|
253
|
+
* }
|
|
254
|
+
* })();
|
|
255
|
+
* }, [assetInfo, getAssetLocation]);
|
|
256
|
+
*
|
|
257
|
+
*/
|
|
258
|
+
const useAssetRuntime = () => {
|
|
259
|
+
const [assetInfo, setAssetInfo] = React.useState();
|
|
260
|
+
React.useEffect(() => {
|
|
261
|
+
const getAssetInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
+
const updatedAssetInfo = yield irisAppRuntimeCore.AssetRuntime.getAssetInfo();
|
|
263
|
+
setAssetInfo(updatedAssetInfo);
|
|
264
|
+
});
|
|
265
|
+
getAssetInfo();
|
|
266
|
+
}, []);
|
|
267
|
+
return { assetInfo };
|
|
268
268
|
};
|
|
269
269
|
|
|
270
|
-
/**
|
|
271
|
-
* A hook to expose custom field runtime methods
|
|
272
|
-
*
|
|
273
|
-
* @returns {UseCustomFieldRuntime} CustomFieldRuntime
|
|
274
|
-
*/
|
|
275
|
-
const useCustomFieldRuntime = () => {
|
|
276
|
-
return irisAppRuntimeCore.CustomFieldRuntime;
|
|
270
|
+
/**
|
|
271
|
+
* A hook to expose custom field runtime methods
|
|
272
|
+
*
|
|
273
|
+
* @returns {UseCustomFieldRuntime} CustomFieldRuntime
|
|
274
|
+
*/
|
|
275
|
+
const useCustomFieldRuntime = () => {
|
|
276
|
+
return irisAppRuntimeCore.CustomFieldRuntime;
|
|
277
277
|
};
|
|
278
278
|
|
|
279
|
-
/**
|
|
280
|
-
* This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
|
|
281
|
-
*
|
|
282
|
-
* @param entity The entity to fetch and set custom fields for.
|
|
283
|
-
* @returns The custom fields for the entity, and functions to set custom fields for the entity.
|
|
284
|
-
* @example
|
|
285
|
-
* import { useAssetRuntime, useCustomFieldRuntimeForEntity } from '@trackunit/react-core-hooks';
|
|
286
|
-
* const { assetInfo } = useAssetRuntime();
|
|
287
|
-
* const { customFields, setCustomFieldsForEntity } = useCustomFieldRuntimeForEntity( {
|
|
288
|
-
* id: assetInfo?.assetId || '',
|
|
289
|
-
* type: 'ASSET'
|
|
290
|
-
* });
|
|
291
|
-
*
|
|
292
|
-
* // set custom field data
|
|
293
|
-
* setCustomFieldsForEntity({"key": "value"});
|
|
294
|
-
*/
|
|
295
|
-
const useCustomFieldRuntimeForEntity = (entity) => {
|
|
296
|
-
const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
|
|
297
|
-
const [customFields, setCustomFields] = React.useState();
|
|
298
|
-
React.useEffect(() => {
|
|
299
|
-
if (entity.id) {
|
|
300
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
-
setCustomFields(yield getCustomFieldsFor(entity));
|
|
302
|
-
}))();
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
setCustomFields([]);
|
|
306
|
-
}
|
|
307
|
-
}, [entity, getCustomFieldsFor]);
|
|
308
|
-
const setCustomFieldsForEntity = (values) => __awaiter(void 0, void 0, void 0, function* () {
|
|
309
|
-
if (entity.id) {
|
|
310
|
-
yield setCustomFieldsFor(entity, values);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
const setCustomFieldsFromFormDataForEntity = (formData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
314
|
-
if (entity.id) {
|
|
315
|
-
yield setCustomFieldsFromFormData(entity, formData, customFields || []);
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
return {
|
|
319
|
-
customFields,
|
|
320
|
-
setCustomFieldsFromFormDataForEntity,
|
|
321
|
-
setCustomFieldsForEntity,
|
|
322
|
-
};
|
|
279
|
+
/**
|
|
280
|
+
* This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
|
|
281
|
+
*
|
|
282
|
+
* @param entity The entity to fetch and set custom fields for.
|
|
283
|
+
* @returns The custom fields for the entity, and functions to set custom fields for the entity.
|
|
284
|
+
* @example
|
|
285
|
+
* import { useAssetRuntime, useCustomFieldRuntimeForEntity } from '@trackunit/react-core-hooks';
|
|
286
|
+
* const { assetInfo } = useAssetRuntime();
|
|
287
|
+
* const { customFields, setCustomFieldsForEntity } = useCustomFieldRuntimeForEntity( {
|
|
288
|
+
* id: assetInfo?.assetId || '',
|
|
289
|
+
* type: 'ASSET'
|
|
290
|
+
* });
|
|
291
|
+
*
|
|
292
|
+
* // set custom field data
|
|
293
|
+
* setCustomFieldsForEntity({"key": "value"});
|
|
294
|
+
*/
|
|
295
|
+
const useCustomFieldRuntimeForEntity = (entity) => {
|
|
296
|
+
const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
|
|
297
|
+
const [customFields, setCustomFields] = React.useState();
|
|
298
|
+
React.useEffect(() => {
|
|
299
|
+
if (entity.id) {
|
|
300
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
+
setCustomFields(yield getCustomFieldsFor(entity));
|
|
302
|
+
}))();
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
setCustomFields([]);
|
|
306
|
+
}
|
|
307
|
+
}, [entity, getCustomFieldsFor]);
|
|
308
|
+
const setCustomFieldsForEntity = (values) => __awaiter(void 0, void 0, void 0, function* () {
|
|
309
|
+
if (entity.id) {
|
|
310
|
+
yield setCustomFieldsFor(entity, values);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
const setCustomFieldsFromFormDataForEntity = (formData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
314
|
+
if (entity.id) {
|
|
315
|
+
yield setCustomFieldsFromFormData(entity, formData, customFields || []);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
return {
|
|
319
|
+
customFields,
|
|
320
|
+
setCustomFieldsFromFormDataForEntity,
|
|
321
|
+
setCustomFieldsForEntity,
|
|
322
|
+
};
|
|
323
323
|
};
|
|
324
324
|
|
|
325
|
-
/**
|
|
326
|
-
* A hook to expose rest runtime to be used in React components
|
|
327
|
-
*
|
|
328
|
-
* @returns {UseRestRuntime} a RestRuntime
|
|
329
|
-
*/
|
|
330
|
-
const useRestRuntime = () => {
|
|
331
|
-
return irisAppRuntimeCore.RestRuntime;
|
|
325
|
+
/**
|
|
326
|
+
* A hook to expose rest runtime to be used in React components
|
|
327
|
+
*
|
|
328
|
+
* @returns {UseRestRuntime} a RestRuntime
|
|
329
|
+
*/
|
|
330
|
+
const useRestRuntime = () => {
|
|
331
|
+
return irisAppRuntimeCore.RestRuntime;
|
|
332
332
|
};
|
|
333
333
|
|
|
334
|
-
/**
|
|
335
|
-
* A hook to expose site runtime for React components
|
|
336
|
-
*
|
|
337
|
-
* @requires SiteRuntime
|
|
338
|
-
* @returns {UseSiteRuntime} siteRuntime
|
|
339
|
-
* @example
|
|
340
|
-
* import { useSiteRuntime } from "@trackunit/react-core-hooks";
|
|
341
|
-
* const { siteInfo } = useSiteRuntime();
|
|
342
|
-
* // use siteInfo to get assets for instance.
|
|
343
|
-
* useEffect(() => {
|
|
344
|
-
* (async () => {
|
|
345
|
-
* if (siteInfo?.siteId) {
|
|
346
|
-
* getSiteAssets({ variables: { siteId: siteInfo?.siteId, siteIdStr: siteInfo?.siteId } });
|
|
347
|
-
* }
|
|
348
|
-
* })();
|
|
349
|
-
* }, [getSiteAssets, siteInfo]);
|
|
350
|
-
*
|
|
351
|
-
*/
|
|
352
|
-
const useSiteRuntime = () => {
|
|
353
|
-
const [siteInfo, setSiteInfo] = React.useState();
|
|
354
|
-
React.useEffect(() => {
|
|
355
|
-
const getSiteInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
356
|
-
const updatedSiteInfo = yield irisAppRuntimeCore.SiteRuntime.getSiteInfo();
|
|
357
|
-
setSiteInfo(updatedSiteInfo);
|
|
358
|
-
});
|
|
359
|
-
getSiteInfo();
|
|
360
|
-
}, []);
|
|
361
|
-
return { siteInfo };
|
|
334
|
+
/**
|
|
335
|
+
* A hook to expose site runtime for React components
|
|
336
|
+
*
|
|
337
|
+
* @requires SiteRuntime
|
|
338
|
+
* @returns {UseSiteRuntime} siteRuntime
|
|
339
|
+
* @example
|
|
340
|
+
* import { useSiteRuntime } from "@trackunit/react-core-hooks";
|
|
341
|
+
* const { siteInfo } = useSiteRuntime();
|
|
342
|
+
* // use siteInfo to get assets for instance.
|
|
343
|
+
* useEffect(() => {
|
|
344
|
+
* (async () => {
|
|
345
|
+
* if (siteInfo?.siteId) {
|
|
346
|
+
* getSiteAssets({ variables: { siteId: siteInfo?.siteId, siteIdStr: siteInfo?.siteId } });
|
|
347
|
+
* }
|
|
348
|
+
* })();
|
|
349
|
+
* }, [getSiteAssets, siteInfo]);
|
|
350
|
+
*
|
|
351
|
+
*/
|
|
352
|
+
const useSiteRuntime = () => {
|
|
353
|
+
const [siteInfo, setSiteInfo] = React.useState();
|
|
354
|
+
React.useEffect(() => {
|
|
355
|
+
const getSiteInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
356
|
+
const updatedSiteInfo = yield irisAppRuntimeCore.SiteRuntime.getSiteInfo();
|
|
357
|
+
setSiteInfo(updatedSiteInfo);
|
|
358
|
+
});
|
|
359
|
+
getSiteInfo();
|
|
360
|
+
}, []);
|
|
361
|
+
return { siteInfo };
|
|
362
362
|
};
|
|
363
363
|
|
|
364
|
-
const UserSubscriptionContext = React__namespace.createContext(null);
|
|
365
|
-
/**
|
|
366
|
-
* This is a provider for the UserSubscriptionContext.
|
|
367
|
-
*/
|
|
368
|
-
const UserSubscriptionProvider = (props) => {
|
|
369
|
-
return jsxRuntime.jsx(UserSubscriptionContext.Provider, Object.assign({}, props));
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* This is a hook to use the UserSubscriptionContext.
|
|
373
|
-
*
|
|
374
|
-
* @requires UserSubscriptionProvider
|
|
375
|
-
* @example
|
|
376
|
-
* import { useUserSubscription } from "@trackunit/react-core-hooks";
|
|
377
|
-
* const { numberOfDaysWithAccessToHistoricalData, packageType } = useUserSubscription();
|
|
378
|
-
* // use it for something
|
|
379
|
-
* const data = fetchData(numberOfDaysWithAccessToHistoricalData)
|
|
380
|
-
*
|
|
381
|
-
* @see {@link IUserSubscriptionContext}
|
|
382
|
-
*/
|
|
383
|
-
const useUserSubscription = () => {
|
|
384
|
-
const context = React__namespace.useContext(UserSubscriptionContext);
|
|
385
|
-
if (!context) {
|
|
386
|
-
throw new Error("Cannot use useUserSubscription outside UserSubscriptionProvider");
|
|
387
|
-
}
|
|
388
|
-
return context;
|
|
364
|
+
const UserSubscriptionContext = React__namespace.createContext(null);
|
|
365
|
+
/**
|
|
366
|
+
* This is a provider for the UserSubscriptionContext.
|
|
367
|
+
*/
|
|
368
|
+
const UserSubscriptionProvider = (props) => {
|
|
369
|
+
return jsxRuntime.jsx(UserSubscriptionContext.Provider, Object.assign({}, props));
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* This is a hook to use the UserSubscriptionContext.
|
|
373
|
+
*
|
|
374
|
+
* @requires UserSubscriptionProvider
|
|
375
|
+
* @example
|
|
376
|
+
* import { useUserSubscription } from "@trackunit/react-core-hooks";
|
|
377
|
+
* const { numberOfDaysWithAccessToHistoricalData, packageType } = useUserSubscription();
|
|
378
|
+
* // use it for something
|
|
379
|
+
* const data = fetchData(numberOfDaysWithAccessToHistoricalData)
|
|
380
|
+
*
|
|
381
|
+
* @see {@link IUserSubscriptionContext}
|
|
382
|
+
*/
|
|
383
|
+
const useUserSubscription = () => {
|
|
384
|
+
const context = React__namespace.useContext(UserSubscriptionContext);
|
|
385
|
+
if (!context) {
|
|
386
|
+
throw new Error("Cannot use useUserSubscription outside UserSubscriptionProvider");
|
|
387
|
+
}
|
|
388
|
+
return context;
|
|
389
389
|
};
|
|
390
390
|
|
|
391
|
-
const ToastContext = React__namespace.createContext(null);
|
|
392
|
-
/**
|
|
393
|
-
* This is a provider for the ToastContext.
|
|
394
|
-
*/
|
|
395
|
-
const ToastProvider = (props) => jsxRuntime.jsx(ToastContext.Provider, Object.assign({}, props));
|
|
396
|
-
/**
|
|
397
|
-
* This is a hook to use the ToastContext.
|
|
398
|
-
*
|
|
399
|
-
* @requires ToastProvider
|
|
400
|
-
* @example
|
|
401
|
-
* import { useToast } from "@trackunit/react-core-hooks";
|
|
402
|
-
* const { addToast } = useToast();
|
|
403
|
-
* // use the toast
|
|
404
|
-
* error &&
|
|
405
|
-
* addToast({
|
|
406
|
-
* intent: "warning",
|
|
407
|
-
* title: t("assetHome.specification.failedToSave"),
|
|
408
|
-
* description: error?.message,
|
|
409
|
-
* duration: 3000,
|
|
410
|
-
* });
|
|
411
|
-
*
|
|
412
|
-
* @see {@link IToastContext}
|
|
413
|
-
*/
|
|
414
|
-
const useToast = () => {
|
|
415
|
-
const toastContext = React__namespace.useContext(ToastContext);
|
|
416
|
-
if (!toastContext) {
|
|
417
|
-
throw new Error("useToast must be used within the ToastProvider");
|
|
418
|
-
}
|
|
419
|
-
return toastContext;
|
|
391
|
+
const ToastContext = React__namespace.createContext(null);
|
|
392
|
+
/**
|
|
393
|
+
* This is a provider for the ToastContext.
|
|
394
|
+
*/
|
|
395
|
+
const ToastProvider = (props) => jsxRuntime.jsx(ToastContext.Provider, Object.assign({}, props));
|
|
396
|
+
/**
|
|
397
|
+
* This is a hook to use the ToastContext.
|
|
398
|
+
*
|
|
399
|
+
* @requires ToastProvider
|
|
400
|
+
* @example
|
|
401
|
+
* import { useToast } from "@trackunit/react-core-hooks";
|
|
402
|
+
* const { addToast } = useToast();
|
|
403
|
+
* // use the toast
|
|
404
|
+
* error &&
|
|
405
|
+
* addToast({
|
|
406
|
+
* intent: "warning",
|
|
407
|
+
* title: t("assetHome.specification.failedToSave"),
|
|
408
|
+
* description: error?.message,
|
|
409
|
+
* duration: 3000,
|
|
410
|
+
* });
|
|
411
|
+
*
|
|
412
|
+
* @see {@link IToastContext}
|
|
413
|
+
*/
|
|
414
|
+
const useToast = () => {
|
|
415
|
+
const toastContext = React__namespace.useContext(ToastContext);
|
|
416
|
+
if (!toastContext) {
|
|
417
|
+
throw new Error("useToast must be used within the ToastProvider");
|
|
418
|
+
}
|
|
419
|
+
return toastContext;
|
|
420
420
|
};
|
|
421
421
|
|
|
422
|
-
const TokenContext = React__namespace.createContext(null);
|
|
423
|
-
/**
|
|
424
|
-
* This is a hook to use the TokenContext.
|
|
425
|
-
*
|
|
426
|
-
* @requires TokenProvider
|
|
427
|
-
* @example
|
|
428
|
-
* import { useToken } from "@trackunit/react-core-hooks";
|
|
429
|
-
* const { token } = useToken();
|
|
430
|
-
*
|
|
431
|
-
* @see {@link ITokenContext}
|
|
432
|
-
*/
|
|
433
|
-
const useToken = () => {
|
|
434
|
-
const context = React__namespace.useContext(TokenContext);
|
|
435
|
-
if (!context) {
|
|
436
|
-
throw new Error("useToken must be used within the TokenContext");
|
|
437
|
-
}
|
|
438
|
-
return context;
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* This is a provider for the TokenContext.
|
|
442
|
-
*/
|
|
443
|
-
const TokenProvider = (props) => {
|
|
444
|
-
return jsxRuntime.jsx(TokenContext.Provider, Object.assign({}, props));
|
|
422
|
+
const TokenContext = React__namespace.createContext(null);
|
|
423
|
+
/**
|
|
424
|
+
* This is a hook to use the TokenContext.
|
|
425
|
+
*
|
|
426
|
+
* @requires TokenProvider
|
|
427
|
+
* @example
|
|
428
|
+
* import { useToken } from "@trackunit/react-core-hooks";
|
|
429
|
+
* const { token } = useToken();
|
|
430
|
+
*
|
|
431
|
+
* @see {@link ITokenContext}
|
|
432
|
+
*/
|
|
433
|
+
const useToken = () => {
|
|
434
|
+
const context = React__namespace.useContext(TokenContext);
|
|
435
|
+
if (!context) {
|
|
436
|
+
throw new Error("useToken must be used within the TokenContext");
|
|
437
|
+
}
|
|
438
|
+
return context;
|
|
439
|
+
};
|
|
440
|
+
/**
|
|
441
|
+
* This is a provider for the TokenContext.
|
|
442
|
+
*/
|
|
443
|
+
const TokenProvider = (props) => {
|
|
444
|
+
return jsxRuntime.jsx(TokenContext.Provider, Object.assign({}, props));
|
|
445
445
|
};
|
|
446
446
|
|
|
447
|
-
const CurrentUserContext = React__namespace.createContext(null);
|
|
448
|
-
/**
|
|
449
|
-
* This is a provider for the CurrentUserContext.
|
|
450
|
-
*/
|
|
451
|
-
const CurrentUserProvider = (props) => {
|
|
452
|
-
return jsxRuntime.jsx(CurrentUserContext.Provider, Object.assign({}, props));
|
|
453
|
-
};
|
|
454
|
-
/**
|
|
455
|
-
* This is a hook providing the CurrentUserContext.
|
|
456
|
-
*
|
|
457
|
-
* @requires CurrentUserProvider
|
|
458
|
-
* @example
|
|
459
|
-
* import { useCurrentUser } from "@trackunit/react-core-hooks";
|
|
460
|
-
* const { assumedUser, accountId } = useCurrentUser();
|
|
461
|
-
*
|
|
462
|
-
* //use it for something
|
|
463
|
-
* const { data, loading } = useGetAccountByIdQuery({
|
|
464
|
-
* variables: { accountId: assumedUser?.accountId || accountId || "" },
|
|
465
|
-
* });
|
|
466
|
-
*
|
|
467
|
-
* @see {@link ICurrentUserContext}
|
|
468
|
-
*/
|
|
469
|
-
const useCurrentUser = () => {
|
|
470
|
-
const context = React__namespace.useContext(CurrentUserContext);
|
|
471
|
-
if (!context) {
|
|
472
|
-
throw new Error("useCurrentUser must be used within the CurrentUserProvider");
|
|
473
|
-
}
|
|
474
|
-
return context;
|
|
447
|
+
const CurrentUserContext = React__namespace.createContext(null);
|
|
448
|
+
/**
|
|
449
|
+
* This is a provider for the CurrentUserContext.
|
|
450
|
+
*/
|
|
451
|
+
const CurrentUserProvider = (props) => {
|
|
452
|
+
return jsxRuntime.jsx(CurrentUserContext.Provider, Object.assign({}, props));
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* This is a hook providing the CurrentUserContext.
|
|
456
|
+
*
|
|
457
|
+
* @requires CurrentUserProvider
|
|
458
|
+
* @example
|
|
459
|
+
* import { useCurrentUser } from "@trackunit/react-core-hooks";
|
|
460
|
+
* const { assumedUser, accountId } = useCurrentUser();
|
|
461
|
+
*
|
|
462
|
+
* //use it for something
|
|
463
|
+
* const { data, loading } = useGetAccountByIdQuery({
|
|
464
|
+
* variables: { accountId: assumedUser?.accountId || accountId || "" },
|
|
465
|
+
* });
|
|
466
|
+
*
|
|
467
|
+
* @see {@link ICurrentUserContext}
|
|
468
|
+
*/
|
|
469
|
+
const useCurrentUser = () => {
|
|
470
|
+
const context = React__namespace.useContext(CurrentUserContext);
|
|
471
|
+
if (!context) {
|
|
472
|
+
throw new Error("useCurrentUser must be used within the CurrentUserProvider");
|
|
473
|
+
}
|
|
474
|
+
return context;
|
|
475
475
|
};
|
|
476
476
|
|
|
477
477
|
exports.AnalyticsContext = AnalyticsContext;
|