@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.
Files changed (54) hide show
  1. package/CHANGELOG.md +323 -301
  2. package/dist/esm/Framework.js.map +1 -1
  3. package/dist/esm/app/useAppProvider.js.map +1 -1
  4. package/dist/esm/app/useApps.js.map +1 -1
  5. package/dist/esm/app/useCurrentApp.js.map +1 -1
  6. package/dist/esm/app/useCurrentAppModule.js.map +1 -1
  7. package/dist/esm/app/useCurrentAppModules.js +1 -3
  8. package/dist/esm/app/useCurrentAppModules.js.map +1 -1
  9. package/dist/esm/create-framework-provider.js.map +1 -1
  10. package/dist/esm/feature-flag/useCurrentAppFeatures.js.map +1 -1
  11. package/dist/esm/feature-flag/useFeature.js.map +1 -1
  12. package/dist/esm/feature-flag/useFeatures.js.map +1 -1
  13. package/dist/esm/feature-flag/useFrameworkFeature.js.map +1 -1
  14. package/dist/esm/feature-flag/useFrameworkFeatures.js.map +1 -1
  15. package/dist/esm/hooks/use-current-user.js.map +1 -1
  16. package/dist/esm/hooks/use-http-client.js.map +1 -1
  17. package/dist/esm/signalr/index.js +1 -1
  18. package/dist/esm/signalr/index.js.map +1 -1
  19. package/dist/esm/useFramework.js.map +1 -1
  20. package/dist/esm/useFrameworkModule.js.map +1 -1
  21. package/dist/esm/version.js +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/dist/types/Framework.d.ts +2 -2
  24. package/dist/types/app/useAppProvider.d.ts +2 -2
  25. package/dist/types/app/useApps.d.ts +1 -1
  26. package/dist/types/app/useCurrentApp.d.ts +2 -2
  27. package/dist/types/app/useCurrentAppModule.d.ts +2 -2
  28. package/dist/types/app/useCurrentAppModules.d.ts +2 -2
  29. package/dist/types/create-framework-provider.d.ts +1 -1
  30. package/dist/types/feature-flag/useFeature.d.ts +1 -1
  31. package/dist/types/feature-flag/useFeatures.d.ts +2 -2
  32. package/dist/types/hooks/use-current-user.d.ts +1 -1
  33. package/dist/types/hooks/use-http-client.d.ts +1 -1
  34. package/dist/types/useFrameworkModule.d.ts +1 -1
  35. package/dist/types/version.d.ts +1 -1
  36. package/package.json +14 -14
  37. package/src/Framework.tsx +15 -15
  38. package/src/app/useAppProvider.ts +7 -7
  39. package/src/app/useApps.ts +19 -20
  40. package/src/app/useCurrentApp.ts +23 -23
  41. package/src/app/useCurrentAppModule.ts +25 -25
  42. package/src/app/useCurrentAppModules.ts +24 -26
  43. package/src/create-framework-provider.tsx +19 -18
  44. package/src/feature-flag/useCurrentAppFeatures.ts +8 -8
  45. package/src/feature-flag/useFeature.ts +21 -21
  46. package/src/feature-flag/useFeatures.ts +50 -50
  47. package/src/feature-flag/useFrameworkFeature.ts +6 -6
  48. package/src/feature-flag/useFrameworkFeatures.ts +6 -6
  49. package/src/hooks/use-current-user.ts +3 -3
  50. package/src/hooks/use-http-client.ts +10 -10
  51. package/src/signalr/index.ts +11 -10
  52. package/src/useFramework.ts +9 -9
  53. package/src/useFrameworkModule.ts +20 -15
  54. package/src/version.ts +1 -1
@@ -3,23 +3,23 @@ import { useCallback, useMemo } from 'react';
3
3
  import { of } from 'rxjs';
4
4
  import { map } from 'rxjs/operators';
5
5
 
