@trackunit/react-core-contexts 1.19.11 → 1.19.14
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
|
@@ -535,98 +535,136 @@ const TimeRangeProviderIrisApp = ({ children }) => {
|
|
|
535
535
|
return jsxRuntime.jsx(reactCoreContextsApi.TimeRangeProvider, { value: timeRangeContext, children: children });
|
|
536
536
|
};
|
|
537
537
|
|
|
538
|
+
const providerReducer$1 = (_state, action) => {
|
|
539
|
+
switch (action.type) {
|
|
540
|
+
case "resolved":
|
|
541
|
+
return { status: "resolved", context: action.context };
|
|
542
|
+
case "error":
|
|
543
|
+
return { status: "error" };
|
|
544
|
+
default:
|
|
545
|
+
return _state;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
const INITIAL_STATE$2 = { status: "loading" };
|
|
538
549
|
/**
|
|
539
550
|
* This is a provider for the TokenContext.
|
|
540
551
|
*/
|
|
541
552
|
const TokenProviderIrisApp = ({ children }) => {
|
|
542
|
-
const [
|
|
543
|
-
const [ctxError, setCtxError] = react.useState(false);
|
|
553
|
+
const [state, dispatch] = react.useReducer(providerReducer$1, INITIAL_STATE$2);
|
|
544
554
|
react.useEffect(() => {
|
|
545
555
|
irisAppRuntimeCore.TokenRuntime.getTokenContext()
|
|
546
556
|
.then((ctx) => {
|
|
547
557
|
if (!ctx) {
|
|
548
|
-
|
|
558
|
+
dispatch({ type: "error" });
|
|
549
559
|
return;
|
|
550
560
|
}
|
|
551
|
-
|
|
561
|
+
dispatch({ type: "resolved", context: ctx });
|
|
552
562
|
})
|
|
553
|
-
.catch(() =>
|
|
563
|
+
.catch(() => dispatch({ type: "error" }));
|
|
554
564
|
}, []);
|
|
565
|
+
const onTokenChanged = react.useCallback((ctx) => dispatch({ type: "resolved", context: ctx }), []);
|
|
555
566
|
const methods = react.useMemo(() => ({
|
|
556
|
-
onTokenChanged
|
|
557
|
-
}), [
|
|
567
|
+
onTokenChanged,
|
|
568
|
+
}), [onTokenChanged]);
|
|
558
569
|
useSubscribeToHostChanges(methods);
|
|
559
|
-
if (
|
|
570
|
+
if (state.status === "error") {
|
|
560
571
|
throw new Error("Token context is invalid");
|
|
561
572
|
}
|
|
562
|
-
if (
|
|
573
|
+
if (state.status === "loading") {
|
|
563
574
|
return null;
|
|
564
575
|
}
|
|
565
|
-
return jsxRuntime.jsx(reactCoreContextsApi.TokenProvider, { value:
|
|
576
|
+
return jsxRuntime.jsx(reactCoreContextsApi.TokenProvider, { value: state.context, children: children });
|
|
566
577
|
};
|
|
567
578
|
|
|
579
|
+
const providerReducer = (_state, action) => {
|
|
580
|
+
switch (action.type) {
|
|
581
|
+
case "resolved":
|
|
582
|
+
return { status: "resolved", context: action.context };
|
|
583
|
+
case "error":
|
|
584
|
+
return { status: "error" };
|
|
585
|
+
default:
|
|
586
|
+
return _state;
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
const INITIAL_STATE$1 = { status: "loading" };
|
|
568
590
|
/**
|
|
569
591
|
* This is a provider for the CurrentUserContext.
|
|
570
592
|
*/
|
|
571
593
|
const CurrentUserProviderIrisApp = ({ children }) => {
|
|
572
|
-
const [
|
|
573
|
-
const [ctxError, setCtxError] = react.useState(false);
|
|
594
|
+
const [state, dispatch] = react.useReducer(providerReducer, INITIAL_STATE$1);
|
|
574
595
|
react.useEffect(() => {
|
|
575
596
|
irisAppRuntimeCore.CurrentUserRuntime.getCurrentUserContext()
|
|
576
597
|
.then((ctx) => {
|
|
577
598
|
if (!ctx) {
|
|
578
|
-
|
|
599
|
+
dispatch({ type: "error" });
|
|
579
600
|
return;
|
|
580
601
|
}
|
|
581
|
-
|
|
602
|
+
dispatch({ type: "resolved", context: ctx });
|
|
582
603
|
})
|
|
583
|
-
.catch(() =>
|
|
604
|
+
.catch(() => dispatch({ type: "error" }));
|
|
584
605
|
}, []);
|
|
585
|
-
if (
|
|
606
|
+
if (state.status === "error") {
|
|
586
607
|
throw new Error("Current user context is invalid");
|
|
587
608
|
}
|
|
588
|
-
if (
|
|
609
|
+
if (state.status === "loading") {
|
|
589
610
|
return null;
|
|
590
611
|
}
|
|
591
|
-
return jsxRuntime.jsx(reactCoreContextsApi.CurrentUserProvider, { value:
|
|
612
|
+
return jsxRuntime.jsx(reactCoreContextsApi.CurrentUserProvider, { value: state.context, children: children });
|
|
592
613
|
};
|
|
593
614
|
|
|
615
|
+
const preferenceReducer = (state, action) => {
|
|
616
|
+
switch (action.type) {
|
|
617
|
+
case "languageResolved":
|
|
618
|
+
return { ...state, language: action.language };
|
|
619
|
+
case "systemOfMeasurementResolved":
|
|
620
|
+
return { ...state, systemOfMeasurement: action.systemOfMeasurement };
|
|
621
|
+
case "timeZonePreferenceResolved":
|
|
622
|
+
return { ...state, timeZonePreference: action.timeZonePreference };
|
|
623
|
+
case "error":
|
|
624
|
+
return { ...state, error: true };
|
|
625
|
+
default:
|
|
626
|
+
return state;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
const INITIAL_STATE = {
|
|
630
|
+
language: null,
|
|
631
|
+
systemOfMeasurement: undefined,
|
|
632
|
+
timeZonePreference: undefined,
|
|
633
|
+
error: false,
|
|
634
|
+
};
|
|
594
635
|
/**
|
|
595
636
|
* This is a provider for the CurrentUserContext.
|
|
596
637
|
*/
|
|
597
638
|
const CurrentUserPreferenceProviderIrisApp = ({ children }) => {
|
|
598
|
-
const [
|
|
599
|
-
const [systemOfMeasurement, setSystemOfMeasurement] = react.useState(null);
|
|
600
|
-
const [timeZonePreference, setTimeZonePreference] = react.useState(null);
|
|
601
|
-
const [ctxError, setCtxError] = react.useState(false);
|
|
639
|
+
const [state, dispatch] = react.useReducer(preferenceReducer, INITIAL_STATE);
|
|
602
640
|
react.useEffect(() => {
|
|
603
641
|
irisAppRuntimeCore.CurrentUserPreferenceRuntime.getCurrentUserLanguage()
|
|
604
642
|
.then((lang) => {
|
|
605
643
|
if (!lang) {
|
|
606
|
-
|
|
644
|
+
dispatch({ type: "error" });
|
|
607
645
|
return;
|
|
608
646
|
}
|
|
609
|
-
|
|
647
|
+
dispatch({ type: "languageResolved", language: lang });
|
|
610
648
|
})
|
|
611
|
-
.catch(() =>
|
|
612
|
-
}, [setLanguage]);
|
|
613
|
-
react.useEffect(() => {
|
|
649
|
+
.catch(() => dispatch({ type: "error" }));
|
|
614
650
|
irisAppRuntimeCore.CurrentUserPreferenceRuntime.getCurrentUserSystemOfMeasurement()
|
|
615
|
-
.catch(() =>
|
|
616
|
-
.then(
|
|
617
|
-
}, []);
|
|
618
|
-
react.useEffect(() => {
|
|
651
|
+
.catch(() => undefined)
|
|
652
|
+
.then(systemOfMeasurement => dispatch({ type: "systemOfMeasurementResolved", systemOfMeasurement }));
|
|
619
653
|
irisAppRuntimeCore.CurrentUserPreferenceRuntime.getCurrentUserTimeZonePreference()
|
|
620
|
-
.catch(() =>
|
|
621
|
-
.then(
|
|
654
|
+
.catch(() => undefined)
|
|
655
|
+
.then(timeZonePreference => dispatch({ type: "timeZonePreferenceResolved", timeZonePreference }));
|
|
622
656
|
}, []);
|
|
623
|
-
if (
|
|
657
|
+
if (state.error) {
|
|
624
658
|
throw new Error("Language context is invalid");
|
|
625
659
|
}
|
|
626
|
-
if (!language) {
|
|
660
|
+
if (!state.language) {
|
|
627
661
|
return null;
|
|
628
662
|
}
|
|
629
|
-
return (jsxRuntime.jsx(reactCoreContextsApi.CurrentUserPreferenceProvider, { value: {
|
|
663
|
+
return (jsxRuntime.jsx(reactCoreContextsApi.CurrentUserPreferenceProvider, { value: {
|
|
664
|
+
language: state.language,
|
|
665
|
+
systemOfMeasurement: state.systemOfMeasurement,
|
|
666
|
+
timeZonePreference: state.timeZonePreference,
|
|
667
|
+
}, children: children }));
|
|
630
668
|
};
|
|
631
669
|
|
|
632
670
|
/**
|
package/index.esm.js
CHANGED
|
@@ -6,7 +6,7 @@ import { getMainDefinition, Observable } from '@apollo/client/utilities';
|
|
|
6
6
|
import { useEnvironment, useToken, useErrorHandler } from '@trackunit/react-core-hooks';
|
|
7
7
|
import { print } from 'graphql';
|
|
8
8
|
import { createClient } from 'graphql-sse';
|
|
9
|
-
import { useState, useMemo, useEffect, useCallback, Suspense } from 'react';
|
|
9
|
+
import { useState, useMemo, useEffect, useCallback, useReducer, Suspense } from 'react';
|
|
10
10
|
import { onError } from '@apollo/client/link/error';
|
|
11
11
|
import { ToastRuntime, AnalyticsRuntime, setupHostConnector, AssetSortingRuntime, ConfirmationDialogRuntime, EnvironmentRuntime, ExportDataRuntime, AssetsFilterBarRuntime, CustomersFilterBarRuntime, SitesFilterBarRuntime, 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, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, TimeRangeProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider, WidgetConfigProvider } from '@trackunit/react-core-contexts-api';
|
|
@@ -533,98 +533,136 @@ const TimeRangeProviderIrisApp = ({ children }) => {
|
|
|
533
533
|
return jsx(TimeRangeProvider, { value: timeRangeContext, children: children });
|
|
534
534
|
};
|
|
535
535
|
|
|
536
|
+
const providerReducer$1 = (_state, action) => {
|
|
537
|
+
switch (action.type) {
|
|
538
|
+
case "resolved":
|
|
539
|
+
return { status: "resolved", context: action.context };
|
|
540
|
+
case "error":
|
|
541
|
+
return { status: "error" };
|
|
542
|
+
default:
|
|
543
|
+
return _state;
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
const INITIAL_STATE$2 = { status: "loading" };
|
|
536
547
|
/**
|
|
537
548
|
* This is a provider for the TokenContext.
|
|
538
549
|
*/
|
|
539
550
|
const TokenProviderIrisApp = ({ children }) => {
|
|
540
|
-
const [
|
|
541
|
-
const [ctxError, setCtxError] = useState(false);
|
|
551
|
+
const [state, dispatch] = useReducer(providerReducer$1, INITIAL_STATE$2);
|
|
542
552
|
useEffect(() => {
|
|
543
553
|
TokenRuntime.getTokenContext()
|
|
544
554
|
.then((ctx) => {
|
|
545
555
|
if (!ctx) {
|
|
546
|
-
|
|
556
|
+
dispatch({ type: "error" });
|
|
547
557
|
return;
|
|
548
558
|
}
|
|
549
|
-
|
|
559
|
+
dispatch({ type: "resolved", context: ctx });
|
|
550
560
|
})
|
|
551
|
-
.catch(() =>
|
|
561
|
+
.catch(() => dispatch({ type: "error" }));
|
|
552
562
|
}, []);
|
|
563
|
+
const onTokenChanged = useCallback((ctx) => dispatch({ type: "resolved", context: ctx }), []);
|
|
553
564
|
const methods = useMemo(() => ({
|
|
554
|
-
onTokenChanged
|
|
555
|
-
}), [
|
|
565
|
+
onTokenChanged,
|
|
566
|
+
}), [onTokenChanged]);
|
|
556
567
|
useSubscribeToHostChanges(methods);
|
|
557
|
-
if (
|
|
568
|
+
if (state.status === "error") {
|
|
558
569
|
throw new Error("Token context is invalid");
|
|
559
570
|
}
|
|
560
|
-
if (
|
|
571
|
+
if (state.status === "loading") {
|
|
561
572
|
return null;
|
|
562
573
|
}
|
|
563
|
-
return jsx(TokenProvider, { value:
|
|
574
|
+
return jsx(TokenProvider, { value: state.context, children: children });
|
|
564
575
|
};
|
|
565
576
|
|
|
577
|
+
const providerReducer = (_state, action) => {
|
|
578
|
+
switch (action.type) {
|
|
579
|
+
case "resolved":
|
|
580
|
+
return { status: "resolved", context: action.context };
|
|
581
|
+
case "error":
|
|
582
|
+
return { status: "error" };
|
|
583
|
+
default:
|
|
584
|
+
return _state;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
const INITIAL_STATE$1 = { status: "loading" };
|
|
566
588
|
/**
|
|
567
589
|
* This is a provider for the CurrentUserContext.
|
|
568
590
|
*/
|
|
569
591
|
const CurrentUserProviderIrisApp = ({ children }) => {
|
|
570
|
-
const [
|
|
571
|
-
const [ctxError, setCtxError] = useState(false);
|
|
592
|
+
const [state, dispatch] = useReducer(providerReducer, INITIAL_STATE$1);
|
|
572
593
|
useEffect(() => {
|
|
573
594
|
CurrentUserRuntime.getCurrentUserContext()
|
|
574
595
|
.then((ctx) => {
|
|
575
596
|
if (!ctx) {
|
|
576
|
-
|
|
597
|
+
dispatch({ type: "error" });
|
|
577
598
|
return;
|
|
578
599
|
}
|
|
579
|
-
|
|
600
|
+
dispatch({ type: "resolved", context: ctx });
|
|
580
601
|
})
|
|
581
|
-
.catch(() =>
|
|
602
|
+
.catch(() => dispatch({ type: "error" }));
|
|
582
603
|
}, []);
|
|
583
|
-
if (
|
|
604
|
+
if (state.status === "error") {
|
|
584
605
|
throw new Error("Current user context is invalid");
|
|
585
606
|
}
|
|
586
|
-
if (
|
|
607
|
+
if (state.status === "loading") {
|
|
587
608
|
return null;
|
|
588
609
|
}
|
|
589
|
-
return jsx(CurrentUserProvider, { value:
|
|
610
|
+
return jsx(CurrentUserProvider, { value: state.context, children: children });
|
|
590
611
|
};
|
|
591
612
|
|
|
613
|
+
const preferenceReducer = (state, action) => {
|
|
614
|
+
switch (action.type) {
|
|
615
|
+
case "languageResolved":
|
|
616
|
+
return { ...state, language: action.language };
|
|
617
|
+
case "systemOfMeasurementResolved":
|
|
618
|
+
return { ...state, systemOfMeasurement: action.systemOfMeasurement };
|
|
619
|
+
case "timeZonePreferenceResolved":
|
|
620
|
+
return { ...state, timeZonePreference: action.timeZonePreference };
|
|
621
|
+
case "error":
|
|
622
|
+
return { ...state, error: true };
|
|
623
|
+
default:
|
|
624
|
+
return state;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const INITIAL_STATE = {
|
|
628
|
+
language: null,
|
|
629
|
+
systemOfMeasurement: undefined,
|
|
630
|
+
timeZonePreference: undefined,
|
|
631
|
+
error: false,
|
|
632
|
+
};
|
|
592
633
|
/**
|
|
593
634
|
* This is a provider for the CurrentUserContext.
|
|
594
635
|
*/
|
|
595
636
|
const CurrentUserPreferenceProviderIrisApp = ({ children }) => {
|
|
596
|
-
const [
|
|
597
|
-
const [systemOfMeasurement, setSystemOfMeasurement] = useState(null);
|
|
598
|
-
const [timeZonePreference, setTimeZonePreference] = useState(null);
|
|
599
|
-
const [ctxError, setCtxError] = useState(false);
|
|
637
|
+
const [state, dispatch] = useReducer(preferenceReducer, INITIAL_STATE);
|
|
600
638
|
useEffect(() => {
|
|
601
639
|
CurrentUserPreferenceRuntime.getCurrentUserLanguage()
|
|
602
640
|
.then((lang) => {
|
|
603
641
|
if (!lang) {
|
|
604
|
-
|
|
642
|
+
dispatch({ type: "error" });
|
|
605
643
|
return;
|
|
606
644
|
}
|
|
607
|
-
|
|
645
|
+
dispatch({ type: "languageResolved", language: lang });
|
|
608
646
|
})
|
|
609
|
-
.catch(() =>
|
|
610
|
-
}, [setLanguage]);
|
|
611
|
-
useEffect(() => {
|
|
647
|
+
.catch(() => dispatch({ type: "error" }));
|
|
612
648
|
CurrentUserPreferenceRuntime.getCurrentUserSystemOfMeasurement()
|
|
613
|
-
.catch(() =>
|
|
614
|
-
.then(
|
|
615
|
-
}, []);
|
|
616
|
-
useEffect(() => {
|
|
649
|
+
.catch(() => undefined)
|
|
650
|
+
.then(systemOfMeasurement => dispatch({ type: "systemOfMeasurementResolved", systemOfMeasurement }));
|
|
617
651
|
CurrentUserPreferenceRuntime.getCurrentUserTimeZonePreference()
|
|
618
|
-
.catch(() =>
|
|
619
|
-
.then(
|
|
652
|
+
.catch(() => undefined)
|
|
653
|
+
.then(timeZonePreference => dispatch({ type: "timeZonePreferenceResolved", timeZonePreference }));
|
|
620
654
|
}, []);
|
|
621
|
-
if (
|
|
655
|
+
if (state.error) {
|
|
622
656
|
throw new Error("Language context is invalid");
|
|
623
657
|
}
|
|
624
|
-
if (!language) {
|
|
658
|
+
if (!state.language) {
|
|
625
659
|
return null;
|
|
626
660
|
}
|
|
627
|
-
return (jsx(CurrentUserPreferenceProvider, { value: {
|
|
661
|
+
return (jsx(CurrentUserPreferenceProvider, { value: {
|
|
662
|
+
language: state.language,
|
|
663
|
+
systemOfMeasurement: state.systemOfMeasurement,
|
|
664
|
+
timeZonePreference: state.timeZonePreference,
|
|
665
|
+
}, children: children }));
|
|
628
666
|
};
|
|
629
667
|
|
|
630
668
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.14",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@apollo/client": "3.13.8",
|
|
11
11
|
"react": "19.0.0",
|
|
12
|
-
"@trackunit/iris-app-api": "1.15.
|
|
13
|
-
"@trackunit/iris-app-runtime-core-api": "1.12.
|
|
14
|
-
"@trackunit/react-core-hooks": "1.12.
|
|
15
|
-
"@trackunit/i18n-library-translation": "1.13.
|
|
16
|
-
"@trackunit/react-components": "1.18.
|
|
17
|
-
"@trackunit/iris-app-runtime-core": "1.13.
|
|
12
|
+
"@trackunit/iris-app-api": "1.15.7",
|
|
13
|
+
"@trackunit/iris-app-runtime-core-api": "1.12.58",
|
|
14
|
+
"@trackunit/react-core-hooks": "1.12.69",
|
|
15
|
+
"@trackunit/i18n-library-translation": "1.13.13",
|
|
16
|
+
"@trackunit/react-components": "1.18.21",
|
|
17
|
+
"@trackunit/iris-app-runtime-core": "1.13.61",
|
|
18
18
|
"graphql": "^16.10.0",
|
|
19
19
|
"graphql-sse": "^2.5.4",
|
|
20
|
-
"@trackunit/react-core-contexts-api": "1.13.
|
|
20
|
+
"@trackunit/react-core-contexts-api": "1.13.59"
|
|
21
21
|
},
|
|
22
22
|
"module": "./index.esm.js",
|
|
23
23
|
"main": "./index.cjs.js",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CurrentUserPreferenceState } from "@trackunit/iris-app-runtime-core-api";
|
|
1
|
+
import type { CurrentUserPreferenceState } from "@trackunit/iris-app-runtime-core-api";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
export type UserPreferencesContextIrisApp = Pick<CurrentUserPreferenceState, "language" | "timeZonePreference" | "timeZonePreference">;
|
|
4
4
|
interface CurrentUserPreferenceProviderIrisAppProps {
|