@equinor/fusion-framework-react 7.4.0 → 7.4.2
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/CHANGELOG.md +323 -301
- package/dist/esm/Framework.js.map +1 -1
- package/dist/esm/app/useAppProvider.js.map +1 -1
- package/dist/esm/app/useApps.js.map +1 -1
- package/dist/esm/app/useCurrentApp.js.map +1 -1
- package/dist/esm/app/useCurrentAppModule.js.map +1 -1
- package/dist/esm/app/useCurrentAppModules.js +1 -3
- package/dist/esm/app/useCurrentAppModules.js.map +1 -1
- package/dist/esm/create-framework-provider.js.map +1 -1
- package/dist/esm/feature-flag/useCurrentAppFeatures.js.map +1 -1
- package/dist/esm/feature-flag/useFeature.js.map +1 -1
- package/dist/esm/feature-flag/useFeatures.js.map +1 -1
- package/dist/esm/feature-flag/useFrameworkFeature.js.map +1 -1
- package/dist/esm/feature-flag/useFrameworkFeatures.js.map +1 -1
- package/dist/esm/hooks/use-current-user.js.map +1 -1
- package/dist/esm/hooks/use-http-client.js.map +1 -1
- package/dist/esm/signalr/index.js +1 -1
- package/dist/esm/signalr/index.js.map +1 -1
- package/dist/esm/useFramework.js.map +1 -1
- package/dist/esm/useFrameworkModule.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Framework.d.ts +2 -2
- package/dist/types/app/useAppProvider.d.ts +2 -2
- package/dist/types/app/useApps.d.ts +1 -1
- package/dist/types/app/useCurrentApp.d.ts +2 -2
- package/dist/types/app/useCurrentAppModule.d.ts +2 -2
- package/dist/types/app/useCurrentAppModules.d.ts +2 -2
- package/dist/types/create-framework-provider.d.ts +1 -1
- package/dist/types/feature-flag/useFeature.d.ts +1 -1
- package/dist/types/feature-flag/useFeatures.d.ts +2 -2
- package/dist/types/hooks/use-current-user.d.ts +1 -1
- package/dist/types/hooks/use-http-client.d.ts +1 -1
- package/dist/types/useFrameworkModule.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +14 -14
- package/src/Framework.tsx +15 -15
- package/src/app/useAppProvider.ts +7 -7
- package/src/app/useApps.ts +19 -20
- package/src/app/useCurrentApp.ts +23 -23
- package/src/app/useCurrentAppModule.ts +25 -25
- package/src/app/useCurrentAppModules.ts +24 -26
- package/src/create-framework-provider.tsx +19 -18
- package/src/feature-flag/useCurrentAppFeatures.ts +8 -8
- package/src/feature-flag/useFeature.ts +21 -21
- package/src/feature-flag/useFeatures.ts +50 -50
- package/src/feature-flag/useFrameworkFeature.ts +6 -6
- package/src/feature-flag/useFrameworkFeatures.ts +6 -6
- package/src/hooks/use-current-user.ts +3 -3
- package/src/hooks/use-http-client.ts +10 -10
- package/src/signalr/index.ts +11 -10
- package/src/useFramework.ts +9 -9
- package/src/useFrameworkModule.ts +20 -15
- package/src/version.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FrameworkConfigurator } from '@equinor/fusion-framework';
|
|
2
|
-
import { PropsWithChildren, ReactNode } from 'react';
|
|
1
|
+
import type { FrameworkConfigurator } from '@equinor/fusion-framework';
|
|
2
|
+
import { type PropsWithChildren, type ReactNode } from 'react';
|
|
3
3
|
type ConfigureCallback = (configurator: FrameworkConfigurator) => void;
|
|
4
4
|
export declare const Framework: (props: PropsWithChildren<{
|
|
5
5
|
readonly configure: ConfigureCallback;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FusionModulesInstance } from '@equinor/fusion-framework';
|
|
2
|
-
import { AppModule } from '@equinor/fusion-framework-module-app';
|
|
1
|
+
import type { FusionModulesInstance } from '@equinor/fusion-framework';
|
|
2
|
+
import type { AppModule } from '@equinor/fusion-framework-module-app';
|
|
3
3
|
/**
|
|
4
4
|
* React Hook - get appProvider interface
|
|
5
5
|
* @returns framework AppModule
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ConfigEnvironment,
|
|
1
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { ConfigEnvironment, CurrentApp } from '@equinor/fusion-framework-module-app';
|
|
3
3
|
/**
|
|
4
4
|
* Observers the stream of current app and return the latest application
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AppModules, AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
2
|
-
import { ModuleKey,
|
|
1
|
+
import type { AppModules, AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
2
|
+
import type { ModuleKey, AnyModule, ModuleTypes, ModuleType } from '@equinor/fusion-framework-module';
|
|
3
3
|
/**
|
|
4
4
|
* Retrieves the current app module based on the provided module key.
|
|
5
5
|
* @template TType - The type of the module.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
2
|
-
import {
|
|
1
|
+
import type { AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
2
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
3
3
|
/**
|
|
4
4
|
* Observers the stream of current app initialized modules
|
|
5
5
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IFeatureFlag, IFeatureFlagProvider } from '@equinor/fusion-framework-module-feature-flag';
|
|
2
2
|
export interface UseFeatureResult<T> {
|
|
3
3
|
feature?: IFeatureFlag<T>;
|
|
4
4
|
error?: unknown;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { IFeatureFlagProvider, IFeatureFlag } from '@equinor/fusion-framework-module-feature-flag';
|
|
2
|
+
import type { FeatureSelectorFn } from '@equinor/fusion-framework-module-feature-flag/selectors';
|
|
3
3
|
export interface UseFeaturesResult {
|
|
4
4
|
features: IFeatureFlag[];
|
|
5
5
|
error: unknown;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AccountInfo } from '@equinor/fusion-framework-module-msal';
|
|
1
|
+
import type { AccountInfo } from '@equinor/fusion-framework-module-msal';
|
|
2
2
|
export declare const useCurrentUser: () => AccountInfo | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fusion } from '@equinor/fusion-framework';
|
|
1
|
+
import type { Fusion } from '@equinor/fusion-framework';
|
|
2
2
|
type HttpClient = ReturnType<Fusion['modules']['http']['createClient']>;
|
|
3
3
|
type FrameworkHttpClient = 'portal' | 'people';
|
|
4
4
|
export declare const useHttpClient: (name: FrameworkHttpClient) => HttpClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FusionModules, FusionModulesInstance } from '@equinor/fusion-framework';
|
|
2
|
-
import { AnyModule, ModuleKey, ModuleType, ModuleTypes } from '@equinor/fusion-framework-module';
|
|
2
|
+
import type { AnyModule, ModuleKey, ModuleType, ModuleTypes } from '@equinor/fusion-framework-module';
|
|
3
3
|
/**
|
|
4
4
|
* Retrieves a module from the framework instance based on its name.
|
|
5
5
|
*
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "7.4.
|
|
1
|
+
export declare const version = "7.4.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/fusion-framework-react",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -69,30 +69,30 @@
|
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"rxjs": "^7.8.1",
|
|
72
|
-
"@equinor/fusion-framework": "^7.3.
|
|
73
|
-
"@equinor/fusion-framework-
|
|
74
|
-
"@equinor/fusion-framework-react-module
|
|
75
|
-
"@equinor/fusion-
|
|
76
|
-
"@equinor/fusion-
|
|
72
|
+
"@equinor/fusion-framework": "^7.3.2",
|
|
73
|
+
"@equinor/fusion-framework-module": "^4.3.6",
|
|
74
|
+
"@equinor/fusion-framework-react-module": "^3.1.7",
|
|
75
|
+
"@equinor/fusion-framework-react-module-http": "^8.0.2",
|
|
76
|
+
"@equinor/fusion-observable": "^8.4.5"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@types/react": "^18.2.50",
|
|
80
80
|
"@types/react-dom": "^18.2.7",
|
|
81
81
|
"react": "^18.2.0",
|
|
82
82
|
"react-dom": "^18.2.0",
|
|
83
|
-
"typescript": "^5.
|
|
84
|
-
"@equinor/fusion-framework-module-app": "^6.1.
|
|
85
|
-
"@equinor/fusion-framework-module-
|
|
86
|
-
"@equinor/fusion-framework-module-
|
|
87
|
-
"@equinor/fusion-framework-module-
|
|
88
|
-
"@equinor/fusion-framework-
|
|
83
|
+
"typescript": "^5.7.3",
|
|
84
|
+
"@equinor/fusion-framework-module-app": "^6.1.5",
|
|
85
|
+
"@equinor/fusion-framework-module-feature-flag": "^1.1.13",
|
|
86
|
+
"@equinor/fusion-framework-module-event": "^4.3.1",
|
|
87
|
+
"@equinor/fusion-framework-react-module-context": "^6.2.19",
|
|
88
|
+
"@equinor/fusion-framework-module-msal": "^4.0.1"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"@types/react": "^17.0.0 || ^18.0.0",
|
|
92
92
|
"react": "^17.0.0 || ^18.0.0",
|
|
93
93
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
94
|
-
"@equinor/fusion-framework-module-feature-flag": "^1.1.
|
|
95
|
-
"@equinor/fusion-framework-react-module-signalr": "^3.0.
|
|
94
|
+
"@equinor/fusion-framework-module-feature-flag": "^1.1.13",
|
|
95
|
+
"@equinor/fusion-framework-react-module-signalr": "^3.0.22"
|
|
96
96
|
},
|
|
97
97
|
"peerDependenciesMeta": {
|
|
98
98
|
"@equinor/fusion-framework-module-event": {
|
package/src/Framework.tsx
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { FrameworkConfigurator } from '@equinor/fusion-framework';
|
|
1
|
+
import type { FrameworkConfigurator } from '@equinor/fusion-framework';
|
|
2
2
|
import { createFrameworkProvider } from './create-framework-provider';
|
|
3
|
-
import { PropsWithChildren, ReactNode, Suspense, useMemo } from 'react';
|
|
3
|
+
import { type PropsWithChildren, type ReactNode, Suspense, useMemo } from 'react';
|
|
4
4
|
import { useModules } from '@equinor/fusion-framework-react-module';
|
|
5
5
|
|
|
6
6
|
type ConfigureCallback = (configurator: FrameworkConfigurator) => void;
|
|
7
7
|
|
|
8
8
|
export const Framework = (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
props: PropsWithChildren<{
|
|
10
|
+
readonly configure: ConfigureCallback;
|
|
11
|
+
readonly fallback: NonNullable<ReactNode> | null;
|
|
12
|
+
}>,
|
|
13
13
|
) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
const { configure, fallback, children } = props;
|
|
15
|
+
//import modules from parent context
|
|
16
|
+
const ref = useModules<[]>();
|
|
17
|
+
const Component = useMemo(() => createFrameworkProvider(configure, ref), [configure, ref]);
|
|
18
|
+
return (
|
|
19
|
+
<Suspense fallback={fallback}>
|
|
20
|
+
<Component>{children}</Component>
|
|
21
|
+
</Suspense>
|
|
22
|
+
);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export default Framework;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FusionModulesInstance } from '@equinor/fusion-framework';
|
|
2
|
-
import { AppModule } from '@equinor/fusion-framework-module-app';
|
|
1
|
+
import type { FusionModulesInstance } from '@equinor/fusion-framework';
|
|
2
|
+
import type { AppModule } from '@equinor/fusion-framework-module-app';
|
|
3
3
|
|
|
4
4
|
import { useFramework } from '../useFramework';
|
|
5
5
|
|
|
@@ -8,12 +8,12 @@ import { useFramework } from '../useFramework';
|
|
|
8
8
|
* @returns framework AppModule
|
|
9
9
|
*/
|
|
10
10
|
export const useAppProvider = (): FusionModulesInstance<[AppModule]>['app'] => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const provider = useFramework<[AppModule]>().modules.app;
|
|
12
|
+
if (!provider) {
|
|
13
|
+
throw Error('Current framework does not have AppModule configured');
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
return provider;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
export default useAppProvider;
|
package/src/app/useApps.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { AppManifest } from '@equinor/fusion-framework-module-app';
|
|
1
|
+
import type { AppManifest } from '@equinor/fusion-framework-module-app';
|
|
2
2
|
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
|
|
5
5
|
import { useAppProvider } from './useAppProvider';
|
|
6
6
|
|
|
7
7
|
type UseAppsArgs = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
/** @deprecated - no longer available */
|
|
9
|
+
includeHidden?: boolean;
|
|
10
|
+
// only show apps that the current user has access to
|
|
11
|
+
filterByCurrentUser?: boolean;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -18,25 +18,24 @@ type UseAppsArgs = {
|
|
|
18
18
|
* @since 7.1.1
|
|
19
19
|
*/
|
|
20
20
|
export const useApps = (
|
|
21
|
-
|
|
21
|
+
args?: UseAppsArgs,
|
|
22
22
|
): { apps: AppManifest[] | undefined; isLoading: boolean; error: unknown } => {
|
|
23
|
-
|
|
23
|
+
const provider = useAppProvider();
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const { filterByCurrentUser } = args || {};
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
27
|
+
const {
|
|
28
|
+
value: apps,
|
|
29
|
+
complete,
|
|
30
|
+
error,
|
|
31
|
+
} = useObservableState(
|
|
32
|
+
useMemo(
|
|
33
|
+
() => provider.getAppManifests(filterByCurrentUser ? { filterByCurrentUser } : undefined),
|
|
34
|
+
[provider, filterByCurrentUser],
|
|
35
|
+
),
|
|
36
|
+
);
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
return { apps, isLoading: !complete, error };
|
|
40
39
|
};
|
|
41
40
|
|
|
42
41
|
export default useApps;
|
package/src/app/useCurrentApp.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { useMemo } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
6
|
+
import type {
|
|
7
|
+
ConfigEnvironment,
|
|
8
|
+
AppModule,
|
|
9
|
+
CurrentApp,
|
|
10
10
|
} from '@equinor/fusion-framework-module-app';
|
|
11
11
|
|
|
12
12
|
import { useFramework } from '../useFramework';
|
|
@@ -20,26 +20,26 @@ import { useFramework } from '../useFramework';
|
|
|
20
20
|
* @template TEnv type hint what kind of environment config the application has
|
|
21
21
|
*/
|
|
22
22
|
export const useCurrentApp = <
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
TModules extends Array<AnyModule> = [],
|
|
24
|
+
TEnv extends ConfigEnvironment = ConfigEnvironment,
|
|
25
25
|
>(): {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
currentApp?: CurrentApp<TModules, TEnv> | null;
|
|
27
|
+
setCurrentApp: (appKey: string) => void;
|
|
28
|
+
clearCurrentApp: () => void;
|
|
29
|
+
error?: unknown;
|
|
30
30
|
} => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
const provider = useFramework<[AppModule]>().modules.app;
|
|
32
|
+
if (!provider) {
|
|
33
|
+
throw Error('Current framework does not have AppModule configured');
|
|
34
|
+
}
|
|
35
|
+
const currentApp$ = useMemo(() => provider.current$, [provider]);
|
|
36
|
+
const { value, error } = useObservableState(currentApp$, { initial: provider.current });
|
|
37
|
+
return {
|
|
38
|
+
currentApp: value as CurrentApp<TModules, TEnv>,
|
|
39
|
+
setCurrentApp: useMemo(() => provider.setCurrentApp.bind(provider), [provider]),
|
|
40
|
+
clearCurrentApp: useMemo(() => provider.clearCurrentApp.bind(provider), [provider]),
|
|
41
|
+
error,
|
|
42
|
+
};
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
export default useCurrentApp;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AppModules, AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { AppModules, AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
2
|
+
import type {
|
|
3
|
+
ModuleKey,
|
|
4
|
+
AnyModule,
|
|
5
|
+
ModuleTypes,
|
|
6
|
+
ModuleType,
|
|
7
7
|
} from '@equinor/fusion-framework-module';
|
|
8
8
|
import useCurrentAppModules from './useCurrentAppModules';
|
|
9
9
|
|
|
@@ -18,28 +18,28 @@ import useCurrentAppModules from './useCurrentAppModules';
|
|
|
18
18
|
* - when undefined is, the application has not enabled the requested module
|
|
19
19
|
*/
|
|
20
20
|
export const useCurrentAppModule = <
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
TType extends AnyModule | unknown = unknown,
|
|
22
|
+
TKey extends string = ModuleKey<ModuleTypes<AppModules<[TType]>>>,
|
|
23
23
|
>(
|
|
24
|
-
|
|
24
|
+
moduleKey: TKey,
|
|
25
25
|
): {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
module?:
|
|
27
|
+
| (TType extends AnyModule
|
|
28
|
+
? ModuleType<TType>
|
|
29
|
+
: AppModulesInstance[Extract<keyof AppModulesInstance, TKey>])
|
|
30
|
+
| null;
|
|
31
|
+
error?: unknown;
|
|
32
|
+
complete: boolean;
|
|
33
33
|
} => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
const { modules, error, complete } = useCurrentAppModules();
|
|
35
|
+
const module =
|
|
36
|
+
modules === null
|
|
37
|
+
? null
|
|
38
|
+
: modules === undefined
|
|
39
|
+
? undefined
|
|
40
|
+
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
(modules[moduleKey as keyof typeof modules] as any);
|
|
42
|
+
return { module, error, complete };
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
export default useCurrentAppModule;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import useCurrentApp from './useCurrentApp';
|
|
3
3
|
|
|
4
|
-
import { AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
5
|
-
import { Observable, of } from 'rxjs';
|
|
6
|
-
import {
|
|
4
|
+
import type { AppModulesInstance } from '@equinor/fusion-framework-module-app';
|
|
5
|
+
import { type Observable, of } from 'rxjs';
|
|
6
|
+
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
7
7
|
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -15,30 +15,28 @@ import { useObservableState } from '@equinor/fusion-observable/react';
|
|
|
15
15
|
* @returns the observable instance of initialized modules of the application
|
|
16
16
|
*/
|
|
17
17
|
export const useCurrentAppModules = <TModules extends Array<AnyModule> = []>(): {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
modules?: AppModulesInstance<TModules> | null;
|
|
19
|
+
error?: unknown;
|
|
20
|
+
complete: boolean;
|
|
21
21
|
} => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
complete,
|
|
41
|
-
};
|
|
22
|
+
const { currentApp, error: appError } = useCurrentApp<TModules>();
|
|
23
|
+
const modules$ = useMemo(
|
|
24
|
+
() =>
|
|
25
|
+
currentApp ? (currentApp.instance$ as Observable<AppModulesInstance<TModules>>) : of(null),
|
|
26
|
+
[currentApp],
|
|
27
|
+
);
|
|
28
|
+
const {
|
|
29
|
+
value: modules,
|
|
30
|
+
error,
|
|
31
|
+
complete,
|
|
32
|
+
} = useObservableState(modules$, {
|
|
33
|
+
initial: currentApp === undefined ? undefined : (currentApp?.instance ?? null),
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
modules,
|
|
37
|
+
error: error ?? appError,
|
|
38
|
+
complete,
|
|
39
|
+
};
|
|
42
40
|
};
|
|
43
41
|
|
|
44
42
|
export default useCurrentAppModules;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { lazy } from 'react';
|
|
2
3
|
import initFusion from '@equinor/fusion-framework';
|
|
3
4
|
import { FrameworkConfigurator } from '@equinor/fusion-framework';
|
|
4
5
|
|
|
@@ -26,22 +27,22 @@ import { ModuleProvider } from '@equinor/fusion-framework-react-module';
|
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
29
|
export const createFrameworkProvider = <
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
TModules extends Array<AnyModule> = [],
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
TRef extends ModulesInstanceType<[AnyModule]> = any,
|
|
32
33
|
>(
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
cb: (configurator: FrameworkConfigurator<TModules>, ref?: TRef) => void | Promise<void>,
|
|
35
|
+
ref?: TRef,
|
|
35
36
|
): React.LazyExoticComponent<React.FunctionComponent<React.PropsWithChildren<unknown>>> =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
lazy(async () => {
|
|
38
|
+
const configurator = new FrameworkConfigurator<TModules>();
|
|
39
|
+
await cb(configurator, ref);
|
|
40
|
+
const framework = await initFusion(configurator, ref);
|
|
41
|
+
return {
|
|
42
|
+
default: ({ children }: { children?: React.ReactNode }) => (
|
|
43
|
+
<FrameworkProvider value={framework}>
|
|
44
|
+
<ModuleProvider value={framework.modules}>{children}</ModuleProvider>
|
|
45
|
+
</FrameworkProvider>
|
|
46
|
+
),
|
|
47
|
+
};
|
|
48
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FeatureFlagModule } from '@equinor/fusion-framework-module-feature-flag';
|
|
2
2
|
import { useCurrentAppModule } from '../app';
|
|
3
3
|
import { useFeatures, type UseFeaturesResult } from './useFeatures';
|
|
4
4
|
|
|
@@ -7,13 +7,13 @@ import { useFeatures, type UseFeaturesResult } from './useFeatures';
|
|
|
7
7
|
* @returns An object containing the current app features, a function to toggle a feature, and any error that occurred.
|
|
8
8
|
*/
|
|
9
9
|
export const useCurrentAppFeatures = (): UseFeaturesResult => {
|
|
10
|
-
|
|
10
|
+
const { module, error: moduleError } = useCurrentAppModule<FeatureFlagModule>('featureFlag');
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const { features, toggleFeature, error } = useFeatures(module);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
return {
|
|
15
|
+
features,
|
|
16
|
+
toggleFeature,
|
|
17
|
+
error: error ?? moduleError,
|
|
18
|
+
};
|
|
19
19
|
};
|
|
@@ -2,9 +2,9 @@ import { useCallback, useMemo } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { EMPTY } from 'rxjs';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import type {
|
|
6
|
+
IFeatureFlag,
|
|
7
|
+
IFeatureFlagProvider,
|
|
8
8
|
} from '@equinor/fusion-framework-module-feature-flag';
|
|
9
9
|
|
|
10
10
|
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
@@ -12,12 +12,12 @@ import { useObservableState } from '@equinor/fusion-observable/react';
|
|
|
12
12
|
import { findFeature } from '@equinor/fusion-framework-module-feature-flag/selectors';
|
|
13
13
|
|
|
14
14
|
export interface UseFeatureResult<T> {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
feature?: IFeatureFlag<T>;
|
|
16
|
+
error?: unknown;
|
|
17
|
+
/**
|
|
18
|
+
* @param enable - Optional provide new enabled state of the feature flag. _Defaults to inversion of current feature flag state_
|
|
19
|
+
*/
|
|
20
|
+
toggleFeature: (enable?: boolean) => void;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -29,19 +29,19 @@ export interface UseFeatureResult<T> {
|
|
|
29
29
|
* @returns {UseFeatureResult<T>} - An object containing the feature flag value, a function to toggle the feature flag, and any error that occurred.
|
|
30
30
|
*/
|
|
31
31
|
export const useFeature = <T = unknown>(
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
provider: IFeatureFlagProvider,
|
|
33
|
+
key: string,
|
|
34
34
|
): UseFeatureResult<T> => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
const feature$ = useMemo(() => provider.features$.pipe(findFeature<T>(key)), [provider, key]);
|
|
36
|
+
const { value: feature, error } = useObservableState(feature$ ?? EMPTY);
|
|
37
|
+
const toggleFeature = useCallback(
|
|
38
|
+
(enable?: boolean) => {
|
|
39
|
+
const enabled = enable === undefined ? !provider.getFeature(key)?.enabled : enable;
|
|
40
|
+
provider.toggleFeature({ key, enabled });
|
|
41
|
+
},
|
|
42
|
+
[provider, key],
|
|
43
|
+
);
|
|
44
|
+
return { feature, toggleFeature, error };
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
export default useFeature;
|