@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/bookmark/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bookmark sub-path entry-point.
|
|
3
|
-
*
|
|
4
|
-
* Provides helpers to enable and consume the Fusion bookmark module,
|
|
5
|
-
* allowing users to save and restore application state snapshots.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
export { enableBookmark } from '@equinor/fusion-framework-app/enable-bookmark';
|
|
10
|
-
|
|
11
|
-
export { useCurrentBookmark } from './useCurrentBookmark';
|
|
12
|
-
export { useBookmark } from './useBookmark';
|
|
13
|
-
|
|
14
|
-
export type {
|
|
15
|
-
Bookmark,
|
|
16
|
-
Bookmarks,
|
|
17
|
-
BookmarkData,
|
|
18
|
-
BookmarkPayloadGenerator,
|
|
19
|
-
BookmarkProvider,
|
|
20
|
-
} from '@equinor/fusion-framework-react-module-bookmark';
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useBookmark as _useBookmark,
|
|
3
|
-
type useBookmarkResult,
|
|
4
|
-
} from '@equinor/fusion-framework-react-module-bookmark';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Use useBookmark from @equinor/fusion-framework-react-module-bookmark
|
|
8
|
-
* For application development the useCurrentBookmark should be sufficient enough
|
|
9
|
-
*
|
|
10
|
-
* Functionality provided here is:
|
|
11
|
-
* - addBookmarkCreator
|
|
12
|
-
* - getAllBookmarks
|
|
13
|
-
* - createBookmark
|
|
14
|
-
* - updateBookmark
|
|
15
|
-
* - deleteBookmarkById
|
|
16
|
-
* - setCurrentBookmark
|
|
17
|
-
* - currentBookmark
|
|
18
|
-
* - bookmarks,
|
|
19
|
-
*
|
|
20
|
-
* @template TData - Current applications bookmark type
|
|
21
|
-
* @return {*} {Bookmarks<TData>} the full api fro handling bookmarks
|
|
22
|
-
*/
|
|
23
|
-
export const useBookmark = <_TData>(): useBookmarkResult => _useBookmark();
|
|
24
|
-
|
|
25
|
-
export default useBookmark;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type BookmarkData,
|
|
3
|
-
type BookmarkPayloadGenerator,
|
|
4
|
-
type useCurrentBookmarkReturn,
|
|
5
|
-
useCurrentBookmark as _useCurrentBookmark,
|
|
6
|
-
type BookmarkModule,
|
|
7
|
-
bookmarkWithDataSchema,
|
|
8
|
-
} from '@equinor/fusion-framework-react-module-bookmark';
|
|
9
|
-
|
|
10
|
-
import { useFrameworkModule } from '@equinor/fusion-framework-react';
|
|
11
|
-
import useAppModules from '../useAppModules';
|
|
12
|
-
import { useCurrentApp } from '@equinor/fusion-framework-react/app';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* By providing a CreateBookMarkFn bookmarks is enabled for the current application.
|
|
16
|
-
*
|
|
17
|
-
* @template TData - Type of data stored in bookmark
|
|
18
|
-
* @param {CreateBookMarkFn<TData>} [createBookmarkState] - Function for creating bookmark payload, this function should be wrapped in useCallback
|
|
19
|
-
*
|
|
20
|
-
* ```TS
|
|
21
|
-
* // Example
|
|
22
|
-
* const { currentBookmark } = useCurrentBookmark(useCallback(()=> someState, [someState]))
|
|
23
|
-
* ```
|
|
24
|
-
* @return {*} {CurrentBookmark<TData>}
|
|
25
|
-
*/
|
|
26
|
-
export const useCurrentBookmark = <TData extends BookmarkData>(
|
|
27
|
-
payloadGenerator?: BookmarkPayloadGenerator<TData>,
|
|
28
|
-
): useCurrentBookmarkReturn<TData> => {
|
|
29
|
-
const { currentApp } = useCurrentApp();
|
|
30
|
-
const appBookmarkProvider = useAppModules<[BookmarkModule]>().bookmark;
|
|
31
|
-
const frameworkBookmarkProvider = useFrameworkModule<BookmarkModule>('bookmark');
|
|
32
|
-
// Warn about the deprecated fallback to the framework-scoped bookmark provider
|
|
33
|
-
if (!appBookmarkProvider) {
|
|
34
|
-
console.warn(
|
|
35
|
-
'@deprecation',
|
|
36
|
-
'application has not enabled bookmarks, this will not work in the future',
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
const { currentBookmark, setCurrentBookmark } = _useCurrentBookmark<TData>({
|
|
40
|
-
provider: appBookmarkProvider ?? frameworkBookmarkProvider,
|
|
41
|
-
payloadGenerator,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const currentBookmarkAppKey = bookmarkWithDataSchema().safeParse(currentBookmark).success
|
|
45
|
-
? bookmarkWithDataSchema().parse(currentBookmark).appKey
|
|
46
|
-
: null;
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
currentBookmark: currentBookmarkAppKey === currentApp?.appKey ? currentBookmark : null,
|
|
50
|
-
setCurrentBookmark,
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export default useCurrentBookmark;
|
package/src/context/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context sub-path entry-point.
|
|
3
|
-
*
|
|
4
|
-
* Provides hooks for reading and interacting with the Fusion context
|
|
5
|
-
* (project, facility, etc.) at both the application and framework level.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
export * from '@equinor/fusion-framework-react-module-context';
|
|
10
|
-
|
|
11
|
-
export { useContextProvider } from './useContextProvider';
|
|
12
|
-
export { useCurrentContext } from './useCurrentContext';
|
|
13
|
-
|
|
14
|
-
export { useFrameworkCurrentContext } from '../framework/useFrameworkCurrentContext';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ContextModule } from '@equinor/fusion-framework-react-module-context';
|
|
2
|
-
import { useAppModule } from '../useAppModule';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* React hook that resolves the application-scoped context module provider.
|
|
6
|
-
*
|
|
7
|
-
* @returns The context module provider instance.
|
|
8
|
-
* @throws If the context module is not registered in the application scope.
|
|
9
|
-
*/
|
|
10
|
-
export const useContextProvider = () => useAppModule<ContextModule>('context');
|
|
11
|
-
|
|
12
|
-
export default useContextProvider;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useCurrentContext as _useCurrentContext } from '@equinor/fusion-framework-react-module-context';
|
|
2
|
-
import useContextProvider from './useContextProvider';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* React hook that returns the currently selected Fusion context from the
|
|
6
|
-
* **application-scoped** context module.
|
|
7
|
-
*
|
|
8
|
-
* @returns The current context object, or `undefined` if no context is selected.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const context = useCurrentContext();
|
|
13
|
-
* if (context) {
|
|
14
|
-
* console.log('Selected:', context.title);
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export const useCurrentContext = () => _useCurrentContext(useContextProvider());
|
|
19
|
-
|
|
20
|
-
export default useCurrentContext;
|
package/src/create-component.tsx
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
import { lazy } from 'react';
|
|
3
|
-
|
|
4
|
-
import { FrameworkProvider } from '@equinor/fusion-framework-react';
|
|
5
|
-
import type { Fusion } from '@equinor/fusion-framework-react';
|
|
6
|
-
|
|
7
|
-
import { type AppEnv, configureModules } from '@equinor/fusion-framework-app';
|
|
8
|
-
import type { AppModuleInitiator, AppModulesInstance } from '@equinor/fusion-framework-app';
|
|
9
|
-
|
|
10
|
-
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
11
|
-
|
|
12
|
-
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
13
|
-
|
|
14
|
-
import { ModuleProvider as AppModuleProvider } from '@equinor/fusion-framework-react-module';
|
|
15
|
-
|
|
16
|
-
export type ComponentRenderArgs<TFusion extends Fusion = Fusion, TEnv = AppEnv> = {
|
|
17
|
-
fusion: TFusion;
|
|
18
|
-
env: TEnv;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type ComponentRenderer<TFusion extends Fusion = Fusion, TEnv = AppEnv> = (
|
|
22
|
-
fusion: TFusion,
|
|
23
|
-
env: TEnv,
|
|
24
|
-
) => React.LazyExoticComponent<React.ComponentType>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated
|
|
28
|
-
* Creates an lazy loading Component which configures modules
|
|
29
|
-
* and provides context to framework and configured modules
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* ```mermaid
|
|
33
|
-
* sequenceDiagram
|
|
34
|
-
* App ->>+Framework: createApp
|
|
35
|
-
* Framework->>-Framework: initializeModules
|
|
36
|
-
* Framework->>App: configure(modules, framework, args)
|
|
37
|
-
* App-->Framework: await configuration
|
|
38
|
-
* Framework->>App: React.LazyExoticComponent
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```tsx
|
|
43
|
-
* const configCallback: AppConfigurator = (configurator) => {
|
|
44
|
-
* configurator.http.configureClient(
|
|
45
|
-
* 'bar', {
|
|
46
|
-
* baseUri: 'https://somewhere-test.com',
|
|
47
|
-
* defaultScopes: ['foo/.default']
|
|
48
|
-
* }
|
|
49
|
-
* );
|
|
50
|
-
* };
|
|
51
|
-
*
|
|
52
|
-
* export const App = () => {
|
|
53
|
-
* const client = useHttpClient('bar');
|
|
54
|
-
* const [foo, setFoo] = useState('no value');
|
|
55
|
-
* const onClick = useCallback(() => {
|
|
56
|
-
* client.fetchAsync('api').then(x => x.json).then(setFoo);
|
|
57
|
-
* }, [client]);
|
|
58
|
-
* return <Button onClick={onClick}>{foo}</Button>
|
|
59
|
-
* }
|
|
60
|
-
*
|
|
61
|
-
* export const render = createApp(App, configCallback);
|
|
62
|
-
*
|
|
63
|
-
* export default render;
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* __Exposed providers__
|
|
68
|
-
* @see {@link @equinor/fusion-framework-react.FrameworkProvider | FrameworkProvider}
|
|
69
|
-
* @see {@link ModuleProvider | ModuleProvider}
|
|
70
|
-
*
|
|
71
|
-
* @template TModules module types included in configuration.
|
|
72
|
-
* @param Component - React component to render
|
|
73
|
-
* @param configure - Callback for configuring application
|
|
74
|
-
* @param modules - required modules for application
|
|
75
|
-
*/
|
|
76
|
-
export const createComponent =
|
|
77
|
-
<TModules extends Array<AnyModule>, TRef extends Fusion = Fusion, TEnv extends AppEnv = AppEnv>(
|
|
78
|
-
Component: React.ElementType,
|
|
79
|
-
configure?: AppModuleInitiator<TModules, TRef, TEnv>,
|
|
80
|
-
): ComponentRenderer<TRef, TEnv> =>
|
|
81
|
-
(fusion, env) =>
|
|
82
|
-
lazy(async () => {
|
|
83
|
-
const init = configureModules<TModules, TRef, TEnv>(configure);
|
|
84
|
-
// configureModules returns a generic modules instance; narrow it to the
|
|
85
|
-
// app-specific shape expected by consumers of this component.
|
|
86
|
-
const modules = (await init({
|
|
87
|
-
fusion,
|
|
88
|
-
env,
|
|
89
|
-
})) as unknown as AppModulesInstance;
|
|
90
|
-
|
|
91
|
-
modules.event.dispatchEvent('onReactAppLoaded', {
|
|
92
|
-
detail: { modules, fusion, env: env },
|
|
93
|
-
source: Component,
|
|
94
|
-
});
|
|
95
|
-
return {
|
|
96
|
-
default: () => (
|
|
97
|
-
<FrameworkProvider value={fusion}>
|
|
98
|
-
<AppModuleProvider value={modules}>
|
|
99
|
-
{/* TODO(#5083): tighten generics so Component no longer needs @ts-ignore */}
|
|
100
|
-
{/* eslint-disable-next-line @typescript-eslint/ban-ts-comment*/}
|
|
101
|
-
{/* @ts-ignore */}
|
|
102
|
-
<Component />
|
|
103
|
-
</AppModuleProvider>
|
|
104
|
-
</FrameworkProvider>
|
|
105
|
-
),
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
declare module '@equinor/fusion-framework-module-event' {
|
|
110
|
-
interface FrameworkEventMap {
|
|
111
|
-
onReactAppLoaded: FrameworkEvent<
|
|
112
|
-
FrameworkEventInit<
|
|
113
|
-
{ modules: AppModulesInstance; fusion: Fusion; env: AppEnv },
|
|
114
|
-
React.ComponentType
|
|
115
|
-
>
|
|
116
|
-
>;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export default createComponent;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Suspense, useMemo, type ElementType } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useFramework } from '@equinor/fusion-framework-react';
|
|
4
|
-
|
|
5
|
-
import type { AnyModule } from '@equinor/fusion-framework-module';
|
|
6
|
-
import type { AppEnv, AppModuleInitiator } from '@equinor/fusion-framework-app';
|
|
7
|
-
|
|
8
|
-
import { createComponent } from './create-component';
|
|
9
|
-
import type { AppModule } from '@equinor/fusion-framework-module-app';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates a legacy wrapper component that bootstraps a Fusion React app within
|
|
13
|
-
* the older Fusion CLI hosting model.
|
|
14
|
-
*
|
|
15
|
-
* @deprecated Prefer {@link renderApp} for new applications. This helper exists
|
|
16
|
-
* only for backward-compatibility with apps that must run inside the legacy
|
|
17
|
-
* Fusion CLI.
|
|
18
|
-
*
|
|
19
|
-
* @template TModules - Array of additional module types to initialise.
|
|
20
|
-
* @param Component - The root React element to render.
|
|
21
|
-
* @param configure - Optional callback to configure application modules.
|
|
22
|
-
* @returns A React function component that initialises modules and renders the app.
|
|
23
|
-
*/
|
|
24
|
-
export const createLegacyApp = <TModules extends Array<AnyModule>>(
|
|
25
|
-
Component: ElementType,
|
|
26
|
-
configure?: AppModuleInitiator<TModules>,
|
|
27
|
-
) => {
|
|
28
|
-
const LegacyComponent = () => {
|
|
29
|
-
const fusion = useFramework<[AppModule]>();
|
|
30
|
-
const RenderComponent = useMemo(() => {
|
|
31
|
-
const creator = createComponent(Component, configure);
|
|
32
|
-
// @eikeland
|
|
33
|
-
// TODO(#5084): recheck when legacy fusion-cli is updated!
|
|
34
|
-
const appProvider = fusion.modules.app;
|
|
35
|
-
// Use the real app config/manifest once the provider has resolved them
|
|
36
|
-
if (appProvider?.current) {
|
|
37
|
-
const { config, manifest } = appProvider.current;
|
|
38
|
-
// Legacy app provider config/manifest predate the strict AppEnv shape; cast until legacy fusion-cli is updated.
|
|
39
|
-
return creator(fusion, { config, manifest } as unknown as AppEnv);
|
|
40
|
-
}
|
|
41
|
-
// No app provider available yet; pass an empty object cast to AppEnv as a placeholder.
|
|
42
|
-
return creator(fusion, {} as unknown as AppEnv);
|
|
43
|
-
}, [fusion]);
|
|
44
|
-
return (
|
|
45
|
-
<Suspense fallback={<p>loading app</p>}>
|
|
46
|
-
<RenderComponent />
|
|
47
|
-
</Suspense>
|
|
48
|
-
);
|
|
49
|
-
};
|
|
50
|
-
return LegacyComponent;
|
|
51
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
__useFeature__
|
|
2
|
-
|
|
3
|
-
Custom hook for accessing and manipulating feature flags.
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
const Component = () => {
|
|
7
|
-
const { feature, toggleFeature } = useFeature('my-feature');
|
|
8
|
-
return (
|
|
9
|
-
<>
|
|
10
|
-
<p>My feature is { feature.enabled ? 'enabled': 'disabled' }</p>
|
|
11
|
-
<button onClick={ () => toggleFeature() }>
|
|
12
|
-
{ feature.enabled ? 'disable' : 'enable' } my feature
|
|
13
|
-
</button>
|
|
14
|
-
</>
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
> [!NOTE]
|
|
20
|
-
> this hook can access parent feature if not found in application
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { AppConfigurator, IAppConfigurator } from '@equinor/fusion-framework-app';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
enableFeatureFlagging,
|
|
5
|
-
type FeatureFlagBuilderCallback,
|
|
6
|
-
type IFeatureFlag,
|
|
7
|
-
} from '@equinor/fusion-framework-module-feature-flag';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
createLocalStoragePlugin,
|
|
11
|
-
createUrlPlugin,
|
|
12
|
-
} from '@equinor/fusion-framework-module-feature-flag/plugins';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Enables the specified feature flags.
|
|
16
|
-
*
|
|
17
|
-
* @param configurator - The AppConfigurator instance.
|
|
18
|
-
* @param flags - An array of feature flags to enable.
|
|
19
|
-
*/
|
|
20
|
-
export function enableFeatureFlag(
|
|
21
|
-
configurator: IAppConfigurator,
|
|
22
|
-
flags: Array<IFeatureFlag<unknown> & { allowUrl?: boolean | undefined }>,
|
|
23
|
-
): void;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Enables a feature flag by invoking the provided configurator and callback.
|
|
27
|
-
*
|
|
28
|
-
* @param configurator - The AppConfigurator responsible for configuring the feature flag.
|
|
29
|
-
* @param cb - The FeatureFlagBuilderCallback to be executed for the feature flag.
|
|
30
|
-
*
|
|
31
|
-
* @remarks
|
|
32
|
-
* Advance use __ONLY__
|
|
33
|
-
*/
|
|
34
|
-
export function enableFeatureFlag(
|
|
35
|
-
configurator: IAppConfigurator,
|
|
36
|
-
cb: FeatureFlagBuilderCallback,
|
|
37
|
-
): void;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Enables feature flagging based on the provided configurator and flags callback.
|
|
41
|
-
* @param configurator The AppConfigurator instance.
|
|
42
|
-
* @param flags_cb Optional flags callback that can be an array of feature flags or a callback function.
|
|
43
|
-
*/
|
|
44
|
-
export function enableFeatureFlag(
|
|
45
|
-
configurator: IAppConfigurator,
|
|
46
|
-
flags_cb:
|
|
47
|
-
| Array<IFeatureFlag<unknown> & { allowUrl?: boolean | undefined }>
|
|
48
|
-
| FeatureFlagBuilderCallback,
|
|
49
|
-
): void {
|
|
50
|
-
// Dispatch based on whether the caller passed an array of flags or a builder callback
|
|
51
|
-
switch (typeof flags_cb) {
|
|
52
|
-
case 'function': {
|
|
53
|
-
enableFeatureFlagging(configurator, flags_cb);
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case 'object': {
|
|
57
|
-
const urlFlags: IFeatureFlag[] = [];
|
|
58
|
-
// Split out flags marked allowUrl so they can be registered with the URL plugin
|
|
59
|
-
const localFlags = (flags_cb ?? []).map((flag) => {
|
|
60
|
-
const { allowUrl, ...localFlag } = flag;
|
|
61
|
-
// Track allowUrl flags separately; they still get registered locally too
|
|
62
|
-
if (allowUrl) {
|
|
63
|
-
urlFlags.push(flag);
|
|
64
|
-
}
|
|
65
|
-
return localFlag;
|
|
66
|
-
});
|
|
67
|
-
enableFeatureFlagging(configurator, async (builder) => {
|
|
68
|
-
// TODO(#5086): should unnamed application be allowed to use feature flags?
|
|
69
|
-
builder.addPlugin(
|
|
70
|
-
createLocalStoragePlugin(localFlags, {
|
|
71
|
-
name: (configurator as AppConfigurator).env?.manifest.appKey ?? undefined,
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
74
|
-
builder.addPlugin(createUrlPlugin(urlFlags));
|
|
75
|
-
});
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Feature-flag sub-path entry-point.
|
|
3
|
-
*
|
|
4
|
-
* Provides the {@link enableFeatureFlag} configurator helper and the
|
|
5
|
-
* {@link useFeature} hook for reading and toggling feature flags at runtime.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
export {
|
|
10
|
-
IFeatureFlag,
|
|
11
|
-
IFeatureFlagProvider,
|
|
12
|
-
FeatureFlagModule,
|
|
13
|
-
} from '@equinor/fusion-framework-module-feature-flag';
|
|
14
|
-
|
|
15
|
-
export { enableFeatureFlag } from './enable-feature-flag';
|
|
16
|
-
|
|
17
|
-
export { useFeature } from './useFeature';
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
import { EMPTY, combineLatest, map } from 'rxjs';
|
|
4
|
-
|
|
5
|
-
import { useFrameworkModule } from '@equinor/fusion-framework-react';
|
|
6
|
-
import { useObservableState } from '@equinor/fusion-observable/react';
|
|
7
|
-
import type {
|
|
8
|
-
FeatureFlagModule,
|
|
9
|
-
IFeatureFlag,
|
|
10
|
-
} from '@equinor/fusion-framework-module-feature-flag';
|
|
11
|
-
import { findFeature } from '@equinor/fusion-framework-module-feature-flag/selectors';
|
|
12
|
-
|
|
13
|
-
import { useAppModule } from '../useAppModule';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* React hook for reading and toggling a single feature flag.
|
|
17
|
-
*
|
|
18
|
-
* Merges feature flags from both the framework and the application scope,
|
|
19
|
-
* so framework-level flags are visible alongside app-specific ones.
|
|
20
|
-
*
|
|
21
|
-
* @template T - The type of the feature flag's value payload.
|
|
22
|
-
* @param key - The unique key identifying the feature flag.
|
|
23
|
-
* @returns An object with:
|
|
24
|
-
* - `feature` – the resolved {@link IFeatureFlag}, or `undefined` if not found.
|
|
25
|
-
* - `toggleFeature` – callback to toggle the flag; pass `true`/`false` to
|
|
26
|
-
* set explicitly, or omit to invert the current state.
|
|
27
|
-
* - `error` – any error from the feature-flag observable.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```tsx
|
|
31
|
-
* const { feature, toggleFeature } = useFeature('dark-mode');
|
|
32
|
-
* return (
|
|
33
|
-
* <Switch checked={feature?.enabled} onChange={() => toggleFeature()} />
|
|
34
|
-
* );
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export const useFeature = <T = unknown>(
|
|
38
|
-
key: string,
|
|
39
|
-
): {
|
|
40
|
-
feature?: IFeatureFlag<T>;
|
|
41
|
-
toggleFeature: (enabled?: boolean) => void;
|
|
42
|
-
error?: unknown;
|
|
43
|
-
} => {
|
|
44
|
-
const appProvider = useAppModule<FeatureFlagModule>('featureFlag');
|
|
45
|
-
const frameworkProvider = useFrameworkModule<FeatureFlagModule>('featureFlag');
|
|
46
|
-
|
|
47
|
-
/** get all available feature flags */
|
|
48
|
-
const features$ = useMemo(() => {
|
|
49
|
-
/** the framework does not have the feature flag module */
|
|
50
|
-
if (!frameworkProvider) {
|
|
51
|
-
return appProvider.features$;
|
|
52
|
-
}
|
|
53
|
-
/** merge feature flags from framework and application */
|
|
54
|
-
return combineLatest({
|
|
55
|
-
framework: frameworkProvider.features$,
|
|
56
|
-
app: appProvider.features$,
|
|
57
|
-
}).pipe(
|
|
58
|
-
map(({ framework, app }) => {
|
|
59
|
-
// Application feature flags override framework defaults with the same key.
|
|
60
|
-
const mergedFeatureFlags = { ...framework, ...app };
|
|
61
|
-
return mergedFeatureFlags;
|
|
62
|
-
}),
|
|
63
|
-
);
|
|
64
|
-
}, [appProvider, frameworkProvider]);
|
|
65
|
-
|
|
66
|
-
/** find feature flag by the provided key */
|
|
67
|
-
const feature$ = useMemo(
|
|
68
|
-
() =>
|
|
69
|
-
features$
|
|
70
|
-
// Narrow the merged stream down to the requested feature key.
|
|
71
|
-
.pipe(findFeature<T>(key)),
|
|
72
|
-
[features$, key],
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const { value: feature, error } = useObservableState(feature$ ?? EMPTY);
|
|
76
|
-
|
|
77
|
-
const toggleFeature = useCallback(
|
|
78
|
-
(enable?: boolean) => {
|
|
79
|
-
/** if no value provided, invert the current value */
|
|
80
|
-
const enabled = enable === undefined ? !appProvider.getFeature(key)?.enabled : enable;
|
|
81
|
-
appProvider.toggleFeature({
|
|
82
|
-
key,
|
|
83
|
-
enabled,
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
[appProvider, key],
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
return { feature, toggleFeature, error };
|
|
90
|
-
};
|
package/src/framework/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Framework sub-path entry-point.
|
|
3
|
-
*
|
|
4
|
-
* Re-exports framework-level hooks (as opposed to application-scoped ones)
|
|
5
|
-
* for accessing the Fusion instance, current user, and HTTP clients.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
export { useFramework } from '@equinor/fusion-framework-react';
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
useCurrentUser,
|
|
13
|
-
useHttpClient as useFrameworkHttpClient,
|
|
14
|
-
} from '@equinor/fusion-framework-react/hooks';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useFramework } from '@equinor/fusion-framework-react';
|
|
2
|
-
import { useCurrentContext } from '@equinor/fusion-framework-react-module-context';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* React hook that returns the currently selected context from the
|
|
6
|
-
* **framework-level** context module (as opposed to the application-scoped one).
|
|
7
|
-
*
|
|
8
|
-
* Use this when you need the portal/host context rather than the app's own
|
|
9
|
-
* context provider.
|
|
10
|
-
*
|
|
11
|
-
* @returns The current framework context, or `undefined` if none is selected.
|
|
12
|
-
*/
|
|
13
|
-
export const useFrameworkCurrentContext = () => useCurrentContext(useFramework().modules.context);
|
|
14
|
-
|
|
15
|
-
export default useFrameworkCurrentContext;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
## Help center
|
|
2
|
-
|
|
3
|
-
### useHelpCenter
|
|
4
|
-
|
|
5
|
-
A hook to open the help center side sheet programmatically.
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
const {
|
|
9
|
-
openHelp,
|
|
10
|
-
openArticle,
|
|
11
|
-
openFaqs,
|
|
12
|
-
openSearch,
|
|
13
|
-
openGovernance
|
|
14
|
-
} = useHelpCenter();
|
|
15
|
-
|
|
16
|
-
openHelp();
|
|
17
|
-
openArticle('article-slug-name');
|
|
18
|
-
openFaqs();
|
|
19
|
-
openSearch('search-input');
|
|
20
|
-
openGovernance();
|
|
21
|
-
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const EVENT_NAME = '@Portal::FusionHelp::open';
|
package/src/help-center/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
2
|
-
import type { HelpCenterOpenEventDetail } from './useHelpCenter';
|
|
3
|
-
|
|
4
|
-
export { useHelpCenter } from './useHelpCenter';
|
|
5
|
-
export type { HelpCenterOpenEventDetail } from './useHelpCenter';
|
|
6
|
-
|
|
7
|
-
declare module '@equinor/fusion-framework-module-event' {
|
|
8
|
-
interface FrameworkEventMap {
|
|
9
|
-
'@Portal::FusionHelp::open': FrameworkEvent<FrameworkEventInit<HelpCenterOpenEventDetail>>;
|
|
10
|
-
}
|
|
11
|
-
}
|