-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move legacy app loader and fix loading
- Loading branch information
Showing
58 changed files
with
6,434 additions
and
7,238 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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/', | ||
}, | ||
} | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineAppManifest, mergeManifests } from '@equinor/fusion-framework-cli'; | ||
|
||
export default defineAppManifest((env, { base }) => { | ||
return mergeManifests(base, { | ||
name: 'App-loader', | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "fusion-app-loader", | ||
"version": "1.0.0", | ||
"description": "", | ||
"type": "module", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"prebuild": "rm -f ../../../client/packages/portal-client/src/assets/appLegacyLoader.js", | ||
"build": "fusion-framework-cli app build && mv ./dist/app-bundle.js ../../../client/packages/portal-client/src/assets/appLegacyLoader.js", | ||
"build:resources": "tsc && vite build", | ||
"dev:appLoader": "fusion-framework-cli app dev -c vite.config.js", | ||
"docker": "cd .. && sh docker-script.sh app-react", | ||
"update:fusion": "ncu -i -f /fusion/" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@equinor/eds-core-react": "^0.42.0", | ||
"@equinor/fusion": "^3.4.16", | ||
"@equinor/fusion-components": "^2.12.0", | ||
"@equinor/fusion-framework-app": "^9.1.10-next-9f6eec8c5a4cb3dd430fc6bee227442a3dc28bb8", | ||
"@equinor/fusion-framework-module-app": "^6.0.0-next-9f6eec8c5a4cb3dd430fc6bee227442a3dc28bb8", | ||
"@equinor/fusion-framework-module-http": "^6.2.0", | ||
"@equinor/fusion-framework-module-navigation": "^4.0.7", | ||
"@equinor/fusion-framework-react": "^7.3.0-next-9f6eec8c5a4cb3dd430fc6bee227442a3dc28bb8", | ||
"@equinor/fusion-framework-react-app": "^5.2.10-next-9f6eec8c5a4cb3dd430fc6bee227442a3dc28bb8", | ||
"@equinor/fusion-observable": "^8.4.1", | ||
"@equinor/fusion-react-styles": "^0.6.2", | ||
"@types/react": "^17.0.70", | ||
"@types/react-dom": "^17.0.25", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", | ||
"react-router": "^5.2.0", | ||
"react-router-dom": "^5.2.0", | ||
"rxjs": "^7.8.1", | ||
"styled-components": "^6.1.6", | ||
"typesafe-actions": "^5.1.0", | ||
"typescript": "^5.1.3", | ||
"vite": "^5.2.14", | ||
"vite-tsconfig-paths": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"@equinor/fusion-framework-cli": "^10.0.0-next-499bdf0f6597dbdcfdabd563b94ed08de36bbfe4", | ||
"@types/react-router-dom": "^5.3.3", | ||
"vite-plugin-static-copy": "^0.17.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { NavigationModule } from '@equinor/fusion-framework-module-navigation'; | ||
import { LegacyFusionWrapper } from './app-loader'; | ||
import { AppModuleLoader } from './app-loader/components/AppModuleLoader'; | ||
|
||
import { AppModule } from '@equinor/fusion-framework-module-app'; | ||
import { Fusion, useFramework } from '@equinor/fusion-framework-react'; | ||
|
||
import { ComponentRenderArgs, makeComponent, useAppModules } from '@equinor/fusion-framework-react-app'; | ||
|
||
import { ProgressLoader } from './app-loader/components/ProgressLoader'; | ||
|
||
import { addGlobalDependencies } from './globalResources'; | ||
import { Suspense, createElement } from 'react'; | ||
import configure from './config'; | ||
|
||
addGlobalDependencies(); | ||
|
||
export const App = (props: { | ||
fusion: Fusion; | ||
env: { | ||
config: { | ||
environment: { appKey: string; fusionEnv: string; loadingText?: string }; | ||
}; | ||
}; | ||
}) => { | ||
const fusion = useFramework<[AppModule, NavigationModule]>(); | ||
const appFramework = useAppModules<[AppModule]>(); | ||
return ( | ||
<LegacyFusionWrapper | ||
framework={fusion} | ||
options={{ | ||
loadBundlesFromDisk: false, | ||
environment: { | ||
env: props.env.config.environment.fusionEnv, | ||
}, | ||
}} | ||
loader={<ProgressLoader title={props.env.config.environment.loadingText || 'Loading'} />} | ||
appFramework={appFramework} | ||
> | ||
<AppModuleLoader appKey={props.env?.config.environment.appKey} /> | ||
</LegacyFusionWrapper> | ||
); | ||
}; | ||
|
||
const appComponent = (args: any) => createElement(App, args); | ||
|
||
/** create React render root component */ | ||
export const createApp = (args: ComponentRenderArgs) => makeComponent(appComponent(args), args, configure as any); | ||
|
||
export const AppComponent = (args: ComponentRenderArgs) => { | ||
const AppComponent = createApp(args); | ||
return ( | ||
<Suspense fallback={<></>}> | ||
<AppComponent /> | ||
</Suspense> | ||
); | ||
}; |
61 changes: 61 additions & 0 deletions
61
client/apps/fusion-app-loader/src/app-loader/components/App.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { NavigationModule } from '@equinor/fusion-framework-module-navigation'; | ||
import { LegacyFusionWrapper } from './app-loader'; | ||
import { AppModuleLoader } from './app-loader/components/AppModuleLoader'; | ||
|
||
import { AppModule } from '@equinor/fusion-framework-module-app'; | ||
import { Fusion, useFramework } from '@equinor/fusion-framework-react'; | ||
|
||
import { ComponentRenderArgs, makeComponent, useAppModules } from '@equinor/fusion-framework-react-app'; | ||
|
||
import { ProgressLoader } from './app-loader/components/ProgressLoader'; | ||
|
||
import { addGlobalDependencies } from './globalResources'; | ||
import { Suspense, createElement } from 'react'; | ||
import configure from './config'; | ||
|
||
addGlobalDependencies(); | ||
|
||
export const App = (props: { | ||
fusion: Fusion; | ||
env: { | ||
config: { | ||
environment: { appKey: string; env: string; loadingText?: string }; | ||
}; | ||
}; | ||
}) => { | ||
const fusion = useFramework<[AppModule, NavigationModule]>(); | ||
const appFramework = useAppModules<[AppModule]>(); | ||
|
||
return ( | ||
<LegacyFusionWrapper | ||
framework={fusion} | ||
options={{ | ||
loadBundlesFromDisk: false, | ||
environment: { | ||
env: props.env.config.environment.env, | ||
}, | ||
}} | ||
loader={<ProgressLoader title={props.env.config.environment.loadingText || 'Loading'} />} | ||
appFramework={appFramework} | ||
> | ||
<AppModuleLoader appKey={props.env?.config.environment.appKey} /> | ||
</LegacyFusionWrapper> | ||
); | ||
}; | ||
|
||
const appComponent = (args: any) => createElement(App, args); | ||
|
||
/** create React render root component */ | ||
export const createApp = (args: ComponentRenderArgs) => { | ||
return makeComponent(appComponent(args), args, configure as any); | ||
}; | ||
|
||
export const AppComponent = (args: ComponentRenderArgs) => { | ||
const AppComponent = createApp(args); | ||
return 'hello'; | ||
return ( | ||
<Suspense fallback={<></>}> | ||
<AppComponent /> | ||
</Suspense> | ||
); | ||
}; |
File renamed without changes.
45 changes: 45 additions & 0 deletions
45
client/apps/fusion-app-loader/src/app-loader/components/LegacyAppLoader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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: () => <MessagePage type="Warning" title="No config" />, | ||
}; | ||
} | ||
|
||
const env = { | ||
basename, | ||
config, | ||
manifest: { ...appContainer.currentApp } as LegacyAppManifest, | ||
}; | ||
|
||
return { | ||
default: () => ( | ||
<> | ||
<AppWrapperLegacy appKey={appKey} env={env} /> | ||
</> | ||
), | ||
}; | ||
}); |
63 changes: 63 additions & 0 deletions
63
client/apps/fusion-app-loader/src/app-loader/components/LegacyAppWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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 ( | ||
<MessagePage title="Loader Error"> | ||
<p>Failed to render application, missing app component</p> | ||
</MessagePage> | ||
); | ||
} | ||
return ( | ||
<Suspense fallback={<ProgressLoader title="Loading" />}> | ||
<AppComponent /> | ||
</Suspense> | ||
); | ||
}; | ||
|
||
export default AppWrapperLegacy; |
23 changes: 23 additions & 0 deletions
23
client/apps/fusion-app-loader/src/app-loader/components/LegacyWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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<unknown>) => { | ||
const framework = useFramework<[AppModule, NavigationModule]>(); | ||
const appFramework = useAppModules<[AppModule]>(); | ||
|
||
return ( | ||
<LegacyFusionWrapper | ||
framework={framework} | ||
loader={<ProgressLoader title="Loading" />} | ||
appFramework={appFramework} | ||
> | ||
{children} | ||
</LegacyFusionWrapper> | ||
); | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.