From c66ef67e6a1bce7dfad716680b3dde1dbdab1933 Mon Sep 17 00:00:00 2001 From: Christopher Berge Hove Date: Tue, 22 Oct 2024 08:02:10 +0200 Subject: [PATCH] chore: Update app.config.ts and package.json in legacyAppLoader - Remove unused import and code in app.config.ts - Update dev:appLoader script in package.json - Remove unused components in legacyAppLoader Closes #issue-number --- client/.gitignore | 1 + client/apps/legacyAppLoader/app.config.ts | 44 +++++++------ client/apps/legacyAppLoader/package.json | 2 +- client/apps/legacyAppLoader/src/config.ts | 4 +- .../components/LegacyAppLoader.tsx | 45 ------------- .../components/LegacyAppWrapper.tsx | 63 ------------------- .../components/LegacyWrapper.tsx | 23 ------- .../core/src/app/hooks/use-app-loader.ts | 7 ++- 8 files changed, 29 insertions(+), 160 deletions(-) delete mode 100644 client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyAppLoader.tsx delete mode 100644 client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyAppWrapper.tsx delete mode 100644 client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyWrapper.tsx diff --git a/client/.gitignore b/client/.gitignore index 1984de817..852101131 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -5,6 +5,7 @@ /tmp /out-tsc dist +appLegacyLoader.js # dependencies node_modules diff --git a/client/apps/legacyAppLoader/app.config.ts b/client/apps/legacyAppLoader/app.config.ts index fd7c03e5d..d8e0db361 100644 --- a/client/apps/legacyAppLoader/app.config.ts +++ b/client/apps/legacyAppLoader/app.config.ts @@ -1,24 +1,22 @@ -import { mergeAppConfigs, defineAppConfig } from '@equinor/fusion-framework-cli'; -export default defineAppConfig((_env, { base }) => - mergeAppConfigs( - {}, - { - environment: { - endpoints: { - client: { - baseUri: 'https://backend-fusion-project-portal-test.radix.equinor.com', - defaultScopes: ['api://02f3484c-cad0-4d1d-853d-3a9e604b38f3/access_as_user'], - }, - portal: { - baseUri: 'https://fusion-s-portal-ci.azurewebsites.net', - defaultScopes: ['5a842df8-3238-415d-b168-9f16a6a6031b/.default'], - }, - }, - fusionEnv: 'ci', - loadingText: 'Loading', - appKey: 'handover-garden', - basename: 'localhost:3000/apps/handover-garden/', +import { defineAppConfig } from '@equinor/fusion-framework-cli'; +export default defineAppConfig((_env) => ({ + environment: { + endpoints: { + client: { + baseUri: 'https://backend-fusion-project-portal-test.radix.equinor.com', + defaultScopes: ['api://02f3484c-cad0-4d1d-853d-3a9e604b38f3/access_as_user'], }, - } - ) -); + portal: { + baseUri: 'https://fusion-s-portal-ci.azurewebsites.net', + defaultScopes: ['5a842df8-3238-415d-b168-9f16a6a6031b/.default'], + }, + apps: { + defaultScopes: ['5a842df8-3238-415d-b168-9f16a6a6031b/.default'], + }, + }, + fusionEnv: 'ci', + loadingText: 'Loading', + appKey: 'project-control-and-analysis', + basename: 'localhost:3000/apps/project-control-and-analysis/', + }, +})); diff --git a/client/apps/legacyAppLoader/package.json b/client/apps/legacyAppLoader/package.json index 4b4bba320..046450b84 100644 --- a/client/apps/legacyAppLoader/package.json +++ b/client/apps/legacyAppLoader/package.json @@ -8,7 +8,7 @@ "prebuild": "rm -f ../../packages/portal-client/src/assets/appLegacyLoader.js", "build:appLoader": "fusion-framework-cli app build && mv ./dist/app-bundle.js ../../packages/portal-client/src/assets/appLegacyLoader.js", "build:resources": "tsc && vite build", - "dev:appLoader": "fusion-framework-cli app dev -c vite.config.js", + "dev:appLoader": "fusion-framework-cli app dev", "docker": "cd .. && sh docker-script.sh app-react", "update:fusion": "ncu -i -f /fusion/" }, diff --git a/client/apps/legacyAppLoader/src/config.ts b/client/apps/legacyAppLoader/src/config.ts index 42ed3642e..2576f6d7a 100644 --- a/client/apps/legacyAppLoader/src/config.ts +++ b/client/apps/legacyAppLoader/src/config.ts @@ -13,7 +13,7 @@ interface Client { export const configure: AppModuleInitiator< [NavigationModule], Fusion, - { config: { environment: { endpoints: { client: Client; portal: Client; fusion: Client } } } } + { config: { environment: { endpoints: { client: Client; portal: Client; apps: Client } } } } > = (configurator, { env, fusion }) => { configurator.configureHttpClient('portal-client', env.config?.environment.endpoints.client); configurator.configureHttpClient('portal', env.config?.environment.endpoints.portal); @@ -22,7 +22,7 @@ export const configure: AppModuleInitiator< // configurator.logger.level = 4; configurator.configureHttpClient('app', { baseUri: new URL('/apps-proxy/', location.origin).href, - defaultScopes: env.config?.environment.endpoints.fusion.defaultScopes, + defaultScopes: env.config?.environment.endpoints.apps.defaultScopes, }); enableAppModule(configurator); diff --git a/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyAppLoader.tsx b/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyAppLoader.tsx deleted file mode 100644 index 1e9097b84..000000000 --- a/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyAppLoader.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { lazy } from 'react'; -import AppWrapperLegacy, { getLegacyFusion } from './LegacyAppWrapper'; - -import { AppConfig } from '@equinor/fusion-framework-module-app'; -import { AppManifest as LegacyAppManifest } from '@equinor/fusion'; - -import LegacyAppContainer from '../legacy-interopt/LegacyAppContainer'; -import { MessagePage } from './MessagePage'; -export type LegacyEnv = { - basename: string; - config: AppConfig; - manifest: LegacyAppManifest; -}; - -export const createLegacyAppLoader = (appKey: string) => - lazy(async () => { - const appContainer = getLegacyFusion().app.container as LegacyAppContainer; - const [basename] = window.location.pathname.match(/\/?apps\/[a-z|-]+\//) ?? ['']; - - if (Object.keys(appContainer.allApps).length === 0) { - await appContainer.getAllAsync(); - } - - const config = await appContainer.setCurrentAppAsync(appKey); - - if (!config) { - return { - default: () => , - }; - } - - const env = { - basename, - config, - manifest: { ...appContainer.currentApp } as LegacyAppManifest, - }; - - return { - default: () => ( - <> - - - ), - }; - }); diff --git a/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyAppWrapper.tsx b/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyAppWrapper.tsx deleted file mode 100644 index dce0449d9..000000000 --- a/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyAppWrapper.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import { Suspense, useMemo } from 'react'; - -import { useFramework } from '@equinor/fusion-framework-react'; - -import { GLOBAL_FUSION_CONTEXT_KEY } from '../legacy-interopt/static'; -import { createLegacyRender } from '../legacy-interopt'; - -import { MessagePage } from './MessagePage'; -import { ProgressLoader } from './ProgressLoader'; - -import { LegacyEnv } from './LegacyAppLoader'; - -const DEBUG_LOG = false; -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -export const getLegacyFusion = () => window[GLOBAL_FUSION_CONTEXT_KEY]; -/** - * Legacy wrapper element - * this should be removed in future when applications are moved over to ESM - */ - -export const AppWrapperLegacy = (props: { appKey: string; env: LegacyEnv }): JSX.Element => { - const { appKey, env } = props; - const fusion = useFramework(); - const legacyFusion = getLegacyFusion(); - const manifest = getLegacyFusion().app.container.get(appKey) || null; - - const AppComponent = useMemo(() => { - if (!manifest) { - console.warn('🌍❗️ Portal Legacy:', 'missing application manifest'); - return null; - } - - /** sanity check if the `registerApp` has been loaded */ - if (!manifest.render && !manifest.AppComponent) { - DEBUG_LOG && - console.warn('🌍❗️ Portal Legacy:', 'no render or component, make sure app script is loading'); - return null; - } - - DEBUG_LOG && console.debug('🌍 Portal:', 'creating application component', manifest); - - const render = manifest.render ?? createLegacyRender(manifest, legacyFusion); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - return render(fusion, env); - }, [fusion, legacyFusion, manifest, env]); - - if (!AppComponent) { - return ( - -

