@equinor/fusion-framework-react 8.0.0-next.0 → 8.0.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/CHANGELOG.md +60 -12
- package/README.md +164 -31
- package/dist/esm/Framework.js +32 -0
- package/dist/esm/Framework.js.map +1 -1
- package/dist/esm/app/index.js.map +1 -1
- package/dist/esm/app/useAppProvider.js +12 -2
- package/dist/esm/app/useAppProvider.js.map +1 -1
- package/dist/esm/app/useApps.js +17 -3
- package/dist/esm/app/useApps.js.map +1 -1
- package/dist/esm/app/useCurrentApp.js +26 -4
- package/dist/esm/app/useCurrentApp.js.map +1 -1
- package/dist/esm/app/useCurrentAppModule.js +26 -13
- package/dist/esm/app/useCurrentAppModule.js.map +1 -1
- package/dist/esm/app/useCurrentAppModules.js +14 -4
- package/dist/esm/app/useCurrentAppModules.js.map +1 -1
- package/dist/esm/context/index.js +10 -0
- package/dist/esm/context/index.js.map +1 -1
- package/dist/esm/context/useCurrentContext.js +16 -0
- package/dist/esm/context/useCurrentContext.js.map +1 -1
- package/dist/esm/context.js +6 -16
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/create-framework-provider.js +30 -9
- package/dist/esm/create-framework-provider.js.map +1 -1
- package/dist/esm/feature-flag/index.js +10 -0
- package/dist/esm/feature-flag/index.js.map +1 -1
- package/dist/esm/feature-flag/useCurrentAppFeatures.js +12 -2
- package/dist/esm/feature-flag/useCurrentAppFeatures.js.map +1 -1
- package/dist/esm/feature-flag/useFeature.js +16 -6
- package/dist/esm/feature-flag/useFeature.js.map +1 -1
- package/dist/esm/feature-flag/useFeatures.js +24 -6
- package/dist/esm/feature-flag/useFeatures.js.map +1 -1
- package/dist/esm/feature-flag/useFrameworkFeature.js +13 -5
- package/dist/esm/feature-flag/useFrameworkFeature.js.map +1 -1
- package/dist/esm/feature-flag/useFrameworkFeatures.js +12 -4
- package/dist/esm/feature-flag/useFrameworkFeatures.js.map +1 -1
- package/dist/esm/framework-provider.js +21 -0
- package/dist/esm/framework-provider.js.map +1 -0
- package/dist/esm/hooks/index.js +10 -2
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useCurrentUser.js +20 -0
- package/dist/esm/hooks/useCurrentUser.js.map +1 -0
- package/dist/esm/hooks/useHttpClient.js +28 -0
- package/dist/esm/hooks/useHttpClient.js.map +1 -0
- package/dist/esm/http/index.js +11 -1
- package/dist/esm/http/index.js.map +1 -1
- package/dist/esm/index.js +9 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/signalr/index.js +1 -31
- package/dist/esm/signalr/index.js.map +1 -1
- package/dist/esm/signalr/useSignalR.js +33 -0
- package/dist/esm/signalr/useSignalR.js.map +1 -0
- package/dist/esm/useFramework.js +18 -4
- package/dist/esm/useFramework.js.map +1 -1
- package/dist/esm/useFrameworkModule.js +16 -8
- package/dist/esm/useFrameworkModule.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Framework.d.ts +38 -1
- package/dist/types/app/index.d.ts +10 -0
- package/dist/types/app/useAppProvider.d.ts +12 -3
- package/dist/types/app/useApps.d.ts +17 -3
- package/dist/types/app/useCurrentApp.d.ts +25 -4
- package/dist/types/app/useCurrentAppModule.d.ts +13 -7
- package/dist/types/app/useCurrentAppModules.d.ts +14 -4
- package/dist/types/context/index.d.ts +10 -0
- package/dist/types/context/useCurrentContext.d.ts +16 -0
- package/dist/types/context.d.ts +1 -21
- package/dist/types/create-framework-provider.d.ts +29 -8
- package/dist/types/feature-flag/index.d.ts +10 -0
- package/dist/types/feature-flag/useCurrentAppFeatures.d.ts +12 -2
- package/dist/types/feature-flag/useFeature.d.ts +23 -6
- package/dist/types/feature-flag/useFeatures.d.ts +23 -6
- package/dist/types/feature-flag/useFrameworkFeature.d.ts +12 -5
- package/dist/types/feature-flag/useFrameworkFeatures.d.ts +11 -4
- package/dist/types/framework-provider.d.ts +19 -0
- package/dist/types/hooks/index.d.ts +10 -2
- package/dist/types/hooks/useCurrentUser.d.ts +16 -0
- package/dist/types/hooks/useHttpClient.d.ts +20 -0
- package/dist/types/http/index.d.ts +11 -1
- package/dist/types/index.d.ts +9 -1
- package/dist/types/signalr/index.d.ts +1 -24
- package/dist/types/signalr/useSignalR.d.ts +24 -0
- package/dist/types/useFramework.d.ts +16 -4
- package/dist/types/useFrameworkModule.d.ts +13 -6
- package/dist/types/version.d.ts +1 -1
- package/package.json +15 -14
- package/src/Framework.tsx +37 -0
- package/src/app/index.ts +10 -0
- package/src/app/useAppProvider.ts +12 -2
- package/src/app/useApps.ts +17 -3
- package/src/app/useCurrentApp.ts +26 -4
- package/src/app/useCurrentAppModule.ts +26 -14
- package/src/app/useCurrentAppModules.ts +14 -4
- package/src/context/index.ts +10 -0
- package/src/context/useCurrentContext.ts +16 -0
- package/src/context.ts +6 -17
- package/src/create-framework-provider.tsx +31 -10
- package/src/feature-flag/index.ts +10 -0
- package/src/feature-flag/useCurrentAppFeatures.ts +12 -2
- package/src/feature-flag/useFeature.ts +31 -7
- package/src/feature-flag/useFeatures.ts +33 -7
- package/src/feature-flag/useFrameworkFeature.ts +13 -5
- package/src/feature-flag/useFrameworkFeatures.ts +12 -4
- package/src/framework-provider.ts +21 -0
- package/src/hooks/index.ts +10 -2
- package/src/hooks/useCurrentUser.ts +21 -0
- package/src/hooks/useHttpClient.ts +36 -0
- package/src/http/index.ts +11 -1
- package/src/index.tsx +9 -1
- package/src/signalr/index.ts +1 -39
- package/src/signalr/useSignalR.ts +40 -0
- package/src/useFramework.ts +18 -4
- package/src/useFrameworkModule.ts +16 -8
- package/src/version.ts +1 -1
- package/dist/esm/hooks/use-current-user.js +0 -6
- package/dist/esm/hooks/use-current-user.js.map +0 -1
- package/dist/esm/hooks/use-http-client.js +0 -14
- package/dist/esm/hooks/use-http-client.js.map +0 -1
- package/dist/types/hooks/use-current-user.d.ts +0 -2
- package/dist/types/hooks/use-http-client.d.ts +0 -5
- package/src/hooks/use-current-user.ts +0 -7
- package/src/hooks/use-http-client.ts +0 -19
|
@@ -12,23 +12,40 @@ import type { FeatureSelectorFn } from '@equinor/fusion-framework-module-feature
|
|
|
12
12
|
|
|
13
13
|
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Return type of the {@link useFeatures} hook.
|
|
17
|
+
*/
|
|
15
18
|
export interface UseFeaturesResult {
|
|
19
|
+
/** Array of all resolved feature flags. */
|
|
16
20
|
features: IFeatureFlag[];
|
|
21
|
+
/** Any error emitted by the feature-flag observable. */
|
|
17
22
|
error: unknown;
|
|
18
23
|
/**
|
|
24
|
+
* Toggles a feature flag by key.
|
|
25
|
+
*
|
|
19
26
|
* @param key - The key of the feature flag.
|
|
20
|
-
* @param enable -
|
|
27
|
+
* @param enable - Explicit enabled state. When omitted the current state
|
|
28
|
+
* is inverted.
|
|
21
29
|
*/
|
|
22
30
|
toggleFeature: (key: string, enable?: boolean) => void;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
/**
|
|
26
|
-
*
|
|
34
|
+
* React hook that returns all feature flags from a provider, with optional
|
|
35
|
+
* filtering.
|
|
36
|
+
*
|
|
37
|
+
* @param provider - The feature-flag provider instance, or `null`/`undefined`
|
|
38
|
+
* when not yet available.
|
|
39
|
+
* @param selector - Optional predicate to filter the feature flags.
|
|
40
|
+
* @returns A {@link UseFeaturesResult} with the flags, a toggle helper,
|
|
41
|
+
* and any error.
|
|
42
|
+
* @throws {Error} If `toggleFeature` is called when the provider is missing.
|
|
27
43
|
*
|
|
28
|
-
* @
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const { features, toggleFeature } = useFeatures(provider);
|
|
47
|
+
* toggleFeature('beta', true);
|
|
48
|
+
* ```
|
|
32
49
|
*/
|
|
33
50
|
export const useFeatures = (
|
|
34
51
|
provider?: IFeatureFlagProvider | null,
|
|
@@ -41,11 +58,19 @@ export const useFeatures = (
|
|
|
41
58
|
*/
|
|
42
59
|
const { value: features, error } = useObservableState(
|
|
43
60
|
useMemo(() => {
|
|
61
|
+
// Only compute the feature list when a provider is available; otherwise there's nothing to observe
|
|
44
62
|
if (provider) {
|
|
63
|
+
// Map the feature dictionary to a list, optionally narrowed by the caller-provided selector
|
|
45
64
|
return provider?.features$.pipe(
|
|
46
65
|
map((x) => {
|
|
47
66
|
const values = Object.values(x);
|
|
48
|
-
|
|
67
|
+
// Return everything when no selector is provided
|
|
68
|
+
if (!selector) {
|
|
69
|
+
return values;
|
|
70
|
+
}
|
|
71
|
+
// Apply the caller-provided selector to narrow down the feature list
|
|
72
|
+
const filtered = values.filter(selector);
|
|
73
|
+
return filtered;
|
|
49
74
|
}),
|
|
50
75
|
);
|
|
51
76
|
}
|
|
@@ -62,6 +87,7 @@ export const useFeatures = (
|
|
|
62
87
|
*/
|
|
63
88
|
const toggleFeature = useCallback(
|
|
64
89
|
(key: string, enable?: boolean) => {
|
|
90
|
+
// Cannot toggle a feature without a provider to persist the change
|
|
65
91
|
if (!provider) {
|
|
66
92
|
throw new Error('Missing IFeatureFlagProvider.');
|
|
67
93
|
}
|
|
@@ -4,15 +4,23 @@ import { useFrameworkModule } from '../useFrameworkModule';
|
|
|
4
4
|
import { useFeature } from './useFeature';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* React hook that retrieves a single feature flag from the **framework-level**
|
|
8
|
+
* feature-flag provider.
|
|
8
9
|
*
|
|
9
|
-
* @template T -
|
|
10
|
-
* @param
|
|
11
|
-
* @returns {
|
|
12
|
-
*
|
|
10
|
+
* @template T - Value type carried by the feature flag.
|
|
11
|
+
* @param key - Unique key identifying the feature flag.
|
|
12
|
+
* @returns A {@link UseFeatureResult} with the flag value, toggle helper,
|
|
13
|
+
* and any error.
|
|
14
|
+
* @throws {Error} If the `FeatureFlagModule` is not enabled in the framework.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const { feature, toggleFeature } = useFrameworkFeature('experimental-ui');
|
|
19
|
+
* ```
|
|
13
20
|
*/
|
|
14
21
|
export const useFrameworkFeature = <T>(key: string): ReturnType<typeof useFeature<T>> => {
|
|
15
22
|
const provider = useFrameworkModule<FeatureFlagModule>('featureFlag');
|
|
23
|
+
// Fail fast when the FeatureFlagModule has not been enabled on the framework
|
|
16
24
|
if (!provider) {
|
|
17
25
|
throw Error('Feature flagging is not enabled in the framework');
|
|
18
26
|
}
|
|
@@ -4,13 +4,21 @@ import { useFrameworkModule } from '../useFrameworkModule';
|
|
|
4
4
|
import { useFeatures } from './useFeatures';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
7
|
+
* React hook that returns all feature flags from the **framework-level**
|
|
8
|
+
* feature-flag provider.
|
|
9
|
+
*
|
|
10
|
+
* @returns A {@link UseFeaturesResult} containing all framework feature flags,
|
|
11
|
+
* a toggle helper, and any error.
|
|
12
|
+
* @throws {Error} If the `FeatureFlagModule` is not enabled in the framework.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const { features, toggleFeature } = useFrameworkFeatures();
|
|
17
|
+
* ```
|
|
11
18
|
*/
|
|
12
19
|
export const useFrameworkFeatures = (): ReturnType<typeof useFeatures> => {
|
|
13
20
|
const provider = useFrameworkModule<FeatureFlagModule>('featureFlag');
|
|
21
|
+
// Fail fast when the FeatureFlagModule has not been enabled on the framework
|
|
14
22
|
if (!provider) {
|
|
15
23
|
throw Error('Feature flagging is not enabled in the framework');
|
|
16
24
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { context } from './context';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Component for providing framework.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Should be created by {@link createFrameworkProvider}
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import {FrameworkProvider} from '@equinor/fusion-framework-react';
|
|
12
|
+
* export const Component = (args: React.PropsWithChildren<{framework: Fusion}>) => {
|
|
13
|
+
* return (
|
|
14
|
+
* <FrameworkProvider value={args.framework}>
|
|
15
|
+
* {args.children}
|
|
16
|
+
* </FrameworkProvider>
|
|
17
|
+
* );
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const FrameworkProvider = context.Provider;
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Convenience hooks for common framework operations.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Available via the `@equinor/fusion-framework-react/hooks` sub-entry-point.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export { useCurrentUser } from './useCurrentUser';
|
|
10
|
+
export { useHttpClient } from './useHttpClient';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AccountInfo } from '@equinor/fusion-framework-module-msal';
|
|
2
|
+
import { useFramework } from '../useFramework';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* React hook that returns the currently authenticated user's account info.
|
|
6
|
+
*
|
|
7
|
+
* @returns The {@link AccountInfo} of the signed-in user, or `undefined` if
|
|
8
|
+
* no user is authenticated.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const UserGreeting = () => {
|
|
13
|
+
* const user = useCurrentUser();
|
|
14
|
+
* return <span>Hello, {user?.name ?? 'Guest'}</span>;
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const useCurrentUser = (): AccountInfo | undefined => {
|
|
19
|
+
const framework = useFramework();
|
|
20
|
+
return framework.modules.auth.account || undefined;
|
|
21
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { Fusion } from '@equinor/fusion-framework';
|
|
3
|
+
import { useFramework } from '../useFramework';
|
|
4
|
+
|
|
5
|
+
/** Resolved HTTP client instance returned by the framework HTTP module. */
|
|
6
|
+
type HttpClient = ReturnType<Fusion['modules']['http']['createClient']>;
|
|
7
|
+
|
|
8
|
+
/** Well-known HTTP client keys pre-configured by the framework. */
|
|
9
|
+
type FrameworkHttpClient = 'portal' | 'people';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* React hook that returns a pre-configured HTTP client from the framework.
|
|
13
|
+
*
|
|
14
|
+
* @param name - Key of the HTTP client to retrieve (e.g. `'portal'` or `'people'`).
|
|
15
|
+
* @returns The resolved {@link HttpClient} instance.
|
|
16
|
+
* @throws {Error} If no client is configured for the given key.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const client = useHttpClient('portal');
|
|
21
|
+
* client.fetch('/api/data').subscribe(console.log);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export const useHttpClient = (name: FrameworkHttpClient): HttpClient => {
|
|
25
|
+
const framework = useFramework();
|
|
26
|
+
|
|
27
|
+
const client = useMemo(() => {
|
|
28
|
+
// Reuse an already-configured client for this key when one exists
|
|
29
|
+
if (framework.modules.http.hasClient(name)) {
|
|
30
|
+
return framework.modules.http.createClient(name);
|
|
31
|
+
}
|
|
32
|
+
throw Error(`no configured client for key [${name}]`);
|
|
33
|
+
}, [framework, name]);
|
|
34
|
+
// TODO(#5085): abort on unmount?
|
|
35
|
+
return client;
|
|
36
|
+
};
|
package/src/http/index.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* HTTP sub-entry-point (`@equinor/fusion-framework-react/http`).
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Re-exports the framework-level {@link useHttpClient} hook as
|
|
6
|
+
* `useFrameworkHttpClient` together with all exports from the
|
|
7
|
+
* standalone HTTP React module.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
export { useHttpClient as useFrameworkHttpClient } from '../hooks/useHttpClient';
|
|
2
12
|
|
|
3
13
|
export * from '@equinor/fusion-framework-react-module-http';
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* React bindings for the Fusion Framework.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This package provides React components, context providers, and hooks for
|
|
6
|
+
* initialising and consuming a Fusion Framework instance inside a React
|
|
7
|
+
* application tree. It is the main entry-point for portals and host
|
|
8
|
+
* applications that need to bootstrap the framework with React.
|
|
9
|
+
*
|
|
2
10
|
* [[include:framework-react/README.MD]]
|
|
3
11
|
* @module
|
|
4
12
|
*/
|
|
@@ -7,7 +15,7 @@ export type { Fusion } from '@equinor/fusion-framework';
|
|
|
7
15
|
export { FusionConfigurator } from '@equinor/fusion-framework';
|
|
8
16
|
|
|
9
17
|
export { createFrameworkProvider } from './create-framework-provider';
|
|
10
|
-
export { FrameworkProvider } from './
|
|
18
|
+
export { FrameworkProvider } from './framework-provider';
|
|
11
19
|
|
|
12
20
|
export { useFramework } from './useFramework';
|
|
13
21
|
export { useFrameworkModule } from './useFrameworkModule';
|
package/src/signalr/index.ts
CHANGED
|
@@ -1,39 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type SignalRModule,
|
|
5
|
-
useProviderTopic,
|
|
6
|
-
} from '@equinor/fusion-framework-react-module-signalr';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* hook for subscribing to a topic of a SignalR hub
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
```ts
|
|
13
|
-
// config.ts
|
|
14
|
-
import {enableSignalR} from '@equinor/fusion-framework-react-module-signalr';
|
|
15
|
-
(configurator) => enableSignalR(configurator, 'notifications');
|
|
16
|
-
|
|
17
|
-
// myHook.ts
|
|
18
|
-
const myHook = () => {
|
|
19
|
-
const topic = useSignalR('notifications', 'foo');
|
|
20
|
-
return useObservableState(topic).next;
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
*
|
|
24
|
-
* @see {@link [module signalr](https://equinor.github.io/fusion-framework/modules/signalr)}
|
|
25
|
-
*
|
|
26
|
-
* @param hubId identifier of connection hub (must be configured)
|
|
27
|
-
* @param topicId identifier of topic to connect to
|
|
28
|
-
* @returns Topic
|
|
29
|
-
*/
|
|
30
|
-
export const useSignalR = <T>(
|
|
31
|
-
hubId: string,
|
|
32
|
-
topicId: string,
|
|
33
|
-
): ReturnType<typeof useProviderTopic<T>> => {
|
|
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);
|
|
39
|
-
};
|
|
1
|
+
export { useSignalR } from './useSignalR.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useFramework } from '../useFramework';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type SignalRModule,
|
|
5
|
+
useProviderTopic,
|
|
6
|
+
} from '@equinor/fusion-framework-react-module-signalr';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* hook for subscribing to a topic of a SignalR hub
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
```ts
|
|
13
|
+
// config.ts
|
|
14
|
+
import {enableSignalR} from '@equinor/fusion-framework-react-module-signalr';
|
|
15
|
+
(configurator) => enableSignalR(configurator, 'notifications');
|
|
16
|
+
|
|
17
|
+
// myHook.ts
|
|
18
|
+
const myHook = () => {
|
|
19
|
+
const topic = useSignalR('notifications', 'foo');
|
|
20
|
+
return useObservableState(topic).next;
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
*
|
|
24
|
+
* @see {@link [module signalr](https://equinor.github.io/fusion-framework/modules/signalr)}
|
|
25
|
+
*
|
|
26
|
+
* @param hubId identifier of connection hub (must be configured)
|
|
27
|
+
* @param topicId identifier of topic to connect to
|
|
28
|
+
* @returns Topic
|
|
29
|
+
*/
|
|
30
|
+
export const useSignalR = <T>(
|
|
31
|
+
hubId: string,
|
|
32
|
+
topicId: string,
|
|
33
|
+
): ReturnType<typeof useProviderTopic<T>> => {
|
|
34
|
+
const provider = useFramework<[SignalRModule]>().modules.signalR;
|
|
35
|
+
// Fail fast when the SignalRModule has not been configured on the framework
|
|
36
|
+
if (!provider) {
|
|
37
|
+
throw Error('SignalR is not configured, see @equinor/fusion-framework-react-module-signalr');
|
|
38
|
+
}
|
|
39
|
+
return useProviderTopic(provider, hubId, topicId);
|
|
40
|
+
};
|
package/src/useFramework.ts
CHANGED
|
@@ -4,20 +4,34 @@ import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
|
4
4
|
import { useContext } from 'react';
|
|
5
5
|
import { context } from './context';
|
|
6
6
|
/**
|
|
7
|
+
* React hook that returns the current Fusion Framework instance from context.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* The hook first looks for a framework instance provided via
|
|
11
|
+
* {@link FrameworkProvider}. If none is found it falls back to the global
|
|
12
|
+
* `window.Fusion` object. A console warning / error is emitted when the
|
|
13
|
+
* framework cannot be resolved.
|
|
14
|
+
*
|
|
15
|
+
* @template TModules - Tuple of additional module types expected on the
|
|
16
|
+
* framework instance (used for type-narrowing only).
|
|
17
|
+
* @returns The active {@link Fusion} instance.
|
|
18
|
+
*
|
|
7
19
|
* @example
|
|
8
20
|
* ```ts
|
|
9
|
-
* const
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* }
|
|
21
|
+
* const useMyService = () => {
|
|
22
|
+
* const fusion = useFramework();
|
|
23
|
+
* return fusion.modules.http.createClient('my-service');
|
|
24
|
+
* };
|
|
13
25
|
* ```
|
|
14
26
|
*/
|
|
15
27
|
export const useFramework = <TModules extends Array<AnyModule> = []>(): Fusion<TModules> => {
|
|
16
28
|
let framework = useContext(context);
|
|
29
|
+
// Warn loudly when the framework context is missing so integrators notice the misuse
|
|
17
30
|
if (!framework) {
|
|
18
31
|
console.warn('could not locate fusion in context!');
|
|
19
32
|
}
|
|
20
33
|
framework ??= window.Fusion;
|
|
34
|
+
// Surface an error when neither context nor the global fallback has the framework instance
|
|
21
35
|
if (!framework) {
|
|
22
36
|
console.error('Could not load framework, might not be initiated?');
|
|
23
37
|
}
|
|
@@ -8,13 +8,20 @@ import type {
|
|
|
8
8
|
} from '@equinor/fusion-framework-module';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* React hook that retrieves a module from the Fusion Framework by name.
|
|
12
12
|
*
|
|
13
|
-
* @template TType - The
|
|
14
|
-
* @template TKey - The
|
|
15
|
-
* @param name - The name of the module to retrieve.
|
|
16
|
-
* @returns The
|
|
17
|
-
*
|
|
13
|
+
* @template TType - The expected module type (used for type-narrowing).
|
|
14
|
+
* @template TKey - The module key string.
|
|
15
|
+
* @param name - The registered name of the module to retrieve.
|
|
16
|
+
* @returns The resolved module instance, or `undefined` if the module is
|
|
17
|
+
* not registered.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import type { HttpModule } from '@equinor/fusion-framework-module-http';
|
|
22
|
+
*
|
|
23
|
+
* const http = useFrameworkModule<HttpModule>('http');
|
|
24
|
+
* ```
|
|
18
25
|
*/
|
|
19
26
|
export const useFrameworkModule = <
|
|
20
27
|
TType extends AnyModule | unknown = unknown,
|
|
@@ -25,10 +32,11 @@ export const useFrameworkModule = <
|
|
|
25
32
|
? ModuleType<TType> | undefined
|
|
26
33
|
: FusionModulesInstance[Extract<keyof FusionModulesInstance, TKey>] | undefined => {
|
|
27
34
|
const framework = useFramework();
|
|
28
|
-
// TODO
|
|
35
|
+
// TODO(#5082): tighten generics so this indexed lookup no longer needs @ts-expect-error
|
|
29
36
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
-
// @ts-
|
|
37
|
+
// @ts-expect-error
|
|
31
38
|
const module = framework.modules[name];
|
|
39
|
+
// Warn when the requested module key does not resolve to a registered module
|
|
32
40
|
if (!module) {
|
|
33
41
|
console.warn(`the requested module [${module}] is not included in the framework instance`);
|
|
34
42
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '8.0.
|
|
2
|
+
export const version = '8.0.1';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-current-user.js","sourceRoot":"","sources":["../../../src/hooks/use-current-user.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,CAAC,MAAM,cAAc,GAAG,GAA4B,EAAE;IAC1D,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,OAAO,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,SAAS,CAAC;AACrD,CAAC,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { useFramework } from '../useFramework';
|
|
3
|
-
export const useHttpClient = (name) => {
|
|
4
|
-
const framework = useFramework();
|
|
5
|
-
const client = useMemo(() => {
|
|
6
|
-
if (framework.modules.http.hasClient(name)) {
|
|
7
|
-
return framework.modules.http.createClient(name);
|
|
8
|
-
}
|
|
9
|
-
throw Error(`no configured client for key [${name}]`);
|
|
10
|
-
}, [framework, name]);
|
|
11
|
-
// TODO - abort on unmount?
|
|
12
|
-
return client;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=use-http-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-http-client.js","sourceRoot":"","sources":["../../../src/hooks/use-http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAK/C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAyB,EAAc,EAAE;IACrE,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IAEjC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE;QAC1B,IAAI,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3C,OAAO,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACnD,CAAC;QACD,MAAM,KAAK,CAAC,iCAAiC,IAAI,GAAG,CAAC,CAAC;IACxD,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IACtB,2BAA2B;IAC3B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Fusion } from '@equinor/fusion-framework';
|
|
2
|
-
type HttpClient = ReturnType<Fusion['modules']['http']['createClient']>;
|
|
3
|
-
type FrameworkHttpClient = 'portal' | 'people';
|
|
4
|
-
export declare const useHttpClient: (name: FrameworkHttpClient) => HttpClient;
|
|
5
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { AccountInfo } from '@equinor/fusion-framework-module-msal';
|
|
2
|
-
import { useFramework } from '../useFramework';
|
|
3
|
-
|
|
4
|
-
export const useCurrentUser = (): AccountInfo | undefined => {
|
|
5
|
-
const framework = useFramework();
|
|
6
|
-
return framework.modules.auth.account || undefined;
|
|
7
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import type { Fusion } from '@equinor/fusion-framework';
|
|
3
|
-
import { useFramework } from '../useFramework';
|
|
4
|
-
|
|
5
|
-
type HttpClient = ReturnType<Fusion['modules']['http']['createClient']>;
|
|
6
|
-
type FrameworkHttpClient = 'portal' | 'people';
|
|
7
|
-
|
|
8
|
-
export const useHttpClient = (name: FrameworkHttpClient): HttpClient => {
|
|
9
|
-
const framework = useFramework();
|
|
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;
|
|
19
|
-
};
|