Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Improve loading logic in LegacyAppContainer, by loading app… #828

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pr-828-2137854066.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

---
"fusion-project-portal": patch
---
Improve loading logic in LegacyAppContainer, by loading app from new app api with proxy
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ export class LegacyAppContainer extends EventEmitter<AppContainerEvents> {
* 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) {
Expand Down Expand Up @@ -285,8 +285,9 @@ export class LegacyAppContainer extends EventEmitter<AppContainerEvents> {
return this.updateComplete;
}

async #loadScript(appKey: string): Promise<void> {
async #loadScript(manifest: AppManifest): Promise<void> {
return new Promise((resolve, reject) => {
const { appKey, build } = manifest;
const script = document.createElement('script');
script.async = true;
script.id = appKey;
Expand All @@ -296,16 +297,15 @@ export class LegacyAppContainer extends EventEmitter<AppContainerEvents> {
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}`;
});
}

#update(): void {
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();
Expand Down