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

fix: model tab not always loading #300

Merged
merged 2 commits into from
Jul 27, 2021
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
4 changes: 4 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class AppComponent implements OnInit {
}
});

this.namespaceTracker.activateNamespaceChanged.subscribe((newNamespace) => {
this.checkIfModelsAvailable(newNamespace);
});

// Keep track of the current url so we know what part of the app we are in and highlight it in the
// nav bar accordingly.
this.router.events
Expand Down
12 changes: 7 additions & 5 deletions src/app/models/models.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface KfservingMessage {
styleUrls: ['./models.component.scss']
})
export class ModelsComponent implements OnInit {
static maxCommunicationAttempts = 10;
static maxCommunicationAttempts = 20;
private communicationAttempts = 0;

// baseUrl is the base path to the kfserving service
Expand Down Expand Up @@ -75,7 +75,6 @@ export class ModelsComponent implements OnInit {
});

window.addEventListener('message', (event) => {
console.log(event);
const payload = event.data as KfservingMessage;
if (!payload) {
return;
Expand Down Expand Up @@ -131,6 +130,7 @@ export class ModelsComponent implements OnInit {

this.url = this.domSanitizer.bypassSecurityTrustResourceUrl(this.generateKfservingUrl());


this.sendingNamespace = setInterval(() => {
if (!this.sendingNamespace) {
return;
Expand All @@ -141,10 +141,12 @@ export class ModelsComponent implements OnInit {
return;
}

const contentWindow = this.modelElement.nativeElement.contentWindow as Window;
contentWindow.postMessage(this.namespace, '*');
if (this.modelElement) {
const contentWindow = this.modelElement.nativeElement.contentWindow as Window;
contentWindow.postMessage(this.namespace, '*');

this.communicationAttempts++;
this.communicationAttempts++;
}
}, 350);
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/namespace-select/namespace-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class NamespaceSelectComponent implements OnInit {
private appRouter: AppRouter,
private namespaceService: NamespaceTracker,
private namespaceApiService: NamespaceServiceService,
public namespaceTracker: NamespaceTracker,
private router: Router,
private snackbar: MatSnackBar) {
}
Expand Down Expand Up @@ -46,6 +47,7 @@ export class NamespaceSelectComponent implements OnInit {
}

onNamespaceSelected(namespace: string) {
this.namespaceTracker.activeNamespace = namespace;
return this.appRouter.navigateToNamespaceHomepage(namespace);
}
}
14 changes: 13 additions & 1 deletion src/app/namespace/namespace-tracker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@ import { Namespace, NamespaceServiceService } from '../../api';
export class NamespaceTracker {
private gettingNamespaces = false;

activeNamespace = 'default';
// tslint:disable-next-line:variable-name
private _activeNamespace = 'default';
get activeNamespace(): string {
return this._activeNamespace;
}

set activeNamespace(value: string) {
this._activeNamespace = value;

this.activateNamespaceChanged.emit(value);
}

namespaces = new Array<Namespace>();

@Output() namespacesChanged = new EventEmitter();
@Output() activateNamespaceChanged = new EventEmitter<string>();

constructor(private namespaceService: NamespaceServiceService) {
}
Expand Down