Skip to content

Commit c95ef6b

Browse files
committed
feat: show front-end error in result
1 parent df24cc0 commit c95ef6b

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

zeppelin-web-angular/src/app/pages/workspace/share/result/result.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<div *ngSwitchCase="datasetType.TEXT" class="text-plain"><pre [innerHTML]="plainText"></pre></div>
6969
<div *ngSwitchCase="datasetType.IMG" class="img"><img [src]="imgData" alt="img"></div>
7070
</ng-container>
71+
<div *ngIf="frontEndError" class="text-plain"><pre>{{frontEndError}}</pre></div>
7172
<div *ngIf="angularComponent">
7273
<ng-container *ngComponentOutlet="angularComponent.component;ngModuleFactory: angularComponent.moduleFactory;injector: injector"></ng-container>
7374
</div>

zeppelin-web-angular/src/app/pages/workspace/share/result/result.component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export class NotebookParagraphResultComponent implements OnInit, AfterViewInit,
206206
}
207207

208208
renderDefaultDisplay() {
209+
this.frontEndError = '';
209210
switch (this.result.type) {
210211
case DatasetType.TABLE:
211212
this.renderGraph();
@@ -240,16 +241,17 @@ export class NotebookParagraphResultComponent implements OnInit, AfterViewInit,
240241
}
241242

242243
renderAngular(): void {
243-
try {
244-
this.runtimeCompilerService.createAndCompileTemplate(this.id, this.result.data).then(data => {
244+
this.runtimeCompilerService
245+
.createAndCompileTemplate(this.id, this.result.data)
246+
.then(data => {
245247
this.angularComponent = data;
246-
// this.angularComponent.moduleFactory
248+
this.cdr.markForCheck();
249+
})
250+
.catch(error => {
251+
this.angularComponent = null;
252+
this.frontEndError = error.message;
247253
this.cdr.markForCheck();
248254
});
249-
} catch (e) {
250-
this.frontEndError = e.message;
251-
console.log(e);
252-
}
253255
}
254256

255257
renderText(): void {

zeppelin-web-angular/src/app/services/runtime-compiler.service.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
*/
1212

1313
import {
14+
ChangeDetectionStrategy,
1415
Compiler,
1516
Component,
1617
Injectable,
17-
ModuleWithComponentFactories,
1818
NgModule,
1919
NgModuleFactory,
20+
NO_ERRORS_SCHEMA,
2021
Type
2122
} from '@angular/core';
2223

24+
import { CompileDirectiveMetadata, HtmlParser, TemplateParser } from '@angular/compiler';
2325
import { RuntimeDynamicModuleModule } from '@zeppelin/core';
2426
import { NgZService } from './ng-z.service';
2527

@@ -33,16 +35,17 @@ export class DynamicTemplate {
3335
) {}
3436
}
3537

38+
export class DynamicTemplateError {
39+
constructor(public message: string) {}
40+
}
41+
3642
@Injectable({
3743
providedIn: 'root'
3844
})
3945
export class RuntimeCompilerService {
40-
// tslint:disable-next-line:no-any
41-
private compiledModule?: ModuleWithComponentFactories<any>;
42-
4346
public async createAndCompileTemplate(paragraphId: string, template: string): Promise<DynamicTemplate> {
4447
const ngZService = this.ngZService;
45-
const dynamicComponent = Component({ template: template })(
48+
const dynamicComponent = Component({ template: template, selector: `dynamic-${paragraphId}` })(
4649
class DynamicTemplateComponent {
4750
z = {
4851
set: (key: string, value, id: string) => ngZService.setContextValue(key, value, id),
@@ -63,8 +66,13 @@ export class RuntimeCompilerService {
6366
imports: [RuntimeDynamicModuleModule]
6467
})(class DynamicModule {});
6568

66-
this.compiledModule = await this.compiler.compileModuleAndAllComponentsAsync(dynamicModule);
67-
return new DynamicTemplate(template, dynamicComponent, this.compiledModule.ngModuleFactory);
69+
try {
70+
this.compiler.clearCache();
71+
const compiledModule = await this.compiler.compileModuleAndAllComponentsAsync(dynamicModule);
72+
return new DynamicTemplate(template, dynamicComponent, compiledModule.ngModuleFactory);
73+
} catch (e) {
74+
throw new DynamicTemplateError(`${e}`);
75+
}
6876
}
6977

7078
constructor(private compiler: Compiler, private ngZService: NgZService) {}

0 commit comments

Comments
 (0)