@trackunit/react-core-contexts 1.30.2 → 1.30.4
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 +53 -12
- package/index.esm.js +55 -14
- package/package.json +8 -8
- package/src/useSubscribeToHostChanges.d.ts +17 -6
package/index.cjs.js
CHANGED
|
@@ -352,16 +352,57 @@ const AnalyticsProviderIrisApp = ({ children }) => {
|
|
|
352
352
|
};
|
|
353
353
|
|
|
354
354
|
/**
|
|
355
|
-
* Subscribe to methods initiated by changes in the host
|
|
355
|
+
* Subscribe to methods initiated by changes in the host.
|
|
356
356
|
*
|
|
357
|
-
*
|
|
357
|
+
* Handlers are registered on the singleton `host-runtime` penpal channel via
|
|
358
|
+
* {@link registerHostChangeHandler}, so push events from the host
|
|
359
|
+
* (`onTokenChanged`, `onTimeRangeChanged`, filter-bar updates, …) reach every
|
|
360
|
+
* mounted provider in the iris-app without forcing the host to open one
|
|
361
|
+
* penpal connection per subscription channel.
|
|
362
|
+
*
|
|
363
|
+
* @param methods STABLE object with the methods you'd want to subscribe to.
|
|
364
|
+
* Wrap in `useMemo` (or build with stable callback references) so the
|
|
365
|
+
* effect doesn't re-register on every render.
|
|
366
|
+
* @param _channel Deprecated. Pre-v7 builds used a dedicated penpal channel
|
|
367
|
+
* per subscription provider (e.g. `token-subscription`); v7 collapses all
|
|
368
|
+
* subscriptions onto the singleton's `host-runtime` channel through a
|
|
369
|
+
* handler registry. The argument is accepted for source-compatibility with
|
|
370
|
+
* the v6 API and is ignored.
|
|
358
371
|
*/
|
|
359
|
-
const useSubscribeToHostChanges = (methods) => {
|
|
372
|
+
const useSubscribeToHostChanges = (methods, _channel) => {
|
|
360
373
|
react.useEffect(() => {
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
374
|
+
const unregisters = [];
|
|
375
|
+
// Listed explicitly (rather than via `Object.entries`) so each call to
|
|
376
|
+
// `registerHostChangeHandler<K>` keeps the K → handler-type connection,
|
|
377
|
+
// which a runtime iteration over keys would erase.
|
|
378
|
+
if (methods.onTokenChanged) {
|
|
379
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onTokenChanged", methods.onTokenChanged));
|
|
380
|
+
}
|
|
381
|
+
if (methods.onTimeRangeChanged) {
|
|
382
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onTimeRangeChanged", methods.onTimeRangeChanged));
|
|
383
|
+
}
|
|
384
|
+
if (methods.onFilterBarValuesChanged) {
|
|
385
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onFilterBarValuesChanged", methods.onFilterBarValuesChanged));
|
|
386
|
+
}
|
|
387
|
+
if (methods.onAssetsFilterBarValuesChanged) {
|
|
388
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onAssetsFilterBarValuesChanged", methods.onAssetsFilterBarValuesChanged));
|
|
389
|
+
}
|
|
390
|
+
if (methods.onCustomersFilterBarValuesChanged) {
|
|
391
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onCustomersFilterBarValuesChanged", methods.onCustomersFilterBarValuesChanged));
|
|
392
|
+
}
|
|
393
|
+
if (methods.onSitesFilterBarValuesChanged) {
|
|
394
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onSitesFilterBarValuesChanged", methods.onSitesFilterBarValuesChanged));
|
|
395
|
+
}
|
|
396
|
+
if (methods.onTablePersistenceStateChanged) {
|
|
397
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onTablePersistenceStateChanged", methods.onTablePersistenceStateChanged));
|
|
398
|
+
}
|
|
399
|
+
if (methods.onAssetSortingStateChanged) {
|
|
400
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onAssetSortingStateChanged", methods.onAssetSortingStateChanged));
|
|
401
|
+
}
|
|
402
|
+
if (methods.onWidgetPollIntervalChanged) {
|
|
403
|
+
unregisters.push(irisAppRuntimeCore.registerHostChangeHandler("onWidgetPollIntervalChanged", methods.onWidgetPollIntervalChanged));
|
|
404
|
+
}
|
|
405
|
+
return () => unregisters.forEach(unregister => unregister());
|
|
365
406
|
}, [methods]);
|
|
366
407
|
};
|
|
367
408
|
|
|
@@ -378,7 +419,7 @@ const AssetSortingProviderIrisApp = ({ children }) => {
|
|
|
378
419
|
const methods = react.useMemo(() => ({
|
|
379
420
|
onAssetSortingStateChanged: setAssetSortingState,
|
|
380
421
|
}), [setAssetSortingState]);
|
|
381
|
-
useSubscribeToHostChanges(methods);
|
|
422
|
+
useSubscribeToHostChanges(methods, irisAppRuntimeCoreApi.Channels.AssetSortingSubscription);
|
|
382
423
|
const contextValue = react.useMemo(() => ({
|
|
383
424
|
sortingState: assetSortingState ?? {
|
|
384
425
|
sortBy: irisAppRuntimeCoreApi.AssetSortByProperty.Criticality,
|
|
@@ -493,7 +534,7 @@ const FilterBarProviderIrisApp = ({ children }) => {
|
|
|
493
534
|
setSitesFilterBarValues(values);
|
|
494
535
|
},
|
|
495
536
|
}), []);
|
|
496
|
-
useSubscribeToHostChanges(methods);
|
|
537
|
+
useSubscribeToHostChanges(methods, irisAppRuntimeCoreApi.Channels.FilterBarSubscription);
|
|
497
538
|
const isLoading = react.useMemo(() => assetsFilterBarValues === undefined ||
|
|
498
539
|
customersFilterBarValues === undefined ||
|
|
499
540
|
sitesFilterBarValues === undefined, [assetsFilterBarValues, customersFilterBarValues, sitesFilterBarValues]);
|
|
@@ -596,7 +637,7 @@ const TimeRangeProviderIrisApp = ({ children }) => {
|
|
|
596
637
|
}));
|
|
597
638
|
},
|
|
598
639
|
}), []);
|
|
599
|
-
useSubscribeToHostChanges(methods);
|
|
640
|
+
useSubscribeToHostChanges(methods, irisAppRuntimeCoreApi.Channels.TimeRangeSubscription);
|
|
600
641
|
if (!timeRangeContext) {
|
|
601
642
|
return null;
|
|
602
643
|
}
|
|
@@ -634,7 +675,7 @@ const TokenProviderIrisApp = ({ children }) => {
|
|
|
634
675
|
const methods = react.useMemo(() => ({
|
|
635
676
|
onTokenChanged,
|
|
636
677
|
}), [onTokenChanged]);
|
|
637
|
-
useSubscribeToHostChanges(methods);
|
|
678
|
+
useSubscribeToHostChanges(methods, irisAppRuntimeCoreApi.Channels.TokenSubscription);
|
|
638
679
|
if (state.status === "error") {
|
|
639
680
|
throw new Error("Token context is invalid");
|
|
640
681
|
}
|
|
@@ -762,7 +803,7 @@ const WidgetConfigProviderIrisApp = ({ children }) => {
|
|
|
762
803
|
const methods = react.useMemo(() => ({
|
|
763
804
|
onWidgetPollIntervalChanged: setPollInterval,
|
|
764
805
|
}), [setPollInterval]);
|
|
765
|
-
useSubscribeToHostChanges(methods);
|
|
806
|
+
useSubscribeToHostChanges(methods, irisAppRuntimeCoreApi.Channels.WidgetConfigSubscription);
|
|
766
807
|
const widgetConfigContextValue = react.useMemo(() => ({
|
|
767
808
|
getData: irisAppRuntimeCore.WidgetConfigRuntime.getWidgetData,
|
|
768
809
|
setData: irisAppRuntimeCore.WidgetConfigRuntime.setWidgetData,
|
package/index.esm.js
CHANGED
|
@@ -8,11 +8,11 @@ import { print } from 'graphql';
|
|
|
8
8
|
import { createClient } from 'graphql-sse';
|
|
9
9
|
import { useState, useMemo, useEffect, useCallback, useReducer, Suspense } from 'react';
|
|
10
10
|
import { onError } from '@apollo/client/link/error';
|
|
11
|
-
import { ToastRuntime, AnalyticsRuntime,
|
|
11
|
+
import { ToastRuntime, AnalyticsRuntime, registerHostChangeHandler, AssetSortingRuntime, ConfirmationDialogRuntime, EnvironmentRuntime, ExportDataRuntime, AssetsFilterBarRuntime, CustomersFilterBarRuntime, SitesFilterBarRuntime, GeolocationRuntime, ModalDialogRuntime, NavigationRuntime, OemBrandingRuntime, ThemeCssRuntime, TimeRangeRuntime, TokenRuntime, CurrentUserRuntime, CurrentUserPreferenceRuntime, UserSubscriptionRuntime, WidgetConfigRuntime } from '@trackunit/iris-app-runtime-core';
|
|
12
12
|
import { ToastProvider, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, ExportDataContext, FilterBarProvider, GeolocationProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, TimeRangeProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider, WidgetConfigProvider } from '@trackunit/react-core-contexts-api';
|
|
13
13
|
import { registerTranslations, initializeTranslationsForApp } from '@trackunit/i18n-library-translation';
|
|
14
14
|
import { Spinner } from '@trackunit/react-components';
|
|
15
|
-
import { SortOrder, AssetSortByProperty } from '@trackunit/iris-app-runtime-core-api';
|
|
15
|
+
import { Channels, SortOrder, AssetSortByProperty } from '@trackunit/iris-app-runtime-core-api';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* This error link is used to capture error information, i. e. traceId, graphQL errors, network errors, etc.
|
|
@@ -350,16 +350,57 @@ const AnalyticsProviderIrisApp = ({ children }) => {
|
|
|
350
350
|
};
|
|
351
351
|
|
|
352
352
|
/**
|
|
353
|
-
* Subscribe to methods initiated by changes in the host
|
|
353
|
+
* Subscribe to methods initiated by changes in the host.
|
|
354
354
|
*
|
|
355
|
-
*
|
|
355
|
+
* Handlers are registered on the singleton `host-runtime` penpal channel via
|
|
356
|
+
* {@link registerHostChangeHandler}, so push events from the host
|
|
357
|
+
* (`onTokenChanged`, `onTimeRangeChanged`, filter-bar updates, …) reach every
|
|
358
|
+
* mounted provider in the iris-app without forcing the host to open one
|
|
359
|
+
* penpal connection per subscription channel.
|
|
360
|
+
*
|
|
361
|
+
* @param methods STABLE object with the methods you'd want to subscribe to.
|
|
362
|
+
* Wrap in `useMemo` (or build with stable callback references) so the
|
|
363
|
+
* effect doesn't re-register on every render.
|
|
364
|
+
* @param _channel Deprecated. Pre-v7 builds used a dedicated penpal channel
|
|
365
|
+
* per subscription provider (e.g. `token-subscription`); v7 collapses all
|
|
366
|
+
* subscriptions onto the singleton's `host-runtime` channel through a
|
|
367
|
+
* handler registry. The argument is accepted for source-compatibility with
|
|
368
|
+
* the v6 API and is ignored.
|
|
356
369
|
*/
|
|
357
|
-
const useSubscribeToHostChanges = (methods) => {
|
|
370
|
+
const useSubscribeToHostChanges = (methods, _channel) => {
|
|
358
371
|
useEffect(() => {
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
372
|
+
const unregisters = [];
|
|
373
|
+
// Listed explicitly (rather than via `Object.entries`) so each call to
|
|
374
|
+
// `registerHostChangeHandler<K>` keeps the K → handler-type connection,
|
|
375
|
+
// which a runtime iteration over keys would erase.
|
|
376
|
+
if (methods.onTokenChanged) {
|
|
377
|
+
unregisters.push(registerHostChangeHandler("onTokenChanged", methods.onTokenChanged));
|
|
378
|
+
}
|
|
379
|
+
if (methods.onTimeRangeChanged) {
|
|
380
|
+
unregisters.push(registerHostChangeHandler("onTimeRangeChanged", methods.onTimeRangeChanged));
|
|
381
|
+
}
|
|
382
|
+
if (methods.onFilterBarValuesChanged) {
|
|
383
|
+
unregisters.push(registerHostChangeHandler("onFilterBarValuesChanged", methods.onFilterBarValuesChanged));
|
|
384
|
+
}
|
|
385
|
+
if (methods.onAssetsFilterBarValuesChanged) {
|
|
386
|
+
unregisters.push(registerHostChangeHandler("onAssetsFilterBarValuesChanged", methods.onAssetsFilterBarValuesChanged));
|
|
387
|
+
}
|
|
388
|
+
if (methods.onCustomersFilterBarValuesChanged) {
|
|
389
|
+
unregisters.push(registerHostChangeHandler("onCustomersFilterBarValuesChanged", methods.onCustomersFilterBarValuesChanged));
|
|
390
|
+
}
|
|
391
|
+
if (methods.onSitesFilterBarValuesChanged) {
|
|
392
|
+
unregisters.push(registerHostChangeHandler("onSitesFilterBarValuesChanged", methods.onSitesFilterBarValuesChanged));
|
|
393
|
+
}
|
|
394
|
+
if (methods.onTablePersistenceStateChanged) {
|
|
395
|
+
unregisters.push(registerHostChangeHandler("onTablePersistenceStateChanged", methods.onTablePersistenceStateChanged));
|
|
396
|
+
}
|
|
397
|
+
if (methods.onAssetSortingStateChanged) {
|
|
398
|
+
unregisters.push(registerHostChangeHandler("onAssetSortingStateChanged", methods.onAssetSortingStateChanged));
|
|
399
|
+
}
|
|
400
|
+
if (methods.onWidgetPollIntervalChanged) {
|
|
401
|
+
unregisters.push(registerHostChangeHandler("onWidgetPollIntervalChanged", methods.onWidgetPollIntervalChanged));
|
|
402
|
+
}
|
|
403
|
+
return () => unregisters.forEach(unregister => unregister());
|
|
363
404
|
}, [methods]);
|
|
364
405
|
};
|
|
365
406
|
|
|
@@ -376,7 +417,7 @@ const AssetSortingProviderIrisApp = ({ children }) => {
|
|
|
376
417
|
const methods = useMemo(() => ({
|
|
377
418
|
onAssetSortingStateChanged: setAssetSortingState,
|
|
378
419
|
}), [setAssetSortingState]);
|
|
379
|
-
useSubscribeToHostChanges(methods);
|
|
420
|
+
useSubscribeToHostChanges(methods, Channels.AssetSortingSubscription);
|
|
380
421
|
const contextValue = useMemo(() => ({
|
|
381
422
|
sortingState: assetSortingState ?? {
|
|
382
423
|
sortBy: AssetSortByProperty.Criticality,
|
|
@@ -491,7 +532,7 @@ const FilterBarProviderIrisApp = ({ children }) => {
|
|
|
491
532
|
setSitesFilterBarValues(values);
|
|
492
533
|
},
|
|
493
534
|
}), []);
|
|
494
|
-
useSubscribeToHostChanges(methods);
|
|
535
|
+
useSubscribeToHostChanges(methods, Channels.FilterBarSubscription);
|
|
495
536
|
const isLoading = useMemo(() => assetsFilterBarValues === undefined ||
|
|
496
537
|
customersFilterBarValues === undefined ||
|
|
497
538
|
sitesFilterBarValues === undefined, [assetsFilterBarValues, customersFilterBarValues, sitesFilterBarValues]);
|
|
@@ -594,7 +635,7 @@ const TimeRangeProviderIrisApp = ({ children }) => {
|
|
|
594
635
|
}));
|
|
595
636
|
},
|
|
596
637
|
}), []);
|
|
597
|
-
useSubscribeToHostChanges(methods);
|
|
638
|
+
useSubscribeToHostChanges(methods, Channels.TimeRangeSubscription);
|
|
598
639
|
if (!timeRangeContext) {
|
|
599
640
|
return null;
|
|
600
641
|
}
|
|
@@ -632,7 +673,7 @@ const TokenProviderIrisApp = ({ children }) => {
|
|
|
632
673
|
const methods = useMemo(() => ({
|
|
633
674
|
onTokenChanged,
|
|
634
675
|
}), [onTokenChanged]);
|
|
635
|
-
useSubscribeToHostChanges(methods);
|
|
676
|
+
useSubscribeToHostChanges(methods, Channels.TokenSubscription);
|
|
636
677
|
if (state.status === "error") {
|
|
637
678
|
throw new Error("Token context is invalid");
|
|
638
679
|
}
|
|
@@ -760,7 +801,7 @@ const WidgetConfigProviderIrisApp = ({ children }) => {
|
|
|
760
801
|
const methods = useMemo(() => ({
|
|
761
802
|
onWidgetPollIntervalChanged: setPollInterval,
|
|
762
803
|
}), [setPollInterval]);
|
|
763
|
-
useSubscribeToHostChanges(methods);
|
|
804
|
+
useSubscribeToHostChanges(methods, Channels.WidgetConfigSubscription);
|
|
764
805
|
const widgetConfigContextValue = useMemo(() => ({
|
|
765
806
|
getData: WidgetConfigRuntime.getWidgetData,
|
|
766
807
|
setData: WidgetConfigRuntime.setWidgetData,
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.4",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/iris-app-api": "1.20.
|
|
11
|
-
"@trackunit/iris-app-runtime-core-api": "1.16.
|
|
12
|
-
"@trackunit/react-core-hooks": "1.17.
|
|
13
|
-
"@trackunit/i18n-library-translation": "1.22.
|
|
14
|
-
"@trackunit/react-components": "1.26.
|
|
15
|
-
"@trackunit/iris-app-runtime-core": "1.17.
|
|
10
|
+
"@trackunit/iris-app-api": "1.20.8",
|
|
11
|
+
"@trackunit/iris-app-runtime-core-api": "1.16.7",
|
|
12
|
+
"@trackunit/react-core-hooks": "1.17.11",
|
|
13
|
+
"@trackunit/i18n-library-translation": "1.22.2",
|
|
14
|
+
"@trackunit/react-components": "1.26.4",
|
|
15
|
+
"@trackunit/iris-app-runtime-core": "1.17.7",
|
|
16
16
|
"graphql-sse": "^2.5.4",
|
|
17
|
-
"@trackunit/react-core-contexts-api": "1.17.
|
|
17
|
+
"@trackunit/react-core-contexts-api": "1.17.7"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@apollo/client": "^3.13.8",
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ChildConnectorApi = Parameters<typeof setupHostConnector>[0];
|
|
1
|
+
import { ChildConnectorApi } from "@trackunit/iris-app-runtime-core-api";
|
|
3
2
|
/**
|
|
4
|
-
* Subscribe to methods initiated by changes in the host
|
|
3
|
+
* Subscribe to methods initiated by changes in the host.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
5
|
+
* Handlers are registered on the singleton `host-runtime` penpal channel via
|
|
6
|
+
* {@link registerHostChangeHandler}, so push events from the host
|
|
7
|
+
* (`onTokenChanged`, `onTimeRangeChanged`, filter-bar updates, …) reach every
|
|
8
|
+
* mounted provider in the iris-app without forcing the host to open one
|
|
9
|
+
* penpal connection per subscription channel.
|
|
10
|
+
*
|
|
11
|
+
* @param methods STABLE object with the methods you'd want to subscribe to.
|
|
12
|
+
* Wrap in `useMemo` (or build with stable callback references) so the
|
|
13
|
+
* effect doesn't re-register on every render.
|
|
14
|
+
* @param _channel Deprecated. Pre-v7 builds used a dedicated penpal channel
|
|
15
|
+
* per subscription provider (e.g. `token-subscription`); v7 collapses all
|
|
16
|
+
* subscriptions onto the singleton's `host-runtime` channel through a
|
|
17
|
+
* handler registry. The argument is accepted for source-compatibility with
|
|
18
|
+
* the v6 API and is ignored.
|
|
7
19
|
*/
|
|
8
|
-
export declare const useSubscribeToHostChanges: (methods: ChildConnectorApi) => void;
|
|
9
|
-
export {};
|
|
20
|
+
export declare const useSubscribeToHostChanges: (methods: Partial<ChildConnectorApi>, _channel?: string) => void;
|