From 6e599cf8fc3710c8f01465682e9c582e1db5e0f9 Mon Sep 17 00:00:00 2001 From: Christopher Berge Hove Date: Tue, 22 Oct 2024 10:44:38 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20Improve=20loading=20logic=20in=20Le?= =?UTF-8?q?gacyAppContainer,=20by=20loading=20app=E2=80=A6=20(#828)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Noggling --- .changeset/pr-828-2137854066.md | 5 +++++ .../legacy-interopt/LegacyAppContainer.ts | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .changeset/pr-828-2137854066.md diff --git a/.changeset/pr-828-2137854066.md b/.changeset/pr-828-2137854066.md new file mode 100644 index 000000000..6b2fd75bf --- /dev/null +++ b/.changeset/pr-828-2137854066.md @@ -0,0 +1,5 @@ + +--- +"fusion-project-portal": patch +--- +Improve loading logic in LegacyAppContainer, by loading app from new app api with proxy diff --git a/client/apps/legacyAppLoader/src/app-loader/legacy-interopt/LegacyAppContainer.ts b/client/apps/legacyAppLoader/src/app-loader/legacy-interopt/LegacyAppContainer.ts index 7560b2296..26a07c647 100644 --- a/client/apps/legacyAppLoader/src/app-loader/legacy-interopt/LegacyAppContainer.ts +++ b/client/apps/legacyAppLoader/src/app-loader/legacy-interopt/LegacyAppContainer.ts @@ -228,13 +228,13 @@ export class LegacyAppContainer extends EventEmitter { * assume if the manifest missing AppComponent or render, that loading is required */ - if (!AppComponent && !render) { - await this.#loadScript(key); + const manifest = this.#manifests.value[appKey] as unknown as AppManifest; + + if (!AppComponent && !render && manifest.build) { + await this.#loadScript(manifest); } await new Promise((resolve) => window.requestAnimationFrame(resolve)); - const manifest = this.#manifests.value[appKey] as unknown as AppManifest; - const currentApp = appProvider.current; if (currentApp && currentApp.appKey === appKey) { @@ -285,8 +285,9 @@ export class LegacyAppContainer extends EventEmitter { return this.updateComplete; } - async #loadScript(appKey: string): Promise { + async #loadScript(manifest: AppManifest): Promise { return new Promise((resolve, reject) => { + const { appKey, build } = manifest; const script = document.createElement('script'); script.async = true; script.id = appKey; @@ -296,8 +297,7 @@ export class LegacyAppContainer extends EventEmitter { script.addEventListener('load', () => resolve()); script.addEventListener('abort', () => reject()); script.addEventListener('error', () => reject()); - // Todo: Fix uri to mach the new structure - script.src = `${window['clientBaseUri']}/api/bundles/${appKey}.js`; + script.src = `/apps-proxy/bundles/apps/${appKey}/${build?.version}/${build?.entryPoint}`; }); } @@ -305,7 +305,7 @@ export class LegacyAppContainer extends EventEmitter { console.log('Updating'); this.#updateTask = new Promise((resolve, reject) => { this.#updateTask.state = 'pending'; - this.#appModules.app.getAllAppManifests().subscribe({ + this.#appModules.app.getAppManifests({ filterByCurrentUser: true }).subscribe({ complete: () => { this.#updateTask.state = 'fulfilled'; this.#lastUpdated = Date.now();