Skip to content

Commit

Permalink
kwa(front): Update the use of SnackBarService (#2113)
Browse files Browse the repository at this point in the history
* build: Update COMMIT file

Signed-off-by: Orfeas Kourkakis <orfeas@arrikto.com>

* kwa(front): Update the use of SnackBarService

Update the use of SnackBarService in order to pass required data via a
`config` object and provide MAT_SNACK_BAR_DEFAULT_OPTIONS.

Signed-off-by: Orfeas Kourkakis <orfeas@arrikto.com>

---------

Signed-off-by: Orfeas Kourkakis <orfeas@arrikto.com>
  • Loading branch information
orfeas-k authored Feb 22, 2023
1 parent 22babe4 commit b6afce7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/new-ui/v1beta1/frontend/COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8dcfe792
046c6d3c8
17 changes: 16 additions & 1 deletion pkg/new-ui/v1beta1/frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ import { AppComponent } from './app.component';
import { ExperimentsModule } from './pages/experiments/experiments.module';
import { ExperimentDetailsModule } from './pages/experiment-details/experiment-details.module';
import { ExperimentCreationModule } from './pages/experiment-creation/experiment-creation.module';
import {
MatSnackBarConfig,
MAT_SNACK_BAR_DEFAULT_OPTIONS,
} from '@angular/material/snack-bar';

/**
* MAT_SNACK_BAR_DEFAULT_OPTIONS values can be found
* here
* https://github.com/angular/components/blob/main/src/material/snack-bar/snack-bar-config.ts#L25-L58
*/
const KwaSnackBarConfig: MatSnackBarConfig = {
duration: 4000,
};

@NgModule({
declarations: [AppComponent],
Expand All @@ -20,7 +33,9 @@ import { ExperimentCreationModule } from './pages/experiment-creation/experiment
ReactiveFormsModule,
ExperimentCreationModule,
],
providers: [],
providers: [
{ provide: MAT_SNACK_BAR_DEFAULT_OPTIONS, useValue: KwaSnackBarConfig },
],
bootstrap: [AppComponent],
})
export class AppModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
EXPERIMENT_KIND,
} from 'src/app/models/experiment.k8s.model';
import { KWABackendService } from 'src/app/services/backend.service';
import { NamespaceService, SnackType, SnackBarService } from 'kubeflow';
import {
NamespaceService,
SnackType,
SnackBarService,
SnackBarConfig,
} from 'kubeflow';
import { pipe } from 'rxjs';
import { take } from 'rxjs/operators';
import { EarlyStoppingAlgorithmsEnum } from 'src/app/enumerations/algorithms.enum';
Expand Down Expand Up @@ -118,11 +123,14 @@ export class ExperimentCreationComponent implements OnInit {

this.backend.createExperiment(exp).subscribe({
next: () => {
this.snack.open(
'Experiment submitted successfully.',
SnackType.Success,
3000,
);
const config: SnackBarConfig = {
data: {
msg: 'Experiment submitted successfully.',
snackType: SnackType.Success,
},
duration: 3000,
};
this.snack.open(config);
this.returnToExperiments();
},
error: err => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Input, Inject } from '@angular/core';
import { load, dump } from 'js-yaml';
import { SnackBarService, SnackType } from 'kubeflow';
import { SnackBarConfig, SnackBarService, SnackType } from 'kubeflow';
import {
MatDialog,
MatDialogRef,
Expand All @@ -27,7 +27,13 @@ export class YamlModalComponent {
try {
this.dialogRef.close(load(this.yaml));
} catch (e) {
this.snack.open(`${e.reason}`, SnackType.Error, 4000);
const config: SnackBarConfig = {
data: {
msg: `${e.reason}`,
snackType: SnackType.Error,
},
};
this.snack.open(config);
}
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/new-ui/v1beta1/frontend/src/app/services/backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Observable, throwError } from 'rxjs';
import {
BackendService,
K8sObject,
SnackBarConfig,
SnackBarService,
SnackType,
} from 'kubeflow';
Expand Down Expand Up @@ -33,7 +34,14 @@ export class KWABackendService extends BackendService {
}
}

this.snack.open(msg, SnackType.Error, 8000);
const config: SnackBarConfig = {
data: {
msg,
snackType: SnackType.Error,
},
duration: 8000,
};
this.snack.open(config);

return throwError(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
EarlyStoppingAlgorithmsEnum,
} from '../enumerations/algorithms.enum';
import { createParameterGroup, createNasOperationGroup } from '../shared/utils';
import { SnackBarService, SnackType } from 'kubeflow';
import { SnackBarConfig, SnackBarService, SnackType } from 'kubeflow';
import { load } from 'js-yaml';
import {
ObjectiveSpec,
Expand Down Expand Up @@ -398,11 +398,13 @@ export class ExperimentFormService {
try {
metrics.collector.customCollector = load(group.get('customYaml').value);
} catch (e) {
this.snack.open(
'Metrics Colletor(Custom): ' + `${e.reason}`,
SnackType.Error,
4000,
);
const config: SnackBarConfig = {
data: {
msg: 'Metrics Colletor(Custom): ' + `${e.reason}`,
snackType: SnackType.Error,
},
};
this.snack.open(config);
}
return metrics;
}
Expand Down Expand Up @@ -432,11 +434,13 @@ export class ExperimentFormService {
try {
trialTemplate.trialSpec = load(formValue.yaml);
} catch (e) {
this.snack.open(
'Trial Template: ' + `${e.reason}`,
SnackType.Error,
4000,
);
const config: SnackBarConfig = {
data: {
msg: 'Trial Template: ' + `${e.reason}`,
snackType: SnackType.Error,
},
};
this.snack.open(config);
}

return trialTemplate;
Expand Down

0 comments on commit b6afce7

Please sign in to comment.