Skip to content

Commit

Permalink
fix(vscode): display errors and fix graph edge backgrounds
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Bétrancourt <thomas@betrancourt.net>
  • Loading branch information
rclsilver committed Apr 25, 2023
1 parent 8a417be commit 865467f
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 53 deletions.
86 changes: 43 additions & 43 deletions vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"ts-loader": "^9.2.8",
"typescript": "^4.5.5",
"vsce": "^2.9.2",
"webpack": "^5.70.0",
"webpack": "^5.76.0",
"webpack-cli": "^4.9.2"
}
}
2 changes: 1 addition & 1 deletion vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
}
return Object.assign(result, {
[path]: yamlSchemas[path]
})
});
}, {}), {
[functionSchema]: ["**/functions/*.yaml", "**/functions-*/*.yaml"],
[templateSchema]: ["**/templates/*.yaml", "**/templates-*/*.yaml"]
Expand Down
11 changes: 11 additions & 0 deletions vscode/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vscode/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"d3-drag": "^3.0.0",
"d3-scale": "^4.0.2",
"d3-zoom": "^3.0.0",
"normalize.css": "^8.0.1",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
Expand Down
4 changes: 3 additions & 1 deletion vscode/web/src/app/preview/preview.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<lib-utask-steps-viewer></lib-utask-steps-viewer>
<utask-loader *ngIf="!resolution && !invalid"></utask-loader>
<lib-utask-error-message *ngIf="invalid" [data]="'Unable to display the template'"></lib-utask-error-message>
<lib-utask-steps-viewer *ngIf="resolution && !invalid" [resolution]="resolution"></lib-utask-steps-viewer>
4 changes: 4 additions & 0 deletions vscode/web/src/app/preview/preview.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
align-items: center !important;
background: #333 !important;
}

::ng-deep .edge {
fill: transparent;
}
35 changes: 29 additions & 6 deletions vscode/web/src/app/preview/preview.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AfterViewInit, Component, HostListener, ViewChild } from '@angular/core';
import { AfterViewInit, ChangeDetectorRef, Component, HostListener, ViewChild } from '@angular/core';
import { StepsViewerComponent } from '@ovhcloud/utask-lib';
import Step from '@ovhcloud/utask-lib/lib/@models/step.model';
import Resolution from '@ovhcloud/utask-lib/lib/@models/resolution.model';
import { parse } from 'yaml';

@Component({
Expand All @@ -12,23 +12,46 @@ export class PreviewComponent implements AfterViewInit {
// @ts-ignore
private _vscode = acquireVsCodeApi();

@ViewChild(StepsViewerComponent, { static: true }) viewer!: StepsViewerComponent;
resolution: Resolution | null = null;
invalid = false;

@ViewChild(StepsViewerComponent, { static: false }) viewer!: StepsViewerComponent;

constructor(private _changeDetectorRef: ChangeDetectorRef){}

ngAfterViewInit(): void {
this._vscode.postMessage({
type: 'initialized',
value: true,
})
});
}

private setResolution(resolution: Resolution | null): void {
this.resolution = resolution;
this._changeDetectorRef.detectChanges();
}

private clearResolution(): void {
this.setResolution(null);
}

private setInvalid(invalid: boolean): void {
this.invalid = invalid;
this._changeDetectorRef.detectChanges();
}

@HostListener('window:message', ['$event'])
onRefresh(e: MessageEvent) {
if (e.data.type === 'refresh') {
this.setInvalid(false);
this.clearResolution();

try {
this.viewer.resolution = parse(e.data.value);
this.viewer.clear();
this.setResolution(parse(e.data.value) as Resolution);
this.viewer.fit();
this.viewer.draw();
} catch (e) {
this.setInvalid(true);
console.error(e);
}
}
Expand Down
4 changes: 3 additions & 1 deletion vscode/web/src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '~normalize.css';

body {
height: 100vh;
}
}

0 comments on commit 865467f

Please sign in to comment.