Skip to content

Commit

Permalink
fix(context): load default context when context is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Jun 4, 2020
1 parent e308859 commit 42d7baf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions packages/context/src/lib/context-manager/shared/context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ export class ContextService {
// to track the current tools
private tools: Tool[];

get defaultContextUri(): string {
return this._defaultContextUri || this.options.defaultContextUri;
}
set defaultContextUri(uri: string) {
this._defaultContextUri = uri;
}
private _defaultContextUri: string;

constructor(
private http: HttpClient,
private authService: AuthService,
Expand Down Expand Up @@ -275,17 +283,17 @@ export class ContextService {
if (!direct && this.baseUrl && this.authService.authenticated) {
this.getDefault().subscribe(
(_context: DetailedContext) => {
this.options.defaultContextUri = _context.uri;
this.defaultContextUri = _context.uri;
this.addContextToList(_context);
this.setContext(_context);
},
() => {
this.defaultContextId$.next(undefined);
this.loadContext(this.options.defaultContextUri);
this.loadContext(this.defaultContextUri);
}
);
} else {
this.loadContext(this.options.defaultContextUri);
this.loadContext(this.defaultContextUri);
}
};

Expand All @@ -294,7 +302,7 @@ export class ContextService {
const contextParam = params[this.route.options.contextKey as string];
let direct = false;
if (contextParam) {
this.options.defaultContextUri = contextParam;
this.defaultContextUri = contextParam;
direct = true;
}
loadFct(direct);
Expand All @@ -318,6 +326,9 @@ export class ContextService {
},
err => {
contexts$$.unsubscribe();
if (uri !== this.options.defaultContextUri) {
this.loadContext(this.options.defaultContextUri);
}
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/context/src/locale/en.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"uriRequired": "ID required"
},
"invalid": {
"text": "Context '{{value}}' is invalid",
"text": "Context '{{value}}' is invalid. The default context was loaded.",
"title": "Invalid context"
},
"managePermissions": "Manage permissions context",
Expand Down
2 changes: 1 addition & 1 deletion packages/context/src/locale/fr.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"uriRequired": "L'identifiant est obligatoire"
},
"invalid": {
"text": "Le contexte \"{{value}}\" est invalide",
"text": "Le contexte \"{{value}}\" est invalide. Le contexte par défaut a été chargé.",
"title": "Contexte invalide"
},
"managePermissions": "Gérer les permissions du contexte",
Expand Down

0 comments on commit 42d7baf

Please sign in to comment.