Failed to render application, missing app component

-
- ); - } - return ( - }> - - - ); -}; - -export default AppWrapperLegacy; diff --git a/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyWrapper.tsx b/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyWrapper.tsx deleted file mode 100644 index 86014e963..000000000 --- a/client/apps/legacyAppLoader/src/fusion-app-loader/components/LegacyWrapper.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { useFramework } from '@equinor/fusion-framework-react'; -import { PropsWithChildren } from 'react'; - -import { AppModule } from '@equinor/fusion-framework-module-app'; -import { NavigationModule } from '@equinor/fusion-framework-module-navigation'; -import { LegacyFusionWrapper } from '../legacy-interopt/components'; -import { useAppModules } from '@equinor/fusion-framework-react-app'; -import { ProgressLoader } from './ProgressLoader'; - -export const LegacyWrapper = ({ children }: PropsWithChildren) => { - const framework = useFramework<[AppModule, NavigationModule]>(); - const appFramework = useAppModules<[AppModule]>(); - - return ( - } - appFramework={appFramework} - > - {children} - - ); -}; diff --git a/client/packages/core/src/app/hooks/use-app-loader.ts b/client/packages/core/src/app/hooks/use-app-loader.ts index f69988650..bf02c7a53 100644 --- a/client/packages/core/src/app/hooks/use-app-loader.ts +++ b/client/packages/core/src/app/hooks/use-app-loader.ts @@ -53,11 +53,11 @@ export const useAppLoader = (appKey: string) => { environment: { appKey, env: getFusionLegacyEnvIdentifier(), - loadingText: 'Loading', endpoints: { client: getLegacyClientConfig(), - fusion: getLegacyFusionConfig(), + portal: getLegacyFusionConfig(), + apps: getLegacyFusionConfig(), }, }, } as AppConfig< @@ -67,7 +67,8 @@ export const useAppLoader = (appKey: string) => { loadingText: string; endpoints: { client: Client; - fusion: Client; + portal: Client; + apps: Client; }; } >,