@trackunit/react-core-hooks 0.2.57 → 0.2.58
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 +157 -2
- package/index.js +157 -2
- package/package.json +1 -1
- package/src/analytics/AnalyticsProvider.d.ts +15 -0
- package/src/assetSorting/AssetSortingProvider.d.ts +26 -0
- package/src/environment/EnvironmentContextProvider.d.ts +8 -0
- package/src/global-selection/GlobalSelectionProvider.d.ts +11 -0
- package/src/irisOemApp/IrisOemAppContextProvider.d.ts +9 -0
- package/src/runtimes/navigation/useNavigationRuntime.d.ts +8 -0
- package/src/runtimes/useAssetRuntime.d.ts +12 -0
- package/src/runtimes/useCustomFieldRuntimeForEntity.d.ts +10 -0
- package/src/runtimes/useSiteRuntime.d.ts +13 -0
- package/src/subscription/UserSubscriptionProvider.d.ts +9 -0
- package/src/toast/ToastProvider.d.ts +15 -0
- package/src/token/TokenProvider.d.ts +7 -0
- package/src/user/CurrentUserProvider.d.ts +13 -1
package/index.cjs
CHANGED
|
@@ -34,6 +34,21 @@ const AnalyticsContext = React.createContext(null);
|
|
|
34
34
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
35
35
|
/**
|
|
36
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}
|
|
37
52
|
*/
|
|
38
53
|
const useAnalytics = (type) => {
|
|
39
54
|
const context = React.useContext(AnalyticsContext);
|
|
@@ -50,6 +65,32 @@ const AssetSortingContext = React.createContext(null);
|
|
|
50
65
|
const AssetSortingProvider = AssetSortingContext.Provider;
|
|
51
66
|
/**
|
|
52
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}
|
|
53
94
|
*/
|
|
54
95
|
const useAssetSorting = () => {
|
|
55
96
|
const context = React.useContext(AssetSortingContext);
|
|
@@ -68,6 +109,14 @@ const EnvironmentContextProvider = (props) => {
|
|
|
68
109
|
};
|
|
69
110
|
/**
|
|
70
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)
|
|
71
120
|
*/
|
|
72
121
|
const useEnvironment = () => {
|
|
73
122
|
const context = React.useContext(EnvironmentContext);
|
|
@@ -80,6 +129,17 @@ const useEnvironment = () => {
|
|
|
80
129
|
const GlobalSelectionContext = React__namespace.createContext(null);
|
|
81
130
|
/**
|
|
82
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}
|
|
83
143
|
*/
|
|
84
144
|
const useGlobalSelection = () => {
|
|
85
145
|
const context = React__namespace.useContext(GlobalSelectionContext);
|
|
@@ -96,11 +156,20 @@ const GlobalSelectionProvider = (props) => jsxRuntime.jsx(GlobalSelectionContext
|
|
|
96
156
|
const OemBrandingContext = React.createContext(null);
|
|
97
157
|
/**
|
|
98
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}
|
|
99
168
|
*/
|
|
100
169
|
const useOemBrandingContext = () => {
|
|
101
170
|
const context = React.useContext(OemBrandingContext);
|
|
102
171
|
if (!context) {
|
|
103
|
-
throw new Error("useOemBranding must be used within an
|
|
172
|
+
throw new Error("useOemBranding must be used within an OemBrandingContextProvider");
|
|
104
173
|
}
|
|
105
174
|
return context;
|
|
106
175
|
};
|
|
@@ -130,7 +199,15 @@ const useURLSynchronization = () => {
|
|
|
130
199
|
/**
|
|
131
200
|
* A hook to expose navigation runtime for React components
|
|
132
201
|
*
|
|
202
|
+
* @requires NavigationRuntime
|
|
133
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>
|
|
134
211
|
*/
|
|
135
212
|
const useNavigationRuntime = () => {
|
|
136
213
|
return irisAppRuntimeCore.NavigationRuntime;
|
|
@@ -164,7 +241,19 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
164
241
|
/**
|
|
165
242
|
* A hook to expose asset runtime for React components
|
|
166
243
|
*
|
|
244
|
+
* @requires AssetRuntime
|
|
167
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
|
+
*
|
|
168
257
|
*/
|
|
169
258
|
const useAssetRuntime = () => {
|
|
170
259
|
const [assetInfo, setAssetInfo] = React.useState();
|
|
@@ -192,6 +281,16 @@ const useCustomFieldRuntime = () => {
|
|
|
192
281
|
*
|
|
193
282
|
* @param entity The entity to fetch and set custom fields for.
|
|
194
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"});
|
|
195
294
|
*/
|
|
196
295
|
const useCustomFieldRuntimeForEntity = (entity) => {
|
|
197
296
|
const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
|
|
@@ -235,7 +334,20 @@ const useRestRuntime = () => {
|
|
|
235
334
|
/**
|
|
236
335
|
* A hook to expose site runtime for React components
|
|
237
336
|
*
|
|
337
|
+
* @requires SiteRuntime
|
|
238
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
|
+
*
|
|
239
351
|
*/
|
|
240
352
|
const useSiteRuntime = () => {
|
|
241
353
|
const [siteInfo, setSiteInfo] = React.useState();
|
|
@@ -258,6 +370,15 @@ const UserSubscriptionProvider = (props) => {
|
|
|
258
370
|
};
|
|
259
371
|
/**
|
|
260
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}
|
|
261
382
|
*/
|
|
262
383
|
const useUserSubscription = () => {
|
|
263
384
|
const context = React__namespace.useContext(UserSubscriptionContext);
|
|
@@ -274,6 +395,21 @@ const ToastContext = React__namespace.createContext(null);
|
|
|
274
395
|
const ToastProvider = (props) => jsxRuntime.jsx(ToastContext.Provider, Object.assign({}, props));
|
|
275
396
|
/**
|
|
276
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}
|
|
277
413
|
*/
|
|
278
414
|
const useToast = () => {
|
|
279
415
|
const toastContext = React__namespace.useContext(ToastContext);
|
|
@@ -286,6 +422,13 @@ const useToast = () => {
|
|
|
286
422
|
const TokenContext = React__namespace.createContext(null);
|
|
287
423
|
/**
|
|
288
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}
|
|
289
432
|
*/
|
|
290
433
|
const useToken = () => {
|
|
291
434
|
const context = React__namespace.useContext(TokenContext);
|
|
@@ -309,7 +452,19 @@ const CurrentUserProvider = (props) => {
|
|
|
309
452
|
return jsxRuntime.jsx(CurrentUserContext.Provider, Object.assign({}, props));
|
|
310
453
|
};
|
|
311
454
|
/**
|
|
312
|
-
* This is a hook
|
|
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}
|
|
313
468
|
*/
|
|
314
469
|
const useCurrentUser = () => {
|
|
315
470
|
const context = React__namespace.useContext(CurrentUserContext);
|
package/index.js
CHANGED
|
@@ -8,6 +8,21 @@ const AnalyticsContext = createContext(null);
|
|
|
8
8
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
9
9
|
/**
|
|
10
10
|
* Hook to get the analytics context.
|
|
11
|
+
*
|
|
12
|
+
* @requires AnalyticsProvider
|
|
13
|
+
* @example
|
|
14
|
+
* import { useAnalytics, useEnvironment } from "@trackunit/react-core-hooks";
|
|
15
|
+
* const { logPageView, logEvent } = useAnalytics(AllEvents);
|
|
16
|
+
*
|
|
17
|
+
* // log page view event
|
|
18
|
+
* useEffect(() => {
|
|
19
|
+
* logPageView({ pageName: "login" });
|
|
20
|
+
* }, [logPageView]);
|
|
21
|
+
*
|
|
22
|
+
* // log event when appropriate
|
|
23
|
+
* logEvent("Login", { loginPage: "New Manager" });
|
|
24
|
+
*
|
|
25
|
+
* @see {@link IAnalyticsContext}
|
|
11
26
|
*/
|
|
12
27
|
const useAnalytics = (type) => {
|
|
13
28
|
const context = useContext(AnalyticsContext);
|
|
@@ -24,6 +39,32 @@ const AssetSortingContext = createContext(null);
|
|
|
24
39
|
const AssetSortingProvider = AssetSortingContext.Provider;
|
|
25
40
|
/**
|
|
26
41
|
* This is a hook to use the AssetSortingContext.
|
|
42
|
+
*
|
|
43
|
+
* @requires AssetSortingProvider
|
|
44
|
+
* @example
|
|
45
|
+
* import { useAssetSorting } from "@trackunit/react-core-hooks";
|
|
46
|
+
* const { sortingState, setSortBy } = useAssetSorting();
|
|
47
|
+
*
|
|
48
|
+
* const initialSort = useMemo(
|
|
49
|
+
* () => ({
|
|
50
|
+
* property: {
|
|
51
|
+
* label: sortingState.sortBy,
|
|
52
|
+
* value: sortingState.sortBy,
|
|
53
|
+
* },
|
|
54
|
+
* order: sortingState.order,
|
|
55
|
+
* }),
|
|
56
|
+
* [sortingState]
|
|
57
|
+
* );
|
|
58
|
+
*
|
|
59
|
+
* return (
|
|
60
|
+
* <Table
|
|
61
|
+
* ...
|
|
62
|
+
* headerOnSort={setSortBy}
|
|
63
|
+
* headerInitialSort={initialSort}
|
|
64
|
+
* />
|
|
65
|
+
* );
|
|
66
|
+
*
|
|
67
|
+
* @see {@link IAssetSortingContext}
|
|
27
68
|
*/
|
|
28
69
|
const useAssetSorting = () => {
|
|
29
70
|
const context = useContext(AssetSortingContext);
|
|
@@ -42,6 +83,14 @@ const EnvironmentContextProvider = (props) => {
|
|
|
42
83
|
};
|
|
43
84
|
/**
|
|
44
85
|
* This is a hook to use the EnvironmentContext.
|
|
86
|
+
*
|
|
87
|
+
* @requires EnvironmentContext
|
|
88
|
+
* @example
|
|
89
|
+
* import { useEnvironment } from "@trackunit/react-core-hooks";
|
|
90
|
+
* const { googleMapsApiKey } = useEnvironment();
|
|
91
|
+
* // use api key for something...
|
|
92
|
+
*
|
|
93
|
+
* @see (@link IEnvironmentContext)
|
|
45
94
|
*/
|
|
46
95
|
const useEnvironment = () => {
|
|
47
96
|
const context = useContext(EnvironmentContext);
|
|
@@ -54,6 +103,17 @@ const useEnvironment = () => {
|
|
|
54
103
|
const GlobalSelectionContext = React.createContext(null);
|
|
55
104
|
/**
|
|
56
105
|
* This is a hook to use the GlobalSelectionContext.
|
|
106
|
+
*
|
|
107
|
+
* @requires GlobalSelectionProvider
|
|
108
|
+
* @example
|
|
109
|
+
* import { useGlobalSelection } from "@trackunit/react-core-hooks";
|
|
110
|
+
*
|
|
111
|
+
* export const useActiveGlobalGroupIdFilter = () => {
|
|
112
|
+
* const { selection } = useGlobalSelection();
|
|
113
|
+
* return (selection?.type === "group") ? selection.groupId : undefined;
|
|
114
|
+
* };
|
|
115
|
+
*
|
|
116
|
+
* @see {@link IGlobalSelectionContext}
|
|
57
117
|
*/
|
|
58
118
|
const useGlobalSelection = () => {
|
|
59
119
|
const context = React.useContext(GlobalSelectionContext);
|
|
@@ -70,11 +130,20 @@ const GlobalSelectionProvider = (props) => jsx(GlobalSelectionContext.Provider,
|
|
|
70
130
|
const OemBrandingContext = createContext(null);
|
|
71
131
|
/**
|
|
72
132
|
* This is a hook to use the IOemBrandingContext.
|
|
133
|
+
*
|
|
134
|
+
* @requires OemBrandingContextProvider
|
|
135
|
+
* @example
|
|
136
|
+
* import { useOemBrandingContext } from "@trackunit/react-core-hooks";
|
|
137
|
+
* const { getOemBranding, getImageByBrand } = useOemBrandingContext();
|
|
138
|
+
* // use oem branding
|
|
139
|
+
* const branding = getOemBranding("some brand")
|
|
140
|
+
*
|
|
141
|
+
* @see {@link IOemBrandingContext}
|
|
73
142
|
*/
|
|
74
143
|
const useOemBrandingContext = () => {
|
|
75
144
|
const context = useContext(OemBrandingContext);
|
|
76
145
|
if (!context) {
|
|
77
|
-
throw new Error("useOemBranding must be used within an
|
|
146
|
+
throw new Error("useOemBranding must be used within an OemBrandingContextProvider");
|
|
78
147
|
}
|
|
79
148
|
return context;
|
|
80
149
|
};
|
|
@@ -104,7 +173,15 @@ const useURLSynchronization = () => {
|
|
|
104
173
|
/**
|
|
105
174
|
* A hook to expose navigation runtime for React components
|
|
106
175
|
*
|
|
176
|
+
* @requires NavigationRuntime
|
|
107
177
|
* @returns {UseNavigationRuntime} navigationRuntime
|
|
178
|
+
* @example
|
|
179
|
+
* import { useNavigationRuntime } from "@trackunit/react-core-hooks";
|
|
180
|
+
* const { navigateTo } = useNavigationRuntime();
|
|
181
|
+
* // ...
|
|
182
|
+
* <Link onClick={() => gotoAssetHome(asset.id)} to="">
|
|
183
|
+
* {asset.name}
|
|
184
|
+
* </Link>
|
|
108
185
|
*/
|
|
109
186
|
const useNavigationRuntime = () => {
|
|
110
187
|
return NavigationRuntime;
|
|
@@ -138,7 +215,19 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
138
215
|
/**
|
|
139
216
|
* A hook to expose asset runtime for React components
|
|
140
217
|
*
|
|
218
|
+
* @requires AssetRuntime
|
|
141
219
|
* @returns {UseAssetRuntime} assetRuntime
|
|
220
|
+
* @example
|
|
221
|
+
* import { useAssetRuntime } from "@trackunit/react-core-hooks";
|
|
222
|
+
* const { assetInfo } = useAssetRuntime();
|
|
223
|
+
* useEffect(() => {
|
|
224
|
+
* (async () => {
|
|
225
|
+
* if (assetInfo) {
|
|
226
|
+
* getAssetLocation({ variables: { id: assetInfo.assetId } });
|
|
227
|
+
* }
|
|
228
|
+
* })();
|
|
229
|
+
* }, [assetInfo, getAssetLocation]);
|
|
230
|
+
*
|
|
142
231
|
*/
|
|
143
232
|
const useAssetRuntime = () => {
|
|
144
233
|
const [assetInfo, setAssetInfo] = useState();
|
|
@@ -166,6 +255,16 @@ const useCustomFieldRuntime = () => {
|
|
|
166
255
|
*
|
|
167
256
|
* @param entity The entity to fetch and set custom fields for.
|
|
168
257
|
* @returns The custom fields for the entity, and functions to set custom fields for the entity.
|
|
258
|
+
* @example
|
|
259
|
+
* import { useAssetRuntime, useCustomFieldRuntimeForEntity } from '@trackunit/react-core-hooks';
|
|
260
|
+
* const { assetInfo } = useAssetRuntime();
|
|
261
|
+
* const { customFields, setCustomFieldsForEntity } = useCustomFieldRuntimeForEntity( {
|
|
262
|
+
* id: assetInfo?.assetId || '',
|
|
263
|
+
* type: 'ASSET'
|
|
264
|
+
* });
|
|
265
|
+
*
|
|
266
|
+
* // set custom field data
|
|
267
|
+
* setCustomFieldsForEntity({"key": "value"});
|
|
169
268
|
*/
|
|
170
269
|
const useCustomFieldRuntimeForEntity = (entity) => {
|
|
171
270
|
const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
|
|
@@ -209,7 +308,20 @@ const useRestRuntime = () => {
|
|
|
209
308
|
/**
|
|
210
309
|
* A hook to expose site runtime for React components
|
|
211
310
|
*
|
|
311
|
+
* @requires SiteRuntime
|
|
212
312
|
* @returns {UseSiteRuntime} siteRuntime
|
|
313
|
+
* @example
|
|
314
|
+
* import { useSiteRuntime } from "@trackunit/react-core-hooks";
|
|
315
|
+
* const { siteInfo } = useSiteRuntime();
|
|
316
|
+
* // use siteInfo to get assets for instance.
|
|
317
|
+
* useEffect(() => {
|
|
318
|
+
* (async () => {
|
|
319
|
+
* if (siteInfo?.siteId) {
|
|
320
|
+
* getSiteAssets({ variables: { siteId: siteInfo?.siteId, siteIdStr: siteInfo?.siteId } });
|
|
321
|
+
* }
|
|
322
|
+
* })();
|
|
323
|
+
* }, [getSiteAssets, siteInfo]);
|
|
324
|
+
*
|
|
213
325
|
*/
|
|
214
326
|
const useSiteRuntime = () => {
|
|
215
327
|
const [siteInfo, setSiteInfo] = useState();
|
|
@@ -232,6 +344,15 @@ const UserSubscriptionProvider = (props) => {
|
|
|
232
344
|
};
|
|
233
345
|
/**
|
|
234
346
|
* This is a hook to use the UserSubscriptionContext.
|
|
347
|
+
*
|
|
348
|
+
* @requires UserSubscriptionProvider
|
|
349
|
+
* @example
|
|
350
|
+
* import { useUserSubscription } from "@trackunit/react-core-hooks";
|
|
351
|
+
* const { numberOfDaysWithAccessToHistoricalData, packageType } = useUserSubscription();
|
|
352
|
+
* // use it for something
|
|
353
|
+
* const data = fetchData(numberOfDaysWithAccessToHistoricalData)
|
|
354
|
+
*
|
|
355
|
+
* @see {@link IUserSubscriptionContext}
|
|
235
356
|
*/
|
|
236
357
|
const useUserSubscription = () => {
|
|
237
358
|
const context = React.useContext(UserSubscriptionContext);
|
|
@@ -248,6 +369,21 @@ const ToastContext = React.createContext(null);
|
|
|
248
369
|
const ToastProvider = (props) => jsx(ToastContext.Provider, Object.assign({}, props));
|
|
249
370
|
/**
|
|
250
371
|
* This is a hook to use the ToastContext.
|
|
372
|
+
*
|
|
373
|
+
* @requires ToastProvider
|
|
374
|
+
* @example
|
|
375
|
+
* import { useToast } from "@trackunit/react-core-hooks";
|
|
376
|
+
* const { addToast } = useToast();
|
|
377
|
+
* // use the toast
|
|
378
|
+
* error &&
|
|
379
|
+
* addToast({
|
|
380
|
+
* intent: "warning",
|
|
381
|
+
* title: t("assetHome.specification.failedToSave"),
|
|
382
|
+
* description: error?.message,
|
|
383
|
+
* duration: 3000,
|
|
384
|
+
* });
|
|
385
|
+
*
|
|
386
|
+
* @see {@link IToastContext}
|
|
251
387
|
*/
|
|
252
388
|
const useToast = () => {
|
|
253
389
|
const toastContext = React.useContext(ToastContext);
|
|
@@ -260,6 +396,13 @@ const useToast = () => {
|
|
|
260
396
|
const TokenContext = React.createContext(null);
|
|
261
397
|
/**
|
|
262
398
|
* This is a hook to use the TokenContext.
|
|
399
|
+
*
|
|
400
|
+
* @requires TokenProvider
|
|
401
|
+
* @example
|
|
402
|
+
* import { useToken } from "@trackunit/react-core-hooks";
|
|
403
|
+
* const { token } = useToken();
|
|
404
|
+
*
|
|
405
|
+
* @see {@link ITokenContext}
|
|
263
406
|
*/
|
|
264
407
|
const useToken = () => {
|
|
265
408
|
const context = React.useContext(TokenContext);
|
|
@@ -283,7 +426,19 @@ const CurrentUserProvider = (props) => {
|
|
|
283
426
|
return jsx(CurrentUserContext.Provider, Object.assign({}, props));
|
|
284
427
|
};
|
|
285
428
|
/**
|
|
286
|
-
* This is a hook
|
|
429
|
+
* This is a hook providing the CurrentUserContext.
|
|
430
|
+
*
|
|
431
|
+
* @requires CurrentUserProvider
|
|
432
|
+
* @example
|
|
433
|
+
* import { useCurrentUser } from "@trackunit/react-core-hooks";
|
|
434
|
+
* const { assumedUser, accountId } = useCurrentUser();
|
|
435
|
+
*
|
|
436
|
+
* //use it for something
|
|
437
|
+
* const { data, loading } = useGetAccountByIdQuery({
|
|
438
|
+
* variables: { accountId: assumedUser?.accountId || accountId || "" },
|
|
439
|
+
* });
|
|
440
|
+
*
|
|
441
|
+
* @see {@link ICurrentUserContext}
|
|
287
442
|
*/
|
|
288
443
|
const useCurrentUser = () => {
|
|
289
444
|
const context = React.useContext(CurrentUserContext);
|
package/package.json
CHANGED
|
@@ -4,5 +4,20 @@ export declare const AnalyticsContext: import("react").Context<IAnalyticsContext
|
|
|
4
4
|
export declare const AnalyticsContextProvider: import("react").Provider<IAnalyticsContext<{}> | null>;
|
|
5
5
|
/**
|
|
6
6
|
* Hook to get the analytics context.
|
|
7
|
+
*
|
|
8
|
+
* @requires AnalyticsProvider
|
|
9
|
+
* @example
|
|
10
|
+
* import { useAnalytics, useEnvironment } from "@trackunit/react-core-hooks";
|
|
11
|
+
* const { logPageView, logEvent } = useAnalytics(AllEvents);
|
|
12
|
+
*
|
|
13
|
+
* // log page view event
|
|
14
|
+
* useEffect(() => {
|
|
15
|
+
* logPageView({ pageName: "login" });
|
|
16
|
+
* }, [logPageView]);
|
|
17
|
+
*
|
|
18
|
+
* // log event when appropriate
|
|
19
|
+
* logEvent("Login", { loginPage: "New Manager" });
|
|
20
|
+
*
|
|
21
|
+
* @see {@link IAnalyticsContext}
|
|
7
22
|
*/
|
|
8
23
|
export declare const useAnalytics: <T extends Record<string, Event<BaseEvent | UnspecifiedEvent>>>(type: T) => IAnalyticsContext<T>;
|
|
@@ -6,5 +6,31 @@ import { IAssetSortingContext } from "@trackunit/react-core-contexts-api";
|
|
|
6
6
|
export declare const AssetSortingProvider: import("react").Provider<IAssetSortingContext | null>;
|
|
7
7
|
/**
|
|
8
8
|
* This is a hook to use the AssetSortingContext.
|
|
9
|
+
*
|
|
10
|
+
* @requires AssetSortingProvider
|
|
11
|
+
* @example
|
|
12
|
+
* import { useAssetSorting } from "@trackunit/react-core-hooks";
|
|
13
|
+
* const { sortingState, setSortBy } = useAssetSorting();
|
|
14
|
+
*
|
|
15
|
+
* const initialSort = useMemo(
|
|
16
|
+
* () => ({
|
|
17
|
+
* property: {
|
|
18
|
+
* label: sortingState.sortBy,
|
|
19
|
+
* value: sortingState.sortBy,
|
|
20
|
+
* },
|
|
21
|
+
* order: sortingState.order,
|
|
22
|
+
* }),
|
|
23
|
+
* [sortingState]
|
|
24
|
+
* );
|
|
25
|
+
*
|
|
26
|
+
* return (
|
|
27
|
+
* <Table
|
|
28
|
+
* ...
|
|
29
|
+
* headerOnSort={setSortBy}
|
|
30
|
+
* headerInitialSort={initialSort}
|
|
31
|
+
* />
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* @see {@link IAssetSortingContext}
|
|
9
35
|
*/
|
|
10
36
|
export declare const useAssetSorting: () => IAssetSortingContext;
|
|
@@ -10,6 +10,14 @@ interface IProps {
|
|
|
10
10
|
export declare const EnvironmentContextProvider: (props: IProps) => JSX.Element;
|
|
11
11
|
/**
|
|
12
12
|
* This is a hook to use the EnvironmentContext.
|
|
13
|
+
*
|
|
14
|
+
* @requires EnvironmentContext
|
|
15
|
+
* @example
|
|
16
|
+
* import { useEnvironment } from "@trackunit/react-core-hooks";
|
|
17
|
+
* const { googleMapsApiKey } = useEnvironment();
|
|
18
|
+
* // use api key for something...
|
|
19
|
+
*
|
|
20
|
+
* @see (@link IEnvironmentContext)
|
|
13
21
|
*/
|
|
14
22
|
export declare const useEnvironment: () => IEnvironmentContext;
|
|
15
23
|
export {};
|
|
@@ -2,6 +2,17 @@ import { IGlobalSelectionContext } from "@trackunit/react-core-contexts-api";
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
/**
|
|
4
4
|
* This is a hook to use the GlobalSelectionContext.
|
|
5
|
+
*
|
|
6
|
+
* @requires GlobalSelectionProvider
|
|
7
|
+
* @example
|
|
8
|
+
* import { useGlobalSelection } from "@trackunit/react-core-hooks";
|
|
9
|
+
*
|
|
10
|
+
* export const useActiveGlobalGroupIdFilter = () => {
|
|
11
|
+
* const { selection } = useGlobalSelection();
|
|
12
|
+
* return (selection?.type === "group") ? selection.groupId : undefined;
|
|
13
|
+
* };
|
|
14
|
+
*
|
|
15
|
+
* @see {@link IGlobalSelectionContext}
|
|
5
16
|
*/
|
|
6
17
|
export declare const useGlobalSelection: () => IGlobalSelectionContext;
|
|
7
18
|
interface IProps {
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
import { IOemBrandingContext } from "@trackunit/react-core-contexts-api";
|
|
3
3
|
/**
|
|
4
4
|
* This is a hook to use the IOemBrandingContext.
|
|
5
|
+
*
|
|
6
|
+
* @requires OemBrandingContextProvider
|
|
7
|
+
* @example
|
|
8
|
+
* import { useOemBrandingContext } from "@trackunit/react-core-hooks";
|
|
9
|
+
* const { getOemBranding, getImageByBrand } = useOemBrandingContext();
|
|
10
|
+
* // use oem branding
|
|
11
|
+
* const branding = getOemBranding("some brand")
|
|
12
|
+
*
|
|
13
|
+
* @see {@link IOemBrandingContext}
|
|
5
14
|
*/
|
|
6
15
|
export declare const useOemBrandingContext: () => IOemBrandingContext;
|
|
7
16
|
interface IProps {
|
|
@@ -4,6 +4,14 @@ export interface UseNavigationRuntime extends INavigationRuntime {
|
|
|
4
4
|
/**
|
|
5
5
|
* A hook to expose navigation runtime for React components
|
|
6
6
|
*
|
|
7
|
+
* @requires NavigationRuntime
|
|
7
8
|
* @returns {UseNavigationRuntime} navigationRuntime
|
|
9
|
+
* @example
|
|
10
|
+
* import { useNavigationRuntime } from "@trackunit/react-core-hooks";
|
|
11
|
+
* const { navigateTo } = useNavigationRuntime();
|
|
12
|
+
* // ...
|
|
13
|
+
* <Link onClick={() => gotoAssetHome(asset.id)} to="">
|
|
14
|
+
* {asset.name}
|
|
15
|
+
* </Link>
|
|
8
16
|
*/
|
|
9
17
|
export declare const useNavigationRuntime: () => UseNavigationRuntime;
|
|
@@ -5,6 +5,18 @@ export interface UseAssetRuntime {
|
|
|
5
5
|
/**
|
|
6
6
|
* A hook to expose asset runtime for React components
|
|
7
7
|
*
|
|
8
|
+
* @requires AssetRuntime
|
|
8
9
|
* @returns {UseAssetRuntime} assetRuntime
|
|
10
|
+
* @example
|
|
11
|
+
* import { useAssetRuntime } from "@trackunit/react-core-hooks";
|
|
12
|
+
* const { assetInfo } = useAssetRuntime();
|
|
13
|
+
* useEffect(() => {
|
|
14
|
+
* (async () => {
|
|
15
|
+
* if (assetInfo) {
|
|
16
|
+
* getAssetLocation({ variables: { id: assetInfo.assetId } });
|
|
17
|
+
* }
|
|
18
|
+
* })();
|
|
19
|
+
* }, [assetInfo, getAssetLocation]);
|
|
20
|
+
*
|
|
9
21
|
*/
|
|
10
22
|
export declare const useAssetRuntime: () => UseAssetRuntime;
|
|
@@ -5,6 +5,16 @@ import { EntityIdentity, ValueAndDefinitionKey } from "@trackunit/iris-app-runti
|
|
|
5
5
|
*
|
|
6
6
|
* @param entity The entity to fetch and set custom fields for.
|
|
7
7
|
* @returns The custom fields for the entity, and functions to set custom fields for the entity.
|
|
8
|
+
* @example
|
|
9
|
+
* import { useAssetRuntime, useCustomFieldRuntimeForEntity } from '@trackunit/react-core-hooks';
|
|
10
|
+
* const { assetInfo } = useAssetRuntime();
|
|
11
|
+
* const { customFields, setCustomFieldsForEntity } = useCustomFieldRuntimeForEntity( {
|
|
12
|
+
* id: assetInfo?.assetId || '',
|
|
13
|
+
* type: 'ASSET'
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // set custom field data
|
|
17
|
+
* setCustomFieldsForEntity({"key": "value"});
|
|
8
18
|
*/
|
|
9
19
|
export declare const useCustomFieldRuntimeForEntity: (entity: EntityIdentity) => {
|
|
10
20
|
customFields: ValueAndDefinition[] | undefined;
|
|
@@ -5,6 +5,19 @@ export interface UseSiteRuntime {
|
|
|
5
5
|
/**
|
|
6
6
|
* A hook to expose site runtime for React components
|
|
7
7
|
*
|
|
8
|
+
* @requires SiteRuntime
|
|
8
9
|
* @returns {UseSiteRuntime} siteRuntime
|
|
10
|
+
* @example
|
|
11
|
+
* import { useSiteRuntime } from "@trackunit/react-core-hooks";
|
|
12
|
+
* const { siteInfo } = useSiteRuntime();
|
|
13
|
+
* // use siteInfo to get assets for instance.
|
|
14
|
+
* useEffect(() => {
|
|
15
|
+
* (async () => {
|
|
16
|
+
* if (siteInfo?.siteId) {
|
|
17
|
+
* getSiteAssets({ variables: { siteId: siteInfo?.siteId, siteIdStr: siteInfo?.siteId } });
|
|
18
|
+
* }
|
|
19
|
+
* })();
|
|
20
|
+
* }, [getSiteAssets, siteInfo]);
|
|
21
|
+
*
|
|
9
22
|
*/
|
|
10
23
|
export declare const useSiteRuntime: () => UseSiteRuntime;
|
|
@@ -10,6 +10,15 @@ interface IProps {
|
|
|
10
10
|
export declare const UserSubscriptionProvider: (props: IProps) => JSX.Element;
|
|
11
11
|
/**
|
|
12
12
|
* This is a hook to use the UserSubscriptionContext.
|
|
13
|
+
*
|
|
14
|
+
* @requires UserSubscriptionProvider
|
|
15
|
+
* @example
|
|
16
|
+
* import { useUserSubscription } from "@trackunit/react-core-hooks";
|
|
17
|
+
* const { numberOfDaysWithAccessToHistoricalData, packageType } = useUserSubscription();
|
|
18
|
+
* // use it for something
|
|
19
|
+
* const data = fetchData(numberOfDaysWithAccessToHistoricalData)
|
|
20
|
+
*
|
|
21
|
+
* @see {@link IUserSubscriptionContext}
|
|
13
22
|
*/
|
|
14
23
|
export declare const useUserSubscription: () => IUserSubscriptionContext;
|
|
15
24
|
export {};
|
|
@@ -10,5 +10,20 @@ export interface ContextProviderProps {
|
|
|
10
10
|
export declare const ToastProvider: (props: ContextProviderProps) => JSX.Element;
|
|
11
11
|
/**
|
|
12
12
|
* This is a hook to use the ToastContext.
|
|
13
|
+
*
|
|
14
|
+
* @requires ToastProvider
|
|
15
|
+
* @example
|
|
16
|
+
* import { useToast } from "@trackunit/react-core-hooks";
|
|
17
|
+
* const { addToast } = useToast();
|
|
18
|
+
* // use the toast
|
|
19
|
+
* error &&
|
|
20
|
+
* addToast({
|
|
21
|
+
* intent: "warning",
|
|
22
|
+
* title: t("assetHome.specification.failedToSave"),
|
|
23
|
+
* description: error?.message,
|
|
24
|
+
* duration: 3000,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* @see {@link IToastContext}
|
|
13
28
|
*/
|
|
14
29
|
export declare const useToast: () => IToastContext;
|
|
@@ -2,6 +2,13 @@ import { ITokenContext } from "@trackunit/react-core-contexts-api";
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
/**
|
|
4
4
|
* This is a hook to use the TokenContext.
|
|
5
|
+
*
|
|
6
|
+
* @requires TokenProvider
|
|
7
|
+
* @example
|
|
8
|
+
* import { useToken } from "@trackunit/react-core-hooks";
|
|
9
|
+
* const { token } = useToken();
|
|
10
|
+
*
|
|
11
|
+
* @see {@link ITokenContext}
|
|
5
12
|
*/
|
|
6
13
|
export declare const useToken: () => ITokenContext;
|
|
7
14
|
interface IProps {
|
|
@@ -9,7 +9,19 @@ interface Props {
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const CurrentUserProvider: (props: Props) => JSX.Element;
|
|
11
11
|
/**
|
|
12
|
-
* This is a hook
|
|
12
|
+
* This is a hook providing the CurrentUserContext.
|
|
13
|
+
*
|
|
14
|
+
* @requires CurrentUserProvider
|
|
15
|
+
* @example
|
|
16
|
+
* import { useCurrentUser } from "@trackunit/react-core-hooks";
|
|
17
|
+
* const { assumedUser, accountId } = useCurrentUser();
|
|
18
|
+
*
|
|
19
|
+
* //use it for something
|
|
20
|
+
* const { data, loading } = useGetAccountByIdQuery({
|
|
21
|
+
* variables: { accountId: assumedUser?.accountId || accountId || "" },
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* @see {@link ICurrentUserContext}
|
|
13
25
|
*/
|
|
14
26
|
export declare const useCurrentUser: () => ICurrentUserContext;
|
|
15
27
|
export {};
|