6
- import {
7
- type IFeatureFlagProvider,
8
- type IFeatureFlag,
6
+ import type {
7
+ IFeatureFlagProvider,
8
+ IFeatureFlag,
9
9
  } from '@equinor/fusion-framework-module-feature-flag';
10
10
 
11
- import { type FeatureSelectorFn } from '@equinor/fusion-framework-module-feature-flag/selectors';
11
+ import type { FeatureSelectorFn } from '@equinor/fusion-framework-module-feature-flag/selectors';
12
12
 
13
13
  import { useObservableState } from '@equinor/fusion-observable/react';
14
14
 
15
15
  export interface UseFeaturesResult {
16
- features: IFeatureFlag[];
17
- error: unknown;
18
- /**
19
- * @param key - The key of the feature flag.
20
- * @param enable - Optional provide new enabled state of the feature flag. _Defaults to inversion of current feature flag state_
21
- */
22
- toggleFeature: (key: string, enable?: boolean) => void;
16
+ features: IFeatureFlag[];
17
+ error: unknown;
18
+ /**
19
+ * @param key - The key of the feature flag.
20
+ * @param enable - Optional provide new enabled state of the feature flag. _Defaults to inversion of current feature flag state_
21
+ */
22
+ toggleFeature: (key: string, enable?: boolean) => void;
23
23
  }
24
24
 
25
25
  /**
@@ -31,47 +31,47 @@ export interface UseFeaturesResult {
31
31
  * @throws Error if the feature flag provider is missing.
32
32
  */
33
33
  export const useFeatures = (
34
- provider?: IFeatureFlagProvider | null,
35
- selector?: FeatureSelectorFn,
34
+ provider?: IFeatureFlagProvider | null,
35
+ selector?: FeatureSelectorFn,
36
36
  ): UseFeaturesResult => {
37
- /**
38
- * Custom hook that provides access to the feature flags and their values.
39
- *
40
- * @returns An object containing the features and any error that occurred while retrieving them.
41
- */
42
- const { value: features, error } = useObservableState(
43
- useMemo(() => {
44
- if (provider) {
45
- return provider?.features$.pipe(
46
- map((x) => {
47
- const values = Object.values(x);
48
- return selector ? values.filter(selector) : values;
49
- }),
50
- );
51
- }
52
- return of([]);
53
- }, [provider, selector]),
54
- { initial: Object.values(provider?.features ?? {}) },
55
- );
56
- /**
57
- * Sets the enabled state of a feature flag.
58
- *
59
- * @param key - The key of the feature flag.
60
- * @param enable - The new enabled state of the feature flag.
61
- * @throws Error if IFeatureFlagProvider is missing.
62
- */
63
- const toggleFeature = useCallback(
64
- (key: string, enable?: boolean) => {
65
- if (!provider) {
66
- throw new Error('Missing IFeatureFlagProvider.');
67
- }
68
- const enabled = enable === undefined ? !provider.getFeature(key)?.enabled : enable;
37
+ /**
38
+ * Custom hook that provides access to the feature flags and their values.
39
+ *
40
+ * @returns An object containing the features and any error that occurred while retrieving them.
41
+ */
42
+ const { value: features, error } = useObservableState(
43
+ useMemo(() => {
44
+ if (provider) {
45
+ return provider?.features$.pipe(
46
+ map((x) => {
47
+ const values = Object.values(x);
48
+ return selector ? values.filter(selector) : values;
49
+ }),
50
+ );
51
+ }
52
+ return of([]);
53
+ }, [provider, selector]),
54
+ { initial: Object.values(provider?.features ?? {}) },
55
+ );
56
+ /**
57
+ * Sets the enabled state of a feature flag.
58
+ *
59
+ * @param key - The key of the feature flag.
60
+ * @param enable - The new enabled state of the feature flag.
61
+ * @throws Error if IFeatureFlagProvider is missing.
62
+ */
63
+ const toggleFeature = useCallback(
64
+ (key: string, enable?: boolean) => {
65
+ if (!provider) {
66
+ throw new Error('Missing IFeatureFlagProvider.');
67
+ }
68
+ const enabled = enable === undefined ? !provider.getFeature(key)?.enabled : enable;
69
69
 
70
- provider.toggleFeature({ key, enabled });
71
- },
72
- [provider],
73
- );
74
- return { features, error, toggleFeature };
70
+ provider.toggleFeature({ key, enabled });
71
+ },
72
+ [provider],
73
+ );
74
+ return { features, error, toggleFeature };
75
75
  };
76
76
 
77
77
  export default useFeatures;
@@ -1,4 +1,4 @@
1
- import { type FeatureFlagModule } from '@equinor/fusion-framework-module-feature-flag';
1
+ import type { FeatureFlagModule } from '@equinor/fusion-framework-module-feature-flag';
2
2
 
3
3
  import { useFrameworkModule } from '../useFrameworkModule';
4
4
  import { useFeature } from './useFeature';
@@ -12,11 +12,11 @@ import { useFeature } from './useFeature';
12
12
  * @throws {Error} - If feature flagging is not enabled in the framework.
13
13
  */
14
14
  export const useFrameworkFeature = <T>(key: string): ReturnType<typeof useFeature<T>> => {
15
- const provider = useFrameworkModule<FeatureFlagModule>('featureFlag');
16
- if (!provider) {
17
- throw Error('Feature flagging is not enabled in the framework');
18
- }
19
- return useFeature(provider, key);
15
+ const provider = useFrameworkModule<FeatureFlagModule>('featureFlag');
16
+ if (!provider) {
17
+ throw Error('Feature flagging is not enabled in the framework');
18
+ }
19
+ return useFeature(provider, key);
20
20
  };
21
21
 
22
22
  export default useFrameworkFeature;
@@ -1,4 +1,4 @@
1
- import { type FeatureFlagModule } from '@equinor/fusion-framework-module-feature-flag';
1
+ import type { FeatureFlagModule } from '@equinor/fusion-framework-module-feature-flag';
2
2
 
3
3
  import { useFrameworkModule } from '../useFrameworkModule';
4
4
  import { useFeatures } from './useFeatures';
@@ -10,11 +10,11 @@ import { useFeatures } from './useFeatures';
10
10
  * @throws Error if feature flagging is not enabled in the framework.
11
11
  */
12
12
  export const useFrameworkFeatures = (): ReturnType<typeof useFeatures> => {
13
- const provider = useFrameworkModule<FeatureFlagModule>('featureFlag');
14
- if (!provider) {
15
- throw Error('Feature flagging is not enabled in the framework');
16
- }
17
- return useFeatures(provider);
13
+ const provider = useFrameworkModule<FeatureFlagModule>('featureFlag');
14
+ if (!provider) {
15
+ throw Error('Feature flagging is not enabled in the framework');
16
+ }
17
+ return useFeatures(provider);
18
18
  };
19
19
 
20
20
  export default useFrameworkFeatures;
@@ -1,7 +1,7 @@
1
- import { AccountInfo } from '@equinor/fusion-framework-module-msal';
1
+ import type { AccountInfo } from '@equinor/fusion-framework-module-msal';
2
2
  import { useFramework } from '../useFramework';
3
3
 
4
4
  export const useCurrentUser = (): AccountInfo | undefined => {
5
- const framework = useFramework();
6
- return framework.modules.auth.defaultAccount;
5
+ const framework = useFramework();
6
+ return framework.modules.auth.defaultAccount;
7
7
  };
@@ -1,19 +1,19 @@
1
1
  import { useMemo } from 'react';
2
- import { Fusion } from '@equinor/fusion-framework';
2
+ import type { Fusion } from '@equinor/fusion-framework';
3
3
  import { useFramework } from '../useFramework';
4
4
 
5
5
  type HttpClient = ReturnType<Fusion['modules']['http']['createClient']>;
6
6
  type FrameworkHttpClient = 'portal' | 'people';
7
7
 
8
8
  export const useHttpClient = (name: FrameworkHttpClient): HttpClient => {
9
- const framework = useFramework();
9
+ const framework = useFramework();
10
10
 
11
- const client = useMemo(() => {
12
- if (framework.modules.http.hasClient(name)) {
13
- return framework.modules.http.createClient(name);
14
- }
15
- throw Error(`no configured client for key [${name}]`);
16
- }, [framework, name]);
17
- // TODO - abort on unmount?
18
- return client;
11
+ const client = useMemo(() => {
12
+ if (framework.modules.http.hasClient(name)) {
13
+ return framework.modules.http.createClient(name);
14
+ }
15
+ throw Error(`no configured client for key [${name}]`);
16
+ }, [framework, name]);
17
+ // TODO - abort on unmount?
18
+ return client;
19
19
  };
@@ -1,6 +1,9 @@
1
1
  import { useFramework } from '../useFramework';
2
2
 
3
- import { SignalRModule, useProviderTopic } from '@equinor/fusion-framework-react-module-signalr';
3
+ import {
4
+ type SignalRModule,
5
+ useProviderTopic,
6
+ } from '@equinor/fusion-framework-react-module-signalr';
4
7
 
5
8
  /**
6
9
  * hook for subscribing to a topic of a SignalR hub
@@ -25,14 +28,12 @@ const myHook = () => {
25
28
  * @returns Topic
26
29
  */
27
30
  export const useSignalR = <T>(
28
- hubId: string,
29
- topicId: string,
31
+ hubId: string,
32
+ topicId: string,
30
33
  ): ReturnType<typeof useProviderTopic<T>> => {
31
- const provider = useFramework<[SignalRModule]>().modules.signalR;
32
- if (!provider) {
33
- throw Error(
34
- 'SignalR is not configured, see @equinor/fusion-framework-react-module-signalr',
35
- );
36
- }
37
- return useProviderTopic(provider, hubId, topicId);
34
+ const provider = useFramework<[SignalRModule]>().modules.signalR;
35
+ if (!provider) {
36
+ throw Error('SignalR is not configured, see @equinor/fusion-framework-react-module-signalr');
37
+ }
38
+ return useProviderTopic(provider, hubId, topicId);
38
39
  };
@@ -13,15 +13,15 @@ import { context } from './context';
13
13
  * ```
14
14
  */
15
15
  export const useFramework = <TModules extends Array<AnyModule> = []>(): Fusion<TModules> => {
16
- let framework = useContext(context);
17
- if (!framework) {
18
- console.warn('could not locate fusion in context!');
19
- }
20
- framework ??= window.Fusion;
21
- if (!framework) {
22
- console.error('Could not load framework, might not be initiated?');
23
- }
24
- return framework;
16
+ let framework = useContext(context);
17
+ if (!framework) {
18
+ console.warn('could not locate fusion in context!');
19
+ }
20
+ framework ??= window.Fusion;
21
+ if (!framework) {
22
+ console.error('Could not load framework, might not be initiated?');
23
+ }
24
+ return framework;
25
25
  };
26
26
 
27
27
  export default useFramework;
@@ -1,6 +1,11 @@
1
1
  import type { FusionModules, FusionModulesInstance } from '@equinor/fusion-framework';
2
2
  import { useFramework } from './useFramework';
3
- import { AnyModule, ModuleKey, ModuleType, ModuleTypes } from '@equinor/fusion-framework-module';
3
+ import type {
4
+ AnyModule,
5
+ ModuleKey,
6
+ ModuleType,
7
+ ModuleTypes,
8
+ } from '@equinor/fusion-framework-module';
4
9
 
5
10
  /**
6
11
  * Retrieves a module from the framework instance based on its name.
@@ -12,20 +17,20 @@ import { AnyModule, ModuleKey, ModuleType, ModuleTypes } from '@equinor/fusion-f
12
17
  * @throws Error if the requested module is not included in the framework instance.
13
18
  */
14
19
  export const useFrameworkModule = <
15
- TType extends AnyModule | unknown = unknown,
16
- TKey extends string = ModuleKey<ModuleTypes<FusionModules<[TType]>>>,
20
+ TType extends AnyModule | unknown = unknown,
21
+ TKey extends string = ModuleKey<ModuleTypes<FusionModules<[TType]>>>,
17
22
  >(
18
- name: TKey,
23
+ name: TKey,
19
24
  ): TType extends AnyModule
20
- ? ModuleType<TType> | undefined
21
- : FusionModulesInstance[Extract<keyof FusionModulesInstance, TKey>] | undefined => {
22
- const framework = useFramework();
23
- // TODO
24
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
25
- // @ts-ignore
26
- const module = framework.modules[name];
27
- if (!module) {
28
- console.warn(`the requested module [${module}] is not included in the framework instance`);
29
- }
30
- return module;
25
+ ? ModuleType<TType> | undefined
26
+ : FusionModulesInstance[Extract<keyof FusionModulesInstance, TKey>] | undefined => {
27
+ const framework = useFramework();
28
+ // TODO
29
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
30
+ // @ts-ignore
31
+ const module = framework.modules[name];
32
+ if (!module) {
33
+ console.warn(`the requested module [${module}] is not included in the framework instance`);
34
+ }
35
+ return module;
31
36
  };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '7.4.0';
2
+ export const version = '7.4.2';