@genesislcap/blank-app-seed 3.30.0-prerelease.14 → 3.30.0-prerelease.15

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 (41) hide show
  1. package/.genx/package.json +1 -1
  2. package/CHANGELOG.md +7 -0
  3. package/client-tmp/react/package.json +12 -6
  4. package/client-tmp/react/src/App.tsx +85 -68
  5. package/client-tmp/react/src/config.ts +0 -15
  6. package/client-tmp/react/src/guards/ProtectedGuard.tsx +56 -0
  7. package/client-tmp/react/src/helpers/hasPermissionHelper.tsx +10 -0
  8. package/client-tmp/react/src/helpers/isAuthenticatedHelper.tsx +14 -0
  9. package/client-tmp/react/src/helpers/isConnectedHelper.tsx +16 -0
  10. package/client-tmp/react/src/layouts/blank/BlankLayout.tsx +1 -1
  11. package/client-tmp/react/src/layouts/default/DefaultLayout.tsx +17 -14
  12. package/client-tmp/react/src/main.tsx +19 -5
  13. package/client-tmp/react/src/pages/NotFoundPage/NotFoundPage.css +0 -0
  14. package/client-tmp/react/src/pages/NotFoundPage/NotFoundPage.tsx +14 -0
  15. package/client-tmp/react/src/pages/NotPermittedPage/NotPermittedPage.test.tsx +1 -1
  16. package/client-tmp/react/src/pages/NotPermittedPage/NotPermittedPage.tsx +1 -1
  17. package/client-tmp/react/src/pbc/README.md +7 -0
  18. package/client-tmp/react/src/pbc/container.tsx +36 -0
  19. package/client-tmp/react/src/pbc/elementsRenderer.tsx +40 -0
  20. package/client-tmp/react/src/pbc/utils.ts +121 -0
  21. package/client-tmp/react/src/services/store.service.ts +48 -0
  22. package/client-tmp/react/src/share/foundation-login.ts +13 -6
  23. package/client-tmp/react/src/share/genesis-components.ts +49 -23
  24. package/client-tmp/react/src/store/AuthContext.tsx +0 -2
  25. package/client-tmp/react/src/store/RoutesContext.tsx +73 -0
  26. package/client-tmp/react/src/types/LayoutName.ts +3 -0
  27. package/client-tmp/react/src/types/RouteLayouts.ts +3 -1
  28. package/client-tmp/react/src/utils/getLayoutNameByRoute.ts +5 -0
  29. package/client-tmp/react/src/utils/history.ts +4 -2
  30. package/client-tmp/react/src/utils/index.ts +3 -1
  31. package/client-tmp/react/src/utils/store.ts +34 -0
  32. package/client-tmp/react/test/e2e/fixture.ts +1 -1
  33. package/client-tmp/react/tsconfig.app.json +1 -22
  34. package/client-tmp/react/tsconfig.json +28 -10
  35. package/client-tmp/react/vite.config.ts +21 -3
  36. package/package.json +1 -1
  37. package/client-tmp/react/src/guards/AuthGuard.tsx +0 -32
  38. package/client-tmp/react/src/guards/PermissionsGuard.tsx +0 -37
  39. package/client-tmp/react/src/index.ts +0 -21
  40. package/client-tmp/react/src/reportWebVitals.ts +0 -13
  41. /package/server/{{appName}}-app/src/main/genesis/scripts/{{{appName}}-data-pipelines.kts → {{appName}}-pipelines.kts} +0 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/blank-app-seed-config",
3
3
  "description": "Genesis Blank App Seed Configuration",
4
- "version": "3.30.0-prerelease.14",
4
+ "version": "3.30.0-prerelease.15",
5
5
  "license": "Apache-2.0",
