@trackunit/react-core-hooks 0.2.169 → 0.2.171

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.js CHANGED
@@ -5,11 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
8
- var reactRouterDom = require('react-router-dom');
9
8
  var sharedUtils = require('@trackunit/shared-utils');
10
9
 
11
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
-
13
10
  function _interopNamespace(e) {
14
11
  if (e && e.__esModule) return e;
15
12
  var n = Object.create(null);
@@ -29,7 +26,6 @@ function _interopNamespace(e) {
29
26
  }
30
27
 
31
28
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
32
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
33
29
 
34
30
  const AnalyticsContext = React.createContext(null);
35
31
  const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
@@ -274,22 +270,6 @@ const useHasAccessTo = (options) => {
274
270
  return { hasAccess };
275
271
  };
276
272
 
277
- /**
278
- * A react hook for notifying host about location changes
279
- */
280
- const useURLSynchronization = () => {
281
- const location = reactRouterDom.useLocation();
282
- React__default["default"].useEffect(() => {
283
- const deepLink = {
284
- path: location.pathname,
285
- search: location.search,
286
- hash: location.hash,
287
- pathname: "",
288
- };
289
- irisAppRuntimeCore.NavigationRuntime.setDeepLink(deepLink);
290
- }, [location]);
291
- };
292
-
293
273
  /**
294
274
  * A hook to expose asset runtime for React components
295
275
  *
@@ -328,61 +308,6 @@ const useAssetRuntime = () => {
328
308
  return { assetInfo, loading, error };
329
309
  };
330
310
 
331
- /**
332
- * A hook to expose custom field runtime methods
333
- *
334
- * @returns {UseCustomFieldRuntime} CustomFieldRuntime
335
- */
336
- const useCustomFieldRuntime = () => {
337
- return irisAppRuntimeCore.CustomFieldRuntime;
338
- };
339
-
340
- /**
341
- * This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
342
- *
343
- * @param entity The entity to fetch and set custom fields for.
344
- * @returns The custom fields for the entity, and functions to set custom fields for the entity.
345
- * @example
346
- * import { useAssetRuntime, useCustomFieldRuntimeForEntity } from '@trackunit/react-core-hooks';
347
- * const { assetInfo } = useAssetRuntime();
348
- * const { customFields, setCustomFieldsForEntity } = useCustomFieldRuntimeForEntity( {
349
- * id: assetInfo?.assetId || '',
350
- * type: 'ASSET'
351
- * });
352
- *
353
- * // set custom field data
354
- * setCustomFieldsForEntity({"key": "value"});
355
- */
356
- const useCustomFieldRuntimeForEntity = (entity) => {
357
- const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
358
- const [customFields, setCustomFields] = React.useState();
359
- React.useEffect(() => {
360
- if (entity.id) {
361
- (() => __awaiter(void 0, void 0, void 0, function* () {
362
- setCustomFields(yield getCustomFieldsFor(entity));
363
- }))();
364
- }
365
- else {
366
- setCustomFields([]);
367
- }
368
- }, [entity, getCustomFieldsFor]);
369
- const setCustomFieldsForEntity = (values) => __awaiter(void 0, void 0, void 0, function* () {
370
- if (entity.id) {
371
- yield setCustomFieldsFor(entity, values);
372
- }
373
- });
374
- const setCustomFieldsFromFormDataForEntity = (formData) => __awaiter(void 0, void 0, void 0, function* () {
375
- if (entity.id) {
376
- yield setCustomFieldsFromFormData(entity, formData, customFields || []);
377
- }
378
- });
379
- return {
380
- customFields,
381
- setCustomFieldsFromFormDataForEntity,
382
- setCustomFieldsForEntity,
383
- };
384
- };
385
-
386
311
  /**
387
312
  * A hook to expose event runtime for React components
388
313
  *
@@ -422,6 +347,44 @@ const useEventRuntime = () => {
422
347
  return { eventInfo, loading, error };
423
348
  };
424
349
 
350
+ /**
351
+ * A hook to expose getIrisAppName for React components
352
+ *
353
+ * @requires ParamsRuntime
354
+ * @returns {UseIrisAppName} appName, loading, error
355
+ * @example
356
+ * import { useIrisAppName } from "@trackunit/react-core-hooks";
357
+ * const { appName } = useIrisAppName();
358
+ * useEffect(() => {
359
+ * (async () => {
360
+ * if (appName) {
361
+ * // do something with appName
362
+ * }
363
+ * })();
364
+ * }, [appName]);
365
+ */
366
+ const useIrisAppName = () => {
367
+ const [appName, setAppName] = React.useState();
368
+ const [loading, setLoading] = React.useState(true);
369
+ const [error, setError] = React.useState();
370
+ React.useEffect(() => {
371
+ const getAppName = () => __awaiter(void 0, void 0, void 0, function* () {
372
+ setLoading(true);
373
+ try {
374
+ const updatedAppName = yield irisAppRuntimeCore.ParamsRuntime.getAppName();
375
+ setLoading(false);
376
+ setAppName(updatedAppName);
377
+ }
378
+ catch (e) {
379
+ setLoading(false);
380
+ setError(new Error("Failed to get iris app name"));
381
+ }
382
+ });
383
+ getAppName();
384
+ }, []);
385
+ return { appName, loading, error };
386
+ };
387
+
425
388
  /**
426
389
  * A hook to expose site runtime for React components
427
390
  *
@@ -693,17 +656,15 @@ exports.useCurrentUser = useCurrentUser;
693
656
  exports.useCurrentUserLanguage = useCurrentUserLanguage;
694
657
  exports.useCurrentUserSystemOfMeasurement = useCurrentUserSystemOfMeasurement;
695
658
  exports.useCurrentUserTimeZonePreference = useCurrentUserTimeZonePreference;
696
- exports.useCustomFieldRuntime = useCustomFieldRuntime;
697
- exports.useCustomFieldRuntimeForEntity = useCustomFieldRuntimeForEntity;
698
659
  exports.useEnvironment = useEnvironment;
699
660
  exports.useEventRuntime = useEventRuntime;
700
661
  exports.useFilterBarContext = useFilterBarContext;
701
662
  exports.useHasAccessTo = useHasAccessTo;
663
+ exports.useIrisAppName = useIrisAppName;
702
664
  exports.useNavigateInHost = useNavigateInHost;
703
665
  exports.useOemBrandingContext = useOemBrandingContext;
704
666
  exports.useSiteRuntime = useSiteRuntime;
705
667
  exports.useTextSearch = useTextSearch;
706
668
  exports.useToast = useToast;
707
669
  exports.useToken = useToken;
708
- exports.useURLSynchronization = useURLSynchronization;
709
670
  exports.useUserSubscription = useUserSubscription;
package/index.esm.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as React from 'react';
2
- import React__default, { createContext, useContext, useState, useEffect, useMemo } from 'react';
2
+ import { createContext, useContext, useState, useEffect, useMemo } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
- import { NavigationRuntime, AssetRuntime, CustomFieldRuntime, EventRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
5
- import { useLocation } from 'react-router-dom';
4
+ import { AssetRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
6
5
  import { filterByMultiple } from '@trackunit/shared-utils';
7
6
 
8
7
  const AnalyticsContext = createContext(null);
@@ -248,22 +247,6 @@ const useHasAccessTo = (options) => {
248
247
  return { hasAccess };
249
248
  };
250
249
 
251
- /**
252
- * A react hook for notifying host about location changes
253
- */
254
- const useURLSynchronization = () => {
255
- const location = useLocation();
256
- React__default.useEffect(() => {
257
- const deepLink = {
258
- path: location.pathname,
259
- search: location.search,
260
- hash: location.hash,
261
- pathname: "",
262
- };
263
- NavigationRuntime.setDeepLink(deepLink);
264
- }, [location]);
265
- };
266
-
267
250
  /**
268
251
  * A hook to expose asset runtime for React components
269
252
  *
@@ -302,61 +285,6 @@ const useAssetRuntime = () => {
302
285
  return { assetInfo, loading, error };
303
286
  };
304
287
 
305
- /**
306
- * A hook to expose custom field runtime methods
307
- *
308
- * @returns {UseCustomFieldRuntime} CustomFieldRuntime
309
- */
310
- const useCustomFieldRuntime = () => {
311
- return CustomFieldRuntime;
312
- };
313
-
314
- /**
315
- * This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
316
- *
317
- * @param entity The entity to fetch and set custom fields for.
318
- * @returns The custom fields for the entity, and functions to set custom fields for the entity.
319
- * @example
320
- * import { useAssetRuntime, useCustomFieldRuntimeForEntity } from '@trackunit/react-core-hooks';
321
- * const { assetInfo } = useAssetRuntime();
322
- * const { customFields, setCustomFieldsForEntity } = useCustomFieldRuntimeForEntity( {
323
- * id: assetInfo?.assetId || '',
324
- * type: 'ASSET'
325
- * });
326
- *
327
- * // set custom field data
328
- * setCustomFieldsForEntity({"key": "value"});
329
- */
330
- const useCustomFieldRuntimeForEntity = (entity) => {
331
- const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
332
- const [customFields, setCustomFields] = useState();
333
- useEffect(() => {
334
- if (entity.id) {
335
- (() => __awaiter(void 0, void 0, void 0, function* () {
336
- setCustomFields(yield getCustomFieldsFor(entity));
337
- }))();
338
- }
339
- else {
340
- setCustomFields([]);
341
- }
342
- }, [entity, getCustomFieldsFor]);
343
- const setCustomFieldsForEntity = (values) => __awaiter(void 0, void 0, void 0, function* () {
344
- if (entity.id) {
345
- yield setCustomFieldsFor(entity, values);
346
- }
347
- });
348
- const setCustomFieldsFromFormDataForEntity = (formData) => __awaiter(void 0, void 0, void 0, function* () {
349
- if (entity.id) {
350
- yield setCustomFieldsFromFormData(entity, formData, customFields || []);
351
- }
352
- });
353
- return {
354
- customFields,
355
- setCustomFieldsFromFormDataForEntity,
356
- setCustomFieldsForEntity,
357
- };
358
- };
359
-
360
288
  /**
361
289
  * A hook to expose event runtime for React components
362
290
  *
@@ -396,6 +324,44 @@ const useEventRuntime = () => {
396
324
  return { eventInfo, loading, error };
397
325
  };
398
326
 
327
+ /**
328
+ * A hook to expose getIrisAppName for React components
329
+ *
330
+ * @requires ParamsRuntime
331
+ * @returns {UseIrisAppName} appName, loading, error
332
+ * @example
333
+ * import { useIrisAppName } from "@trackunit/react-core-hooks";
334
+ * const { appName } = useIrisAppName();
335
+ * useEffect(() => {
336
+ * (async () => {
337
+ * if (appName) {
338
+ * // do something with appName
339
+ * }
340
+ * })();
341
+ * }, [appName]);
342
+ */
343
+ const useIrisAppName = () => {
344
+ const [appName, setAppName] = useState();
345
+ const [loading, setLoading] = useState(true);
346
+ const [error, setError] = useState();
347
+ useEffect(() => {
348
+ const getAppName = () => __awaiter(void 0, void 0, void 0, function* () {
349
+ setLoading(true);
350
+ try {
351
+ const updatedAppName = yield ParamsRuntime.getAppName();
352
+ setLoading(false);
353
+ setAppName(updatedAppName);
354
+ }
355
+ catch (e) {
356
+ setLoading(false);
357
+ setError(new Error("Failed to get iris app name"));
358
+ }
359
+ });
360
+ getAppName();
361
+ }, []);
362
+ return { appName, loading, error };
363
+ };
364
+
399
365
  /**
400
366
  * A hook to expose site runtime for React components
401
367
  *
@@ -646,4 +612,4 @@ const useCurrentUser = () => {
646
612
  return context;
647
613
  };
648
614
 
649
- export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useCustomFieldRuntime, useCustomFieldRuntimeForEntity, useEnvironment, useEventRuntime, useFilterBarContext, useHasAccessTo, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useURLSynchronization, useUserSubscription };
615
+ export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, CurrentUserPreferenceProvider, CurrentUserProvider, EnvironmentContextProvider, FilterBarProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useConfirmationDialog, useCurrentUser, useCurrentUserLanguage, useCurrentUserSystemOfMeasurement, useCurrentUserTimeZonePreference, useEnvironment, useEventRuntime, useFilterBarContext, useHasAccessTo, useIrisAppName, useNavigateInHost, useOemBrandingContext, useSiteRuntime, useTextSearch, useToast, useToken, useUserSubscription };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-hooks",
3
- "version": "0.2.169",
3
+ "version": "0.2.171",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -10,8 +10,6 @@
10
10
  "@trackunit/react-core-contexts-api": "*",
11
11
  "react": "^18.2.0",
12
12
  "@trackunit/iris-app-runtime-core": "*",
13
- "react-router-dom": "6.18.0",
14
- "@trackunit/iris-app-runtime-core-api": "*",
15
13
  "jest-fetch-mock": "^3.0.3",
16
14
  "@trackunit/shared-utils": "*"
17
15
  },
package/src/index.d.ts CHANGED
@@ -5,11 +5,9 @@ export * from "./environment/EnvironmentContextProvider";
5
5
  export * from "./filter-bar/FilterBarProvider";
6
6
  export * from "./irisOemApp/IrisOemAppContextProvider";
7
7
  export * from "./navigation/NavigationContextProvider";
8
- export * from "./navigation/useURLSynchronization";
9
8
  export * from "./runtimes/useAssetRuntime";
10
- export * from "./runtimes/useCustomFieldRuntime";
11
- export * from "./runtimes/useCustomFieldRuntimeForEntity";
12
9
  export * from "./runtimes/useEventRuntime";
10
+ export * from "./runtimes/useParamsRuntime";
13
11
  export * from "./runtimes/useSiteRuntime";
14
12
  export * from "./subscription/UserSubscriptionProvider";
15
13
  export * from "./toast/ToastProvider";
@@ -0,0 +1,22 @@
1
+ export interface UseIrisAppName {
2
+ appName: string | undefined;
3
+ loading: boolean;
4
+ error: Error | undefined;
5
+ }
6
+ /**
7
+ * A hook to expose getIrisAppName for React components
8
+ *
9
+ * @requires ParamsRuntime
10
+ * @returns {UseIrisAppName} appName, loading, error
11
+ * @example
12
+ * import { useIrisAppName } from "@trackunit/react-core-hooks";
13
+ * const { appName } = useIrisAppName();
14
+ * useEffect(() => {
15
+ * (async () => {
16
+ * if (appName) {
17
+ * // do something with appName
18
+ * }
19
+ * })();
20
+ * }, [appName]);
21
+ */
22
+ export declare const useIrisAppName: () => UseIrisAppName;
@@ -1,4 +0,0 @@
1
- /**
2
- * A react hook for notifying host about location changes
3
- */
4
- export declare const useURLSynchronization: () => void;
@@ -1,9 +0,0 @@
1
- import { ICustomFieldRuntime } from "@trackunit/iris-app-runtime-core";
2
- export interface UseCustomFieldRuntime extends ICustomFieldRuntime {
3
- }
4
- /**
5
- * A hook to expose custom field runtime methods
6
- *
7
- * @returns {UseCustomFieldRuntime} CustomFieldRuntime
8
- */
9
- export declare const useCustomFieldRuntime: () => UseCustomFieldRuntime;
@@ -1,23 +0,0 @@
1
- import { ValueAndDefinition } from "@trackunit/iris-app-runtime-core";
2
- import { EntityIdentity, ValueAndDefinitionKey } from "@trackunit/iris-app-runtime-core-api";
3
- /**
4
- * This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
5
- *
6
- * @param entity The entity to fetch and set custom fields for.
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"});
18
- */
19
- export declare const useCustomFieldRuntimeForEntity: (entity: EntityIdentity) => {
20
- customFields: ValueAndDefinition[] | undefined;
21
- setCustomFieldsFromFormDataForEntity: (formData: Record<string, boolean | string | string[] | number>) => Promise<void>;
22
- setCustomFieldsForEntity: (values: ValueAndDefinitionKey[]) => Promise<void>;
23
- };