@equinor/fusion-framework-react-app 14.0.3 → 14.1.1
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/README.md +9 -2
- package/dist/esm/ag-grid/community.js +12 -0
- package/dist/esm/ag-grid/community.js.map +1 -0
- package/dist/esm/ag-grid/enterprise.js +12 -0
- package/dist/esm/ag-grid/enterprise.js.map +1 -0
- package/dist/esm/ag-grid/react.js +12 -0
- package/dist/esm/ag-grid/react.js.map +1 -0
- package/dist/esm/ag-grid/testing.js +19 -0
- package/dist/esm/ag-grid/testing.js.map +1 -0
- package/dist/esm/ag-grid/theme.js +13 -0
- package/dist/esm/ag-grid/theme.js.map +1 -0
- package/dist/esm/create-component.js +1 -1
- package/dist/esm/msal/useToken.js +12 -3
- package/dist/esm/msal/useToken.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ag-grid/community.d.ts +11 -0
- package/dist/types/ag-grid/enterprise.d.ts +11 -0
- package/dist/types/ag-grid/react.d.ts +11 -0
- package/dist/types/ag-grid/testing.d.ts +18 -0
- package/dist/types/ag-grid/theme.d.ts +13 -0
- package/dist/types/create-component.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +80 -25
- package/CHANGELOG.md +0 -2730
- package/docs/ag-grid.md +0 -70
- package/docs/analytics.md +0 -122
- package/docs/app.md +0 -148
- package/docs/apploader.md +0 -110
- package/docs/bookmark.md +0 -101
- package/docs/context.md +0 -86
- package/docs/feature-flag.md +0 -119
- package/docs/framework.md +0 -93
- package/docs/help-center.md +0 -88
- package/docs/http.md +0 -118
- package/docs/msal.md +0 -291
- package/docs/navigation.md +0 -80
- package/docs/routing.md +0 -86
- package/docs/settings.md +0 -139
- package/src/__tests__/render-app.test.tsx +0 -113
- package/src/__tests__/useStateSyncEvents.test.ts +0 -57
- package/src/ag-grid/useTheme.ts +0 -21
- package/src/analytics/README.md +0 -148
- package/src/analytics/index.ts +0 -9
- package/src/analytics/useTrackFeature.ts +0 -73
- package/src/apploader/Apploader.tsx +0 -50
- package/src/apploader/README.md +0 -81
- package/src/apploader/index.ts +0 -10
- package/src/apploader/useApploader.ts +0 -107
- package/src/bookmark/index.ts +0 -20
- package/src/bookmark/useBookmark.ts +0 -25
- package/src/bookmark/useCurrentBookmark.ts +0 -54
- package/src/context/index.ts +0 -14
- package/src/context/useContextProvider.ts +0 -12
- package/src/context/useCurrentContext.ts +0 -20
- package/src/create-component.tsx +0 -120
- package/src/create-legacy-app.tsx +0 -51
- package/src/feature-flag/README.md +0 -20
- package/src/feature-flag/enable-feature-flag.ts +0 -79
- package/src/feature-flag/index.ts +0 -17
- package/src/feature-flag/useFeature.ts +0 -90
- package/src/framework/index.ts +0 -14
- package/src/framework/useFrameworkCurrentContext.ts +0 -15
- package/src/help-center/README.md +0 -21
- package/src/help-center/event-name.ts +0 -1
- package/src/help-center/index.ts +0 -11
- package/src/help-center/useHelpCenter.ts +0 -162
- package/src/http/index.ts +0 -10
- package/src/http/selectors.ts +0 -9
- package/src/index.ts +0 -46
- package/src/make-component.tsx +0 -102
- package/src/msal/index.ts +0 -16
- package/src/msal/useAccessToken.ts +0 -26
- package/src/msal/useCurrentAccount.ts +0 -21
- package/src/msal/useToken.ts +0 -52
- package/src/navigation/index.ts +0 -10
- package/src/navigation/useNavigationModule.ts +0 -10
- package/src/navigation/useRouter.ts +0 -35
- package/src/render-app.ts +0 -35
- package/src/render-component.tsx +0 -55
- package/src/routing/index.ts +0 -33
- package/src/settings/README.md +0 -123
- package/src/settings/index.ts +0 -12
- package/src/settings/useAppSetting.ts +0 -113
- package/src/settings/useAppSettings.ts +0 -103
- package/src/settings/useAppSettingsStatus.ts +0 -52
- package/src/state/index.ts +0 -12
- package/src/state/useAppState.ts +0 -299
- package/src/state/useStateSyncEvents.ts +0 -59
- package/src/useAppEnvironmentVariables.ts +0 -59
- package/src/useAppModule.ts +0 -45
- package/src/useAppModules.ts +0 -21
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -48
- package/vitest.config.ts +0 -15
package/src/settings/README.md
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
## Portal Settings
|
|
2
|
-
|
|
3
|
-
> TBD
|
|
4
|
-
|
|
5
|
-
## App Settings
|
|
6
|
-
|
|
7
|
-
App settings are a way to store and retrieve settings that are shared across the app. The settings are stored in the configured service of the app module.
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
declare module '@equinor/fusion-framework-react-app/settings' {
|
|
11
|
-
interface AppSettings {
|
|
12
|
-
theme: 'default' | 'light' | 'dark';
|
|
13
|
-
mode: 'simple' | 'advanced';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
useAppSetting('theme', 'default');
|
|
17
|
-
|
|
18
|
-
// Explicit type the setting
|
|
19
|
-
useAppSetting<{notDefined: string}>('notDefined', 'not registered');
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### Example
|
|
23
|
-
|
|
24
|
-
```tsx
|
|
25
|
-
const MyApp = () => {
|
|
26
|
-
const [ theme, setTheme ] = useAppSetting('theme', 'default');
|
|
27
|
-
const [ mode, setMode ] = useAppSetting('mode', 'simple');
|
|
28
|
-
|
|
29
|
-
// using the setter as a callback
|
|
30
|
-
const toggleMode = useCallback(() => {
|
|
31
|
-
setMode(mode => mode === 'simple' ? 'advanced' : 'simple')
|
|
32
|
-
}, [setMode]);
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<MyThemeProvider theme={theme} onChange={setTheme}>
|
|
36
|
-
<Button onClick={toggleMode}>Toggle mode</Button>
|
|
37
|
-
{mode === 'simple' ? <SimpleView /> : <AdvancedView />}
|
|
38
|
-
</MyThemeProvider>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Using all settings
|
|
44
|
-
|
|
45
|
-
> [!WARNING]
|
|
46
|
-
> **Using the `setSettings` must include all settings, not just the ones you want to change.**
|
|
47
|
-
> prefer using `setSettings` with a callback function.
|
|
48
|
-
|
|
49
|
-
> [!IMPORTANT]
|
|
50
|
-
> This is not recommended for large apps, as it will cause re-renders on every setting change.
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
53
|
-
const MyApp = () => {
|
|
54
|
-
const [ settings, setSettings ] = useAppSettings();
|
|
55
|
-
|
|
56
|
-
const updateTheme = useCallback(
|
|
57
|
-
(theme: AppSettings['theme']) => setSettings(settings => ({...settings, theme})),
|
|
58
|
-
[updateSettings]
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<MyThemeProvider theme={settings.theme} onChange={updateTheme}>
|
|
63
|
-
{settings.mode === 'simple' ? <SimpleView /> : <AdvancedView />}
|
|
64
|
-
</MyThemeProvider>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Using hook callbacks
|
|
70
|
-
|
|
71
|
-
The `useAppSettings` and `useAppSetting` hooks can take callbacks for loading, updating, updated and error handling.
|
|
72
|
-
|
|
73
|
-
> [!NOTE]
|
|
74
|
-
> These callbacks are optional and can be used to show loading spinners, error dialogs or other UI elements.
|
|
75
|
-
>
|
|
76
|
-
> We have chosen to use callbacks as parameters to the hooks, instead of returning them, to avoid unnecessary re-renders.
|
|
77
|
-
|
|
78
|
-
> [!NOTE]
|
|
79
|
-
> `onUpdating` and `onLoading` refers to the global state of the settings, not the individual settings. This means that if you have multiple settings that are being updated, the `onUpdating` and `onLoading` will be true until all settings are updated.
|
|
80
|
-
>
|
|
81
|
-
> Good practice is to disable UI elements that can trigger settings updates when `onUpdating` or `onLoading` is true.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
> [!IMPORTANT]
|
|
85
|
-
> Hooks must be memoized to avoid re-renders on every render. Provided callbacks are not internally memoized, to allow consumers to control implementation of these callbacks.
|
|
86
|
-
|
|
87
|
-
```tsx
|
|
88
|
-
|
|
89
|
-
// state and callback for loading settings
|
|
90
|
-
const [ loading, setLoading ] = useState(false);
|
|
91
|
-
|
|
92
|
-
// state and callback for updating settings
|
|
93
|
-
const [ updating, setUpdating ] = useState(false);
|
|
94
|
-
|
|
95
|
-
// state and callback for error handling
|
|
96
|
-
const [ error, setError ] = useState<Error | null>(null);
|
|
97
|
-
|
|
98
|
-
// callback for when settings are updated
|
|
99
|
-
const onUpdated = useCallback(() => {
|
|
100
|
-
showSnackbar('Settings updated');
|
|
101
|
-
}, [showSnackbar]);
|
|
102
|
-
|
|
103
|
-
const [ settings, setSettings ] = useAppSettings(defaultSettings, {
|
|
104
|
-
onLoading: setLoading,
|
|
105
|
-
onUpdating: setUpdating,
|
|
106
|
-
onError: setError,
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const updateSettings = useCallback(() => {
|
|
110
|
-
setSettings(/* new settings */);
|
|
111
|
-
}, [setSettings, onUpdated]);
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
<MyThemeProvider theme={settings.theme}>
|
|
115
|
-
{loading && <Loading />}
|
|
116
|
-
{updating && <Updating />}
|
|
117
|
-
{error && <ErrorDialog error={error} />}
|
|
118
|
-
<Button onClick={updateSettings} disabled={loading||updating}>
|
|
119
|
-
Update settings
|
|
120
|
-
</Button>
|
|
121
|
-
</MyThemeProvider>
|
|
122
|
-
);
|
|
123
|
-
```
|
package/src/settings/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settings sub-path entry-point.
|
|
3
|
-
*
|
|
4
|
-
* Provides hooks for reading and updating per-application user settings
|
|
5
|
-
* that are persisted by the Fusion platform.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
export { useAppSetting } from './useAppSetting';
|
|
10
|
-
export { useAppSettings } from './useAppSettings';
|
|
11
|
-
|
|
12
|
-
export type { AppSettings } from '@equinor/fusion-framework-module-app';
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { useCallback, useLayoutEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { BehaviorSubject, map } from 'rxjs';
|
|
3
|
-
|
|
4
|
-
import { useCurrentApp } from '@equinor/fusion-framework-react/app';
|
|
5
|
-
|
|
6
|
-
import { useAppSettingsStatus, type AppSettingsStatusHooks } from './useAppSettingsStatus';
|
|
7
|
-
|
|
8
|
-
import type { AppSettings } from '@equinor/fusion-framework-module-app';
|
|
9
|
-
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
10
|
-
|
|
11
|
-
type UpdateSettingFunction<T, O = T> = (currentSetting: T | undefined) => O;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Custom hook to manage application settings.
|
|
15
|
-
*
|
|
16
|
-
* @template TSettings - The type of the settings object. Defaults to `AppSettings`.
|
|
17
|
-
* @template TProp - The type of the property key in the settings object. Defaults to `keyof TSettings`.
|
|
18
|
-
*
|
|
19
|
-
* @param {TProp} prop - The property key in the settings object to manage.
|
|
20
|
-
* @param {TSettings[TProp]} [defaultValue] - The default value for the setting.
|
|
21
|
-
* @param hooks - Optional hooks to handle the status changes and errors.
|
|
22
|
-
*
|
|
23
|
-
* @returns {Array} An array containing:
|
|
24
|
-
* - `setting`: The current setting value or undefined.
|
|
25
|
-
* - `setSetting`: A function to update the setting.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* const { setting, setSetting } = useAppSetting('theme');
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* // with default value
|
|
32
|
-
* const { setting, setSetting } = useAppSetting('theme', 'dark');
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* // with hooks
|
|
36
|
-
* const [isLoading, setIsLoading] = useState(false);
|
|
37
|
-
* const [isUpdating, setIsUpdating] = useState(false);
|
|
38
|
-
* const [error, setError] = useState<Error | null>(null);
|
|
39
|
-
*
|
|
40
|
-
* const { setting, setSetting } = useAppSetting('theme', 'dark', {
|
|
41
|
-
* onLoading: setIsLoading,
|
|
42
|
-
* onUpdating: setIsUpdating,
|
|
43
|
-
* onError: setError,
|
|
44
|
-
* onUpdated: useCallback(() => console.log('Settings updated'), [])
|
|
45
|
-
* });
|
|
46
|
-
*/
|
|
47
|
-
export const useAppSetting = <
|
|
48
|
-
TSettings extends Record<string, unknown> = AppSettings,
|
|
49
|
-
TProp extends keyof TSettings = keyof TSettings,
|
|
50
|
-
>(
|
|
51
|
-
prop: TProp,
|
|
52
|
-
defaultValue?: TSettings[TProp],
|
|
53
|
-
hooks?: AppSettingsStatusHooks & {
|
|
54
|
-
onError?: (error: Error | null) => void;
|
|
55
|
-
onUpdated?: () => void;
|
|
56
|
-
},
|
|
57
|
-
): [
|
|
58
|
-
TSettings[TProp] | undefined,
|
|
59
|
-
(update: TSettings[TProp] | UpdateSettingFunction<TSettings[TProp]>) => void,
|
|
60
|
-
] => {
|
|
61
|
-
const [{ onError, onUpdated, onLoading, onUpdating }] = useState(() => hooks ?? {});
|
|
62
|
-
|
|
63
|
-
const { currentApp = null } = useCurrentApp();
|
|
64
|
-
|
|
65
|
-
// create a subject to manage the setting value
|
|
66
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: new subject when app changes
|
|
67
|
-
const subject = useMemo(() => {
|
|
68
|
-
return new BehaviorSubject<TSettings[TProp] | undefined>(defaultValue);
|
|
69
|
-
}, [currentApp]);
|
|
70
|
-
|
|
71
|
-
useLayoutEffect(() => {
|
|
72
|
-
// Narrow the settings stream down to just this specific setting's value
|
|
73
|
-
const sub = currentApp?.settings$
|
|
74
|
-
.pipe(map((settings) => (settings as TSettings)[prop]))
|
|
75
|
-
.subscribe(subject);
|
|
76
|
-
return () => sub?.unsubscribe();
|
|
77
|
-
}, [currentApp, subject, prop]);
|
|
78
|
-
|
|
79
|
-
// subscribe to the setting value
|
|
80
|
-
const { value: setting } = useObservableState(subject);
|
|
81
|
-
|
|
82
|
-
// update function
|
|
83
|
-
const setSetting = useCallback(
|
|
84
|
-
(update: TSettings[TProp] | UpdateSettingFunction<TSettings[TProp]>) => {
|
|
85
|
-
// Cannot persist a setting update without a current app to write it to
|
|
86
|
-
if (!currentApp) {
|
|
87
|
-
return onError?.(new Error('App is not available'));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// resolve setting value with the provided value or function
|
|
91
|
-
const value =
|
|
92
|
-
typeof update === 'function'
|
|
93
|
-
? (update as UpdateSettingFunction<TSettings[TProp]>)(subject.value)
|
|
94
|
-
: update;
|
|
95
|
-
|
|
96
|
-
currentApp.updateSetting<TSettings, TProp>(prop, value).subscribe({
|
|
97
|
-
error: onError,
|
|
98
|
-
complete: onUpdated,
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
[currentApp, subject, prop, onError, onUpdated],
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// status hooks
|
|
105
|
-
useAppSettingsStatus(currentApp, {
|
|
106
|
-
onLoading,
|
|
107
|
-
onUpdating,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return [setting, setSetting];
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export default useAppSetting;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { useCallback, useLayoutEffect, useMemo } from 'react';
|
|
2
|
-
import { BehaviorSubject, type Observable } from 'rxjs';
|
|
3
|
-
|
|
4
|
-
import type { AppSettings } from '@equinor/fusion-framework-module-app';
|
|
5
|
-
|
|
6
|
-
import { useCurrentApp } from '@equinor/fusion-framework-react/app';
|
|
7
|
-
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
8
|
-
|
|
9
|
-
import { useAppSettingsStatus, type AppSettingsStatusHooks } from './useAppSettingsStatus';
|
|
10
|
-
|
|
11
|
-
type UpdateSettingsFunction<T, O = T> = (currentSettings: T | undefined) => O;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Custom hook to manage application settings.
|
|
15
|
-
*
|
|
16
|
-
* @template TSettings - The type of the settings object, extending Record<string, any>. Defaults to AppSettings.
|
|
17
|
-
*
|
|
18
|
-
* @param {TSettings} [defaultValue] - The default value for the settings.
|
|
19
|
-
* @param hooks - Optional hooks to handle the status changes and errors.
|
|
20
|
-
*
|
|
21
|
-
* @remarks
|
|
22
|
-
* `defaultValue` will only be used on the first render.
|
|
23
|
-
* `hooks`must be memoized to avoid unnecessary re-renders.
|
|
24
|
-
*
|
|
25
|
-
* @returns {Array} An array containing:
|
|
26
|
-
* - `settings`: The current settings object.
|
|
27
|
-
* - `setSettings`: A function to update the settings.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* const [settings, setSettings] = useAppSettings();
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* const [settings, setSettings] = useAppSettings({ theme: 'dark' });
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* const [isLoading, setIsLoading] = useState(false);
|
|
37
|
-
* const [isUpdating, setIsUpdating] = useState(false);
|
|
38
|
-
* const [error, setError] = useState<Error | null>(null);
|
|
39
|
-
*
|
|
40
|
-
* const onUpdated = useCallback(() => console.log('Settings updated'), []);
|
|
41
|
-
*
|
|
42
|
-
* const [settings, setSettings] = useAppSettings({ theme: 'dark' }, {
|
|
43
|
-
* onLoading: setIsLoading,
|
|
44
|
-
* onUpdating: setIsUpdating,
|
|
45
|
-
* onError: setError,
|
|
46
|
-
* onUpdated,
|
|
47
|
-
* });
|
|
48
|
-
*/
|
|
49
|
-
export const useAppSettings = <TSettings extends Record<string, unknown> = AppSettings>(
|
|
50
|
-
defaultValue?: TSettings,
|
|
51
|
-
hooks?: AppSettingsStatusHooks & {
|
|
52
|
-
onError?: (error: Error | null) => void;
|
|
53
|
-
onUpdated?: () => void;
|
|
54
|
-
},
|
|
55
|
-
): [TSettings, (settings: TSettings | UpdateSettingsFunction<TSettings>) => void] => {
|
|
56
|
-
const { onError, onUpdated, onLoading, onUpdating } = hooks ?? {};
|
|
57
|
-
const { currentApp = null } = useCurrentApp();
|
|
58
|
-
|
|
59
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: create new subject when app changes
|
|
60
|
-
const subject = useMemo(() => {
|
|
61
|
-
return new BehaviorSubject<TSettings>(defaultValue ?? ({} as TSettings));
|
|
62
|
-
}, [currentApp]);
|
|
63
|
-
|
|
64
|
-
// connect the subject to the current app settings stream
|
|
65
|
-
useLayoutEffect(() => {
|
|
66
|
-
// Nothing to subscribe to until an app is resolved
|
|
67
|
-
if (!currentApp) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const sub = (currentApp.settings$ as Observable<TSettings>).subscribe(subject);
|
|
71
|
-
return () => sub.unsubscribe();
|
|
72
|
-
}, [currentApp, subject]);
|
|
73
|
-
|
|
74
|
-
// subscribe to the subject to get the latest settings
|
|
75
|
-
const { value: settings } = useObservableState(subject, { initial: defaultValue });
|
|
76
|
-
|
|
77
|
-
const setSettings = useCallback(
|
|
78
|
-
(update: TSettings | UpdateSettingsFunction<TSettings>) => {
|
|
79
|
-
// Cannot persist settings updates without a current app to write them to
|
|
80
|
-
if (!currentApp) {
|
|
81
|
-
return onError?.(new Error('App is not available'));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// resolve settings with the provided value or function
|
|
85
|
-
const settings = typeof update === 'function' ? update(subject.value) : update;
|
|
86
|
-
|
|
87
|
-
currentApp.updateSettings(settings).subscribe({
|
|
88
|
-
next: () => {
|
|
89
|
-
onUpdated?.();
|
|
90
|
-
onError?.(null);
|
|
91
|
-
},
|
|
92
|
-
error: onError,
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
[currentApp, subject, onError, onUpdated],
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
useAppSettingsStatus(currentApp, { onLoading, onUpdating });
|
|
99
|
-
|
|
100
|
-
return [settings, setSettings];
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export default useAppSettings;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect } from 'react';
|
|
2
|
-
import { map } from 'rxjs';
|
|
3
|
-
|
|
4
|
-
import type { IApp } from '@equinor/fusion-framework-module-app';
|
|
5
|
-
|
|
6
|
-
export type AppSettingsStatusHooks = {
|
|
7
|
-
onLoading?: (isLoading: boolean) => void;
|
|
8
|
-
onUpdating?: (isUpdating: boolean) => void;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Custom hook to handle app settings status updates.
|
|
13
|
-
*
|
|
14
|
-
* @param {IApp | null} app - The app instance to monitor settings status.
|
|
15
|
-
* @param {AppSettingsStatusHooks} [hooks] - Optional hooks to handle loading and updating status.
|
|
16
|
-
* @param {function} [hooks.onLoading] - Callback function to handle loading status.
|
|
17
|
-
* @param {function} [hooks.onUpdating] - Callback function to handle updating status.
|
|
18
|
-
*
|
|
19
|
-
* @returns {void}
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const hooks = useMemo(() => ({
|
|
23
|
-
* onLoading: (isLoading) => console.log('Loading:', isLoading),
|
|
24
|
-
* onUpdating: (isUpdating) => console.log('Updating:', isUpdating),
|
|
25
|
-
* }, []);
|
|
26
|
-
* useAppSettingsStatus(app, hooks);
|
|
27
|
-
*/
|
|
28
|
-
export const useAppSettingsStatus = (app: IApp | null, hooks?: AppSettingsStatusHooks) => {
|
|
29
|
-
const { onLoading, onUpdating } = hooks ?? {};
|
|
30
|
-
|
|
31
|
-
useLayoutEffect(() => {
|
|
32
|
-
// Only subscribe once both an app and an onLoading callback are available
|
|
33
|
-
if (app && onLoading) {
|
|
34
|
-
// Derive a boolean loading flag from whether 'fetch_settings' is an active status
|
|
35
|
-
const subscription = app.status$
|
|
36
|
-
.pipe(map((status) => status.has('fetch_settings')))
|
|
37
|
-
.subscribe(onLoading);
|
|
38
|
-
return () => subscription.unsubscribe();
|
|
39
|
-
}
|
|
40
|
-
}, [app, onLoading]);
|
|
41
|
-
|
|
42
|
-
useLayoutEffect(() => {
|
|
43
|
-
// Only subscribe once both an app and an onUpdating callback are available
|
|
44
|
-
if (app && onUpdating) {
|
|
45
|
-
// Derive a boolean updating flag from whether 'update_settings' is an active status
|
|
46
|
-
const subscription = app.status$
|
|
47
|
-
.pipe(map((status) => status.has('update_settings')))
|
|
48
|
-
.subscribe(onUpdating);
|
|
49
|
-
return () => subscription.unsubscribe();
|
|
50
|
-
}
|
|
51
|
-
}, [app, onUpdating]);
|
|
52
|
-
};
|
package/src/state/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
AllowedValue,
|
|
3
|
-
IStateProvider,
|
|
4
|
-
StateItem,
|
|
5
|
-
StateSyncEvent,
|
|
6
|
-
type StateSyncEventType,
|
|
7
|
-
} from '@equinor/fusion-framework-module-state';
|
|
8
|
-
|
|
9
|
-
export { enableState as enableAppState } from '@equinor/fusion-framework-app/enable-state';
|
|
10
|
-
|
|
11
|
-
export { useAppState } from './useAppState';
|
|
12
|
-
export { useStateSyncEvents } from './useStateSyncEvents';
|