6
6
  "scripts": {
7
7
  "lint": "eslint .",
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.30.0-prerelease.15](https://github.com/genesiscommunitysuccess/blank-app-seed/compare/v3.30.0-prerelease.14...v3.30.0-prerelease.15) (2024-09-26)
4
+
5
+
6
+ ### Features
7
+
8
+ * pbc support in react [FUI-2140](https://github.com/genesiscommunitysuccess/blank-app-seed/issues/2140) (#347) 4c41243, closes FUI-2173 FUI-2173 FUI-2173 FUI-2157 FUI-2157 origin/ak/FUI-2173 ak/FUI-2157 FUI-2157 FUI-2157
9
+
3
10
  ## [3.30.0-prerelease.14](https://github.com/genesiscommunitysuccess/blank-app-seed/compare/v3.30.0-prerelease.13...v3.30.0-prerelease.14) (2024-09-26)
4
11
 
5
12
 
@@ -9,7 +9,7 @@
9
9
  "build": "vite build",
10
10
  "build:stats": "npm run build --stats-json",
11
11
  "clean": "genx clean dist node_modules",
12
- "dev": "vite",
12
+ "dev": "vite build && vite preview",
13
13
  "dev:docker": "npm run dev -- --host 0.0.0.0",
14
14
  "dev:no-open": "NO_OPEN=true npm run dev",
15
15
  "dev:intellij": "npm run dev",
@@ -33,17 +33,21 @@
33
33
  "@ag-grid-enterprise/core": "29.2.0",
34
34
  "@ag-grid-enterprise/row-grouping": "29.2.0",
35
35
  "@ag-grid-enterprise/server-side-row-model": "29.2.0",
36
+ "@genesislcap/foundation-comms": "{{versions.UI}}",
37
+ "@genesislcap/foundation-entity-management": "{{versions.UI}}",
36
38
  {{#if FDC3.includeDependencies}}
37
39
  "@genesislcap/foundation-fdc3": "{{versions.UI}}",
38
40
  {{/if}}
39
- "@genesislcap/foundation-comms": "{{versions.UI}}",
40
- "@genesislcap/foundation-login": "{{versions.UI}}",
41
- "@genesislcap/foundation-entity-management": "{{versions.UI}}",
42
41
  "@genesislcap/foundation-header": "{{versions.UI}}",
42
+ "@genesislcap/foundation-layout": "{{versions.UI}}",
43
+ "@genesislcap/foundation-logger": "{{versions.UI}}",
44
+ "@genesislcap/foundation-login": "{{versions.UI}}",
45
+ "@genesislcap/foundation-shell": "{{versions.UI}}",
43
46
  "@genesislcap/foundation-ui": "{{versions.UI}}",
47
+ "@genesislcap/foundation-utils": "{{versions.UI}}",
44
48
  "@genesislcap/rapid-design-system": "{{versions.UI}}",
45
49
  "@genesislcap/rapid-grid-pro": "{{versions.UI}}",
46
- "@genesislcap/foundation-layout": "{{versions.UI}}",
50
+ "@genesislcap/web-core": "{{versions.UI}}",
47
51
  "@genesislcap/g2plot-chart": "{{versions.UI}}",
48
52
  "history": "^5.3.0",
49
53
  "react": "^19.0.0-beta-94eed63c49-20240425",
@@ -64,6 +68,7 @@
64
68
  "@testing-library/dom": "^10.4.0",
65
69
  "@testing-library/jest-dom": "^6.5.0",
66
70
  "@testing-library/react": "^16.0.0",
71
+ "@types/css-modules": "^1.0.5",
67
72
  "@types/jest": "^29.5.12",
68
73
  "@types/node": "^20.14.10",
69
74
  "@types/react": "npm:types-react@alpha",
@@ -80,7 +85,8 @@
80
85
  "ts-jest": "^29.2.5",
81
86
  "ts-node": "^10.9.2",
82
87
  "typescript": "^5.2.2",
83
- "vite": "^5.3.1"
88
+ "vite": "^5.3.1",
89
+ "vite-plugin-tsconfig-paths": "^1.4.1"
84
90
  },
85
91
  "overrides": {
86
92
  "@types/react": "npm:types-react@alpha",
@@ -1,31 +1,70 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { unstable_HistoryRouter as HistoryRouter, Routes, Route, useLocation } from 'react-router-dom';
1
3
  import {
2
- unstable_HistoryRouter as HistoryRouter,
3
- Routes,
4
- Route,
5
- useLocation,
6
- } from 'react-router-dom';
7
- import { useEffect } from 'react';
8
- import { history, setApiHost{{#if FDC3.channels.length}}, listenToChannel{{/if}} } from './utils';
4
+ history,
5
+ setApiHost,
6
+ getLayoutNameByRoute,
7
+ {{#if FDC3.channels.length~}}
8
+ listenToChannel,
9
+ onFDC3Ready,
10
+ {{/if}}
11
+ } from './utils';
12
+ import { customEventFactory, registerStylesTarget } from '@/pbc/utils';
9
13
  import LayoutWrapper from './layouts/LayoutWrapper';
10
- import { AUTH_PATH, NOT_PERMITTED_PATH, routeLayouts } from './config';
11
- import AuthGuard from './guards/AuthGuard';
12
- import PermissionsGuard from './guards/PermissionsGuard';
14
+ import LayoutName from '@/types/LayoutName';
15
+ import { AUTH_PATH, routeLayouts } from './config';
13
16
  import { AuthProvider } from './store/AuthContext';
14
- // Pages Components
17
+ import { RoutesProvider, useRoutesContext } from './store/RoutesContext';
15
18
  import AuthPage from './pages/AuthPage/AuthPage';
16
- import NotPermittedPage from './pages/NotPermittedPage/NotPermittedPage';
17
- {{#each routes}}
18
- import {{pascalCase this.name}} from './pages/{{pascalCase this.name}}/{{pascalCase this.name}}';
19
- {{/each}}
20
-
21
- // Genesis Components
22
- import './share/genesis-components';
19
+ import { registerComponents as genesisRegisterComponents } from './share/genesis-components';
20
+ import { configureFoundationLogin } from './share/foundation-login';
21
+ import ProtectedGuard from './guards/ProtectedGuard';
22
+ import { storeService } from '@/services/store.service';
23
23
 
24
- const LayoutWithLocation = () => {
24
+ const DynamicLayout = () => {
25
25
  const location = useLocation();
26
- const layout = routeLayouts[location.pathname] || 'default';
27
- {{#if FDC3.channels.length}}
26
+ const [layoutName, setLayoutName] = useState<LayoutName>(routeLayouts[location.pathname] || 'default');
27
+ const handleRouteChange = (location: any) => {
28
+ setLayoutName(getLayoutNameByRoute(location.pathname));
29
+ };
30
+ const route = useRoutesContext().find((r) => r.path === location.pathname);
31
+ let pageComponent;
32
+ let content;
33
+
28
34
  useEffect(() => {
35
+ handleRouteChange(location);
36
+ const unlisten = history.listen(handleRouteChange);
37
+
38
+ return () => {
39
+ unlisten();
40
+ }
41
+ }, [location]);
42
+
43
+ if (route) {
44
+ pageComponent = route.element;
45
+ } else {
46
+ pageComponent = <AuthPage />;
47
+ }
48
+
49
+ if (location.pathname === `/${AUTH_PATH}` || location.pathname === '/') {
50
+ content = pageComponent;
51
+ } else {
52
+ content = <ProtectedGuard>{pageComponent}</ProtectedGuard>
53
+ }
54
+
55
+ return <LayoutWrapper layout={layoutName}>{content}</LayoutWrapper>
56
+
57
+ };
58
+
59
+ const App: React.FC = ({ rootElement }) => {
60
+ const dispatchCustomEvent = (type: string, detail?: any) => {
61
+ rootElement.dispatchEvent(customEventFactory(type, detail));
62
+ };
63
+ const handleStoreConnected = (event: CustomEvent) => {
64
+ storeService.onConnected(event);
65
+ };
66
+ {{#if FDC3.channels.length~}}
67
+ const FDC3ReadyHandler = () => {
29
68
  {{#each FDC3.channels}}
30
69
  listenToChannel('{{this.name}}', '{{this.type}}', (result) => {
31
70
  console.log('Received FDC3 channel message on: {{this.name}} channel, type: {{this.type}}', result);
@@ -33,61 +72,39 @@ const LayoutWithLocation = () => {
33
72
  // E.g. open a modal or route to specific page: Route.path.push(`[Route name]`);
34
73
  });
35
74
  {{/each}}
36
-
37
- return () => {
38
- console.log('Component is being unmounted');
39
- };
40
- }, []);
75
+ };
41
76
  {{/if}}
42
77
 
43
- let pageComponent;
44
- let permissionCode = '{{this.permissions.viewRight}}';
45
-
46
- switch (location.pathname) {
47
- case `/${AUTH_PATH}`:
48
- pageComponent = <AuthPage />;
49
- break;
50
- case `/${NOT_PERMITTED_PATH}`:
51
- pageComponent = <NotPermittedPage />;
52
- break;
53
- {{#each routes}}
54
- case '/{{kebabCase this.name}}':
55
- pageComponent = <{{pascalCase this.name}} />;
56
- permissionCode = '{{this.permissions.viewRight}}';
57
- break;
58
- {{/each}}
59
- default:
60
- pageComponent = <AuthPage />;
61
- }
78
+ setApiHost();
79
+ genesisRegisterComponents();
80
+ configureFoundationLogin({ router: history });
62
81
 
63
- if (
64
- location.pathname === '/auth' ||
65
- location.pathname === '/'
66
- ) {
67
- return <LayoutWrapper layout={layout}>{pageComponent}</LayoutWrapper>;
68
- } else {
69
- return (
70
- <AuthGuard>
71
- <PermissionsGuard permissionCode={permissionCode}>
72
- <LayoutWrapper layout={layout}>{pageComponent}</LayoutWrapper>
73
- </PermissionsGuard>
74
- </AuthGuard>
75
- );
76
- }
77
- };
82
+ useEffect(() => {
83
+ rootElement.addEventListener('store-connected', handleStoreConnected);
84
+ registerStylesTarget(document.body, 'main');
85
+ {{#if FDC3.channels.length~}}
86
+ onFDC3Ready(FDC3ReadyHandler);
87
+ {{/if}}
88
+ dispatchCustomEvent('store-connected', rootElement);
89
+ dispatchCustomEvent('store-ready', true);
78
90
 
79
- const App: React.FC = () => {
80
- setApiHost();
91
+ return () => {
92
+ rootElement.removeEventListener('store-connected', handleStoreConnected);
93
+ dispatchCustomEvent('store-disconnected');
94
+ };
95
+ }, []);
81
96
 
82
97
  return (
83
98
  <AuthProvider>
84
- <HistoryRouter history={history}>
85
- <Routes>
86
- <Route path="*" element={<LayoutWithLocation />} />
87
- </Routes>
88
- </HistoryRouter>
99
+ <RoutesProvider>
100
+ <HistoryRouter history={history}>
101
+ <Routes>
102
+ <Route path="*" element={<DynamicLayout />} />
103
+ </Routes>
104
+ </HistoryRouter>
105
+ </RoutesProvider>
89
106
  </AuthProvider>
90
107
  );
91
108
  };
92
109
 
93
- export default App;
110
+ export default App;
@@ -1,13 +1,10 @@
1
1
  import { RouteLayouts } from './types/RouteLayouts';
2
2
 
3
3
  export const routeLayouts: RouteLayouts = {
4
- '/auth-mock': 'blank',
5
4
  '/auth': 'blank',
6
5
  '/': 'blank',
7
6
  };
8
7
 
9
- import type { MainMenu } from './types/menu';
10
-
11
8
  export const AUTH_PATH = 'auth';
12
9
  export const NOT_PERMITTED_PATH = 'not-permitted';
13
10
 
@@ -18,15 +15,3 @@ export const API_DATA = {
18
15
  password: '', // provide password to a user in given environment
19
16
  },
20
17
  };
21
-
22
- export const mainMenu: MainMenu = [
23
- {{#each routes}}
24
- {
25
- index: {{@index}},
26
- path: '{{kebabCase this.name}}',
27
- title: '{{#if this.title}}{{this.title}}{{else}}{{this.name}}{{/if}}',
28
- icon: '{{this.icon}}',
29
- variant: 'solid'
30
- }{{#unless @last}},{{/unless}}
31
- {{/each}}
32
- ];
@@ -0,0 +1,56 @@
1
+ import { useState, useEffect, ReactNode } from 'react';
2
+ import isConnectedHelper from '@/helpers/isConnectedHelper';
3
+ import isAuthenticatedHelper from '@/helpers/isAuthenticatedHelper';
4
+ import hasPermissionHelper from '@/helpers/hasPermissionHelper';
5
+ import { useRoutesContext } from '@/store/RoutesContext';
6
+ import { NOT_PERMITTED_PATH, AUTH_PATH } from '@/config';
7
+
8
+ enum PermissionState {
9
+ ALLOWED = 'allowed',
10
+ DENIED = 'denied',
11
+ UNKNOWN = 'unknown',
12
+ }
13
+
14
+ const redirectUrlByPermissionState: { [key in Partial<PermissionState>]?: string } = {
15
+ [PermissionState.DENIED]: NOT_PERMITTED_PATH,
16
+ [PermissionState.UNKNOWN]: AUTH_PATH,
17
+ };
18
+
19
+ const ProtectedGuard: React.FC<{ children: ReactNode }> = ({ children }: { children: ReactNode }) => {
20
+ const routes = useRoutesContext();
21
+ const [isConnected, setIsConnected] = useState<boolean | null>(null);
22
+ const isAuthenticated: boolean | null = null;
23
+ const route = routes.find(({ path }) => path === location.pathname);
24
+ const hasPermission = route?.data?.permissionCode ? hasPermissionHelper(route.data?.permissionCode) : true;
25
+
26
+ useEffect(() => {
27
+ isConnectedHelper().then((connectedState: boolean): void => {
28
+ setIsConnected(connectedState);
29
+ });
30
+ }, []);
31
+
32
+ useEffect((): void => {
33
+ if (isConnected === null) {
34
+ return;
35
+ }
36
+
37
+ const isAuthenticated = isAuthenticatedHelper();
38
+
39
+
40
+ let permissionState;
41
+
42
+ if (!isConnected || !isAuthenticated) {
43
+ permissionState = PermissionState.UNKNOWN;
44
+ } else if (hasPermission === false) {
45
+ permissionState = PermissionState.DENIED;
46
+ }
47
+
48
+ if (permissionState) {
49
+ window.location.href = `/${redirectUrlByPermissionState[permissionState]}`;
50
+ }
51
+ }, [routes, isConnected, isAuthenticated, hasPermission]);
52
+
53
+ return children;
54
+ };
55
+
56
+ export default ProtectedGuard;
@@ -0,0 +1,10 @@
1
+ import { getUser } from '@genesislcap/foundation-user';
2
+
3
+ const hasPermissionHelper = (permissionCode: string | undefined): boolean => {
4
+ const user = getUser();
5
+
6
+ return !!(permissionCode && !user.hasPermission(permissionCode))
7
+
8
+ };
9
+
10
+ export default hasPermissionHelper;
@@ -0,0 +1,14 @@
1
+ import { getUser } from '@genesislcap/foundation-user';
2
+
3
+ const isAuthenticatedHelper = (): boolean => {
4
+ const user = getUser();
5
+
6
+ if (!user.isAuthenticated) {
7
+ user.trackPath();
8
+ return false;
9
+ }
10
+
11
+ return true;
12
+ };
13
+
14
+ export default isAuthenticatedHelper;
@@ -0,0 +1,16 @@
1
+ import { getConnect } from '@genesislcap/foundation-comms';
2
+
3
+ const isConnectedHelper = (): Promise<boolean> => {
4
+ const connect = getConnect();
5
+ const hostUrl = sessionStorage.getItem('hostUrl');
6
+
7
+ if (connect.isConnected) {
8
+ return new Promise((resolve) => resolve(true));
9
+ }
10
+ if (!hostUrl) {
11
+ return new Promise((resolve) => resolve(false));
12
+ }
13
+ return connect.connect(hostUrl);
14
+ };
15
+
16
+ export default isConnectedHelper;
@@ -1,7 +1,7 @@
1
1
  import React, { ReactNode, useEffect, useRef } from 'react';
2
2
  import { configureDesignSystem } from '@genesislcap/foundation-ui';
3
3
  import styles from './BlankLayout.module.css';
4
- import * as designTokens from '../../styles/design-tokens.json';
4
+ import * as designTokens from '@/styles/design-tokens.json';
5
5
 
6
6
  interface BlankLayoutProps {
7
7
  children: ReactNode;
@@ -1,13 +1,14 @@
1
1
  import React, { ReactNode, useEffect, useRef } from 'react';
2
- import { configureDesignSystem } from '@genesislcap/foundation-ui';
2
+ import { configureDesignSystem, getNavItems } from '@genesislcap/foundation-ui';
3
3
  import { useNavigate } from 'react-router-dom';
4
4
  import {
5
5
  baseLayerLuminance,
6
6
  StandardLuminance,
7
7
  } from '@microsoft/fast-components';
8
8
  import styles from './DefaultLayout.module.css';
9
- import { mainMenu } from '../../config';
10
- import * as designTokens from '../../styles/design-tokens.json';
9
+ import PBCElementsRenderer from '@/pbc/elementsRenderer';
10
+ import * as designTokens from '@/styles/design-tokens.json';
11
+ import { useRoutesContext } from '@/store/RoutesContext';
11
12
 
12
13
  interface DefaultLayoutProps {
13
14
  children: ReactNode;
@@ -15,10 +16,13 @@ interface DefaultLayoutProps {
15
16
 
16
17
  const DefaultLayout: React.FC<DefaultLayoutProps> = ({ children }) => {
17
18
  const navigate = useNavigate();
18
-
19
19
  const designSystemProviderRef = useRef<HTMLElement>(null);
20
20
  const foundationHeaderRef = useRef<HTMLElement>(null);
21
- const allRoutes = mainMenu;
21
+ const routes = useRoutesContext();
22
+ const navItems = getNavItems(routes.flatMap((route) => ({
23
+ path: route.path || '',
24
+ navItems: route.data?.navItems,
25
+ })));
22
26
 
23
27
  const onLuminanceToggle = (): void => {
24
28
  if (designSystemProviderRef.current) {
@@ -57,22 +61,21 @@ const DefaultLayout: React.FC<DefaultLayoutProps> = ({ children }) => {
57
61
 
58
62
  return (
59
63
  <rapid-design-system-provider ref={designSystemProviderRef} class={className}>
64
+ <PBCElementsRenderer target={['layout-start']} />
60
65
  <foundation-header
61
66
  ref={foundationHeaderRef}
62
67
  show-luminance-toggle-button
63
68
  show-misc-toggle-button
69
+ routeNavItems={navItems}
64
70
  navigateTo={(path) => navigate(path)}
65
71
  >
66
- <section className={styles['routes-wrapper']} slot="routes">
67
- {allRoutes.map((route, index) => (
68
- <rapid-button key={index} onClick={() => navigate(route.path)}>
69
- <rapid-icon name={route.icon}></rapid-icon>
70
- {route.title}
71
- </rapid-button>
72
- ))}
73
- </section>
74
72
  </foundation-header>
75
- <section className={styles['content']}>{children}</section>
73
+ <section className={styles['content']}>
74
+ <PBCElementsRenderer target={['content-start']} />
75
+ {children}
76
+ <PBCElementsRenderer target={['content', 'content-end']} />
77
+ </section>
78
+ <PBCElementsRenderer target={['layout', 'layout-end']} />
76
79
  </rapid-design-system-provider>
77
80
  );
78
81
  };
@@ -1,10 +1,24 @@
1
1
  import React from 'react'
2
2
  import ReactDOM from 'react-dom/client'
3
3
  import App from './App.tsx'
4
+
5
+ import { registerPBCs } from '@/pbc/utils';
6
+ import { createLogger } from '@genesislcap/foundation-logger';
7
+
4
8
  import './styles/styles.css'
5
9
 
6
- ReactDOM.createRoot(document.getElementById('root')!).render(
7
- <React.StrictMode>
8
- <App />
9
- </React.StrictMode>,
10
- )
10
+ const logger = createLogger('main');
11
+
12
+ function bootstrapApp() {
13
+ const rootEelement = document.getElementById('root');
14
+ ReactDOM.createRoot(rootEelement!).render(
15
+ <React.StrictMode>
16
+ <App rootElement={rootEelement} />
17
+ </React.StrictMode>,
18
+ )
19
+ }
20
+
21
+ registerPBCs()
22
+ .then(hasAssets => logger.debug(hasAssets ? 'PBCs registered' : 'No PBCs detected'))
23
+ .catch((err) => logger.error(err))
24
+ .finally(bootstrapApp)
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import ErrorMessage from '@/components/ErrorMessage/ErrorMessage';
3
+ import './NotFoundPage.css';
4
+
5
+ const NotFoundPage: React.FC = () => {
6
+ return (
7
+ <ErrorMessage
8
+ elementType="h1"
9
+ message="Page Not Found 404"
10
+ />
11
+ );
12
+ };
13
+
14
+ export default NotFoundPage;
@@ -1,7 +1,7 @@
1
1
  import { render, screen } from '@testing-library/react';
2
2
  import NotPermittedPage from './NotPermittedPage';
3
3
 
4
- jest.mock('../../components/ErrorMessage/ErrorMessage', () => {
4
+ jest.mock('@/components/ErrorMessage/ErrorMessage', () => {
5
5
  return jest.fn((props: { message: string }) => <h1 data-testid="error-message">{props.message}</h1>);
6
6
  });
7
7
 
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import ErrorMessage from '../../components/ErrorMessage/ErrorMessage';
2
+ import ErrorMessage from '@/components/ErrorMessage/ErrorMessage';
3
3
  import './NotPermittedPage.css';
4
4
 
5
5
  const NotPermittedPage: React.FC = () => {
@@ -0,0 +1,7 @@
1
+ # PBC
2
+
3
+ This directory contains PBC `genx add` output.
4
+
5
+ The app will reload if you remove, add, or customise a packaged business capability.
6
+
7
+ See the expanded README.md in `@genesislcap/foundation-shell`.
@@ -0,0 +1,36 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { deriveElementTag } from './utils';
3
+ import { useRoutesContext } from '@/store/RoutesContext';
4
+ import { useLocation } from 'react-router-dom';
5
+
6
+
7
+ const PBCContainer: React.FC = () => {
8
+ const containerRef = useRef<HTMLDivElement>(null);
9
+ const routes = useRoutesContext();
10
+ const location = useLocation();
11
+
12
+ useEffect(() => {
13
+ const loadElement = async () => {
14
+ const route = routes.find(({ path }) => path === location.pathname);
15
+ const { data } = route || {};
16
+ const { pbcElement, pbcElementTag } = data || {};
17
+
18
+ if (!pbcElement) {
19
+ return;
20
+ }
21
+ const element = pbcElement.define ? pbcElement : await pbcElement();
22
+ const tagName = pbcElementTag || deriveElementTag(element.name);
23
+ const customElement = document.createElement(tagName);
24
+ if (containerRef.current) {
25
+ containerRef.current.replaceChildren();
26
+ containerRef.current.appendChild(customElement);
27
+ }
28
+ };
29
+
30
+ loadElement();
31
+ }, [location.pathname, routes]);
32
+
33
+ return <div ref={containerRef} className="container" style=\{{ width: '100%', height: '100%' }}></div>;
34
+ };
35
+
36
+ export default PBCContainer;
@@ -0,0 +1,40 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { AppElementPredicate, AppTargetId } from '@genesislcap/foundation-shell/app';
3
+ import { customEventFactory, getTargetElements } from './utils';
4
+
5
+ interface PBCElementsRendererProps {
6
+ target: AppTargetId;
7
+ predicate?: AppElementPredicate;
8
+ }
9
+
10
+ interface PBCContainerElement extends HTMLDivElement {
11
+ $emit: (type: string, detail: any) => void;
12
+ }
13
+
14
+ const PBCElementsRenderer = ({ target = [], predicate = () => true }: PBCElementsRendererProps) => {
15
+ const containerRef = useRef<PBCContainerElement>(null);
16
+
17
+ useEffect(() => {
18
+ if (containerRef.current) {
19
+ containerRef.current.$emit = (type, detail) => {
20
+ containerRef.current.dispatchEvent(customEventFactory(type, detail));
21
+ }
22
+ }
23
+ }, []);
24
+
25
+ useEffect(() => {
26
+ if (containerRef.current) {
27
+ containerRef.current.replaceChildren();
28
+ }
29
+ const templates = getTargetElements(target, predicate);
30
+ templates.forEach((currentTemplate: any) => {
31
+ if (containerRef.current) {
32
+ currentTemplate.render(containerRef.current, containerRef.current);
33
+ }
34
+ });
35
+ }, [target, predicate]);
36
+
37
+ return (<div ref={containerRef} className="container"></div>);
38
+ };
39
+
40
+ export default PBCElementsRenderer;