Skip to content

Commit 0a1cb31

Browse files
authored
[bugfix] Fix value passing bug in New Experiment form (#2027)
* [bugfix] Fix value passing bug in New Experiment form Add missing logic in New Experiment form in order to pass the value of the editor content in Metrics Collector tab, when Kind is set to Custom. * Adjust unit tests for custom yaml metrics collector
1 parent d97c8ae commit 0a1cb31

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/experiment-creation.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ ExperimentFormServiceStub = {
8181
path: new FormControl(),
8282
scheme: new FormControl(),
8383
host: new FormControl(),
84+
customYaml: new FormControl(),
8485
}),
8586
createTrialTemplateForm: () =>
8687
new FormGroup({

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/metrics-collector/metrics-collector.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<ng-container *ngSwitchCase="kind.CUSTOM">
7171
<lib-monaco-editor
7272
[(text)]="customYaml"
73+
(textChange)="onTextChange()"
7374
[language]="'yaml'"
7475
[readOnly]="false"
7576
[width]="375"

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/metrics-collector/metrics-collector.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('FormMetricsCollectorComponent', () => {
3838
scheme: new FormControl(),
3939
host: new FormControl(),
4040
prometheus: new FormControl(),
41+
customYaml: new FormControl(),
4142
});
4243
fixture.detectChanges();
4344
});

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/metrics-collector/metrics-collector.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ import { CollectorKind } from 'src/app/enumerations/metrics-collector';
1010
export class FormMetricsCollectorComponent implements OnInit {
1111
@Input() formGroup: FormGroup;
1212
kind = CollectorKind;
13-
customYaml =
14-
'name: metrics-collector\nimage: <collector-image>\nresources: {}';
13+
customYaml: string;
1514

1615
constructor() {}
1716

18-
ngOnInit() {}
17+
ngOnInit() {
18+
this.customYaml = this.formGroup.get('customYaml').value;
19+
}
20+
21+
onTextChange() {
22+
this.formGroup.patchValue({ customYaml: this.customYaml });
23+
}
1924
}

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/yaml-modal/yaml-modal.component.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CommonModule } from '@angular/common';
22
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
33
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
44
import { MatDialogModule } from '@angular/material/dialog';
5+
import { MatSnackBarModule } from '@angular/material/snack-bar';
56
import { EditorModule, FormModule } from 'kubeflow';
67

78
import { YamlModalComponent } from './yaml-modal.component';
@@ -13,7 +14,13 @@ describe('YamlModalComponent', () => {
1314
beforeEach(
1415
waitForAsync(() => {
1516
TestBed.configureTestingModule({
16-
imports: [CommonModule, MatDialogModule, FormModule, EditorModule],
17+
imports: [
18+
CommonModule,
19+
MatDialogModule,
20+
FormModule,
21+
EditorModule,
22+
MatSnackBarModule,
23+
],
1724
declarations: [YamlModalComponent],
1825
providers: [
1926
{ provide: MatDialogRef, useValue: {} },

pkg/new-ui/v1beta1/frontend/src/app/pages/experiment-creation/yaml-modal/yaml-modal.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, Input, Inject } from '@angular/core';
22
import { load, dump } from 'js-yaml';
3+
import { SnackBarService, SnackType } from 'kubeflow';
34
import {
45
MatDialog,
56
MatDialogRef,
@@ -17,12 +18,17 @@ export class YamlModalComponent {
1718
constructor(
1819
public dialogRef: MatDialogRef<YamlModalComponent>,
1920
@Inject(MAT_DIALOG_DATA) public data: any,
21+
private snack: SnackBarService,
2022
) {
2123
this.yaml = dump(data);
2224
}
2325

2426
save() {
25-
this.dialogRef.close(load(this.yaml));
27+
try {
28+
this.dialogRef.close(load(this.yaml));
29+
} catch (e) {
30+
this.snack.open(`${e.reason}`, SnackType.Error, 4000);
31+
}
2632
}
2733

2834
close() {

pkg/new-ui/v1beta1/frontend/src/app/services/experiment-form.service.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ export class ExperimentFormService {
207207
host: this.builder.control(''),
208208
httpHeaders: this.builder.array([]),
209209
}),
210+
customYaml:
211+
'name: metrics-collector\nimage: <collector-image>\nresources: {}',
210212
});
211213
}
212214

@@ -391,8 +393,17 @@ export class ExperimentFormService {
391393
return metrics;
392394
}
393395

394-
/* TODO(kimwnasptd): We need to handle the Custom case */
395396
if (kind === 'Custom') {
397+
delete metrics.source.fileSystemPath;
398+
try {
399+
metrics.collector.customCollector = load(group.get('customYaml').value);
400+
} catch (e) {
401+
this.snack.open(
402+
'Metrics Colletor(Custom): ' + `${e.reason}`,
403+
SnackType.Error,
404+
4000,
405+
);
406+
}
396407
return metrics;
397408
}
398409

@@ -421,7 +432,11 @@ export class ExperimentFormService {
421432
try {
422433
trialTemplate.trialSpec = load(formValue.yaml);
423434
} catch (e) {
424-
this.snack.open(`${e.reason}`, SnackType.Warning, 4000);
435+
this.snack.open(
436+
'Trial Template: ' + `${e.reason}`,
437+
SnackType.Error,
438+
4000,
439+
);
425440
}
426441

427442
return trialTemplate;

0 commit comments

Comments
 (0)