fix: change stepper to avoid stepping into wrong states
MODIFY
src/app/components/api-card-list/api-card-list.component.ts
src/app/components/api-card-list/api-card-list.component.ts
/*
- * Copyright 2021 Scheer PAS Schweiz AG
+ * Copyright 2022 Scheer PAS Schweiz AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -146,19 +146,19 @@ export class ApiCardListComponent implements OnInit, OnDestroy {
return this.checkApisDocsInApiVersions(apiSummaries);
})
)
- .subscribe(
- (apiList: IApiSummaryExt[]) => {
+ .subscribe({
+ next: (apiList: IApiSummaryExt[]) => {
this.apis = apiList;
this.loadingSpinnerService.stopWaiting();
this.ready = true;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
- (err: any) => {
+ error: (err: any) => {
console.error(err);
this.error = true;
this.loadingSpinnerService.stopWaiting();
}
- );
+ });
}
private getFeaturedApiList() {
@@ -173,19 +173,19 @@ export class ApiCardListComponent implements OnInit, OnDestroy {
return this.checkApisDocsInApiVersions(apiSummaries);
})
)
- .subscribe(
- (apiList: IApiSummaryExt[]) => {
+ .subscribe({
+ next: (apiList: IApiSummaryExt[]) => {
this.apis = apiList;
this.loadingSpinnerService.stopWaiting();
this.ready = true;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
- (err: any) => {
+ error: (err: any) => {
console.error(err);
this.error = true;
this.loadingSpinnerService.stopWaiting();
}
- );
+ });
}
private checkApisDocsInApiVersions(apiSummaries: IApiSummary[]) {

MODIFY
src/app/components/marketplace-client-app/marketplace-client-app.component.ts
src/app/components/marketplace-client-app/marketplace-client-app.component.ts
/*
- * Copyright 2021 Scheer PAS Schweiz AG
+ * Copyright 2022 Scheer PAS Schweiz AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,21 +81,21 @@ export class MarketplaceClientAppComponent implements OnInit {
.createClient(orgId, this.clientName)
.pipe(
switchMap((client: IClient) => {
- console.log(client.id + 'created');
+ console.log(`${client.id} created`);
this.snackbar.showPrimarySnackBar(
this.translator.instant('COMMON.SUCCESS') as string
);
return this.loadClients();
})
)
- .subscribe(
- (results: [IOrganizationSummary[], IClientSummary[]]) => {
+ .subscribe({
+ next: (results: [IOrganizationSummary[], IClientSummary[]]) => {
this.createTableView(results);
},
- (error: HttpErrorResponse) => {
+ error: (error: HttpErrorResponse) => {
this.snackbar.showErrorSnackBar(error.message, error);
}
- );
+ });
}
public applyFilter(event: Event): void {
@@ -129,17 +129,17 @@ export class MarketplaceClientAppComponent implements OnInit {
return this.loadClients();
})
)
- .subscribe(
- (results: [IOrganizationSummary[], IClientSummary[]]) => {
+ .subscribe({
+ next: (results: [IOrganizationSummary[], IClientSummary[]]) => {
this.createTableView(results);
},
- (error) => {
+ error: (error) => {
console.warn(error);
this.snackbar.showErrorSnackBar(
this.translator.instant('COMMON.ERROR') as string
);
}
- );
+ });
}
private loadClients() {

MODIFY
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.html
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.html
<!--
- ~ Copyright 2021 Scheer PAS Schweiz AG
+ ~ Copyright 2022 Scheer PAS Schweiz AG
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
<div id="center">
<mat-stepper #stepper linear>
- <mat-step label="{{ 'WIZARD.FIRST_STEP_LABEL' | translate }}">
+ <!-- disable default behaviour: [completed]=false-->
+ <!-- By default, the completed attribute of a step returns true if the step is valid (in case of linear stepper) and the user has interacted with the step. -->
+ <mat-step
+ label="{{ 'WIZARD.FIRST_STEP_LABEL' | translate }}"
+ [completed]="false">
<mat-card>
<mat-card-header>
<mat-card-title>{{
</mat-card-actions>
</mat-card>
</mat-step>
- <mat-step label="{{ 'WIZARD.THIRD_STEP_LABEL' | translate }}">
+ <mat-step
+ label="{{ 'WIZARD.THIRD_STEP_LABEL' | translate }}"
+ [completed]="false">
<mat-card>
<mat-card-header>
<mat-card-title>{{

MODIFY
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.ts
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.ts
/*
- * Copyright 2021 Scheer PAS Schweiz AG
+ * Copyright 2022 Scheer PAS Schweiz AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,8 +41,10 @@ import { HttpErrorResponse } from '@angular/common/http';
styleUrls: ['./marketplace-signup-stepper.component.scss']
})
export class MarketplaceSignupStepperComponent implements OnInit {
- selectedClients = new Set<IClientSummary>();
+ // stepper completed checks, must be true to go to next step
agreedTermsAndPrivacy: boolean | undefined;
+
+ selectedClients = new Set<IClientSummary>();
termsEnabled: boolean;
newContractDetails: ISignUpInfo;
contract: IContractExt;
@@ -101,8 +103,8 @@ export class MarketplaceSignupStepperComponent implements OnInit {
.value as IClientSummary;
this.backend
.getContracts(client.organizationId, client.id, '1.0')
- .subscribe(
- (contractSummaries: IContractSummary[]) => {
+ .subscribe({
+ next: (contractSummaries: IContractSummary[]) => {
if (
contractSummaries.some((summary: IContractSummary) => {
return (
@@ -116,13 +118,14 @@ export class MarketplaceSignupStepperComponent implements OnInit {
) {
this.printUserError('WIZARD.CONTRACT_EXISTS');
} else {
- stepper.next();
+ this.goToNextStep(stepper, 0);
}
},
- (error: HttpErrorResponse) => {
+
+ error: (error: HttpErrorResponse) => {
this.snackbar.showErrorSnackBar(error.message, error);
}
- );
+ });
}
nextAfterTermsAgreed(): void {
@@ -173,8 +176,8 @@ export class MarketplaceSignupStepperComponent implements OnInit {
);
})
)
- .subscribe(
- (contract: IContractExt) => {
+ .subscribe({
+ next: (contract: IContractExt) => {
this.snackbar.showPrimarySnackBar(
this.translator.instant('WIZARD.SUCCESS') as string
);
@@ -182,12 +185,13 @@ export class MarketplaceSignupStepperComponent implements OnInit {
if ('AwaitingApproval' === this.contract.client.status) {
void this.router.navigate(['approval']);
} else {
- stepper.next();
+ this.goToNextStep(stepper, 2);
+ this.disablePreviousSteps(stepper);
}
},
- (error: HttpErrorResponse) =>
+ error: (error: HttpErrorResponse) =>
this.snackbar.showErrorSnackBar(error.message, error)
- );
+ });
}
finish(): void {
@@ -198,14 +202,11 @@ export class MarketplaceSignupStepperComponent implements OnInit {
organizationId: this.contract.client.client.organization.id,
entityId: this.contract.client.client.id
})
- .subscribe(
- () => {
- // void response
- },
- (error: HttpErrorResponse) => {
+ .subscribe({
+ error: (error: HttpErrorResponse) => {
this.snackbar.showErrorSnackBar(error.message, error);
}
- );
+ });
void this.router.navigate(['applications'], {
fragment: this.tocService.formatClientId(this.contract)
});
@@ -214,4 +215,21 @@ export class MarketplaceSignupStepperComponent implements OnInit {
private printUserError(key: string): void {
this.snackbar.showErrorSnackBar(this.translator.instant(key) as string);
}
+
+ private disablePreviousSteps(stepper: MatStepper) {
+ // disallow to go back to previous states after confirmation
+ for (let i = 0; i <= 2; i++) {
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ stepper.steps.get(i)!.editable = false;
+ }
+ }
+
+ private goToNextStep(stepper: MatStepper, currentStep: number) {
+ // Set completed step directly to allow going to the next step
+ // See: https://github.com/angular/components/pull/15403
+
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ stepper.steps.get(currentStep)!.completed = true;
+ stepper.next();
+ }
}

MODIFY
src/app/services/api/api.service.ts
src/app/services/api/api.service.ts
/*
- * Copyright 2021 Scheer PAS Schweiz AG
+ * Copyright 2022 Scheer PAS Schweiz AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -116,7 +116,7 @@ export class ApiService {
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
}
console.warn(errorMessage);
- return throwError(errorMessage);
+ return throwError(() => new Error(errorMessage));
}
/**

MODIFY
src/app/services/config/config.service.ts
src/app/services/config/config.service.ts
@@ -25,6 +25,7 @@ import {
} from '../../interfaces/IConfig';
import { HttpClient } from '@angular/common/http';
import * as JSON5 from 'json5';
+import { firstValueFrom } from 'rxjs';
@Injectable({
providedIn: 'root'
@@ -35,9 +36,10 @@ export class ConfigService {
constructor(private http: HttpClient) {}
async readAndEvaluateConfig(): Promise<IConfig> {
- const configAsJson5String = await this.http
- .get('assets/config.json5', { responseType: 'text' })
- .toPromise();
+ const configAsJson5String = await firstValueFrom(
+ this.http.get('assets/config.json5', { responseType: 'text' })
+ );
+
try {
if (configAsJson5String != null) {
this.config = JSON5.parse(configAsJson5String);

MODIFY
src/app/services/initializer/initializer.service.ts
src/app/services/initializer/initializer.service.ts
/*
- * Copyright 2021 Scheer PAS Schweiz AG
+ * Copyright 2022 Scheer PAS Schweiz AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { ConfigService } from '../config/config.service';
+import { firstValueFrom } from 'rxjs';
@Injectable({
providedIn: 'root'
@@ -39,10 +40,7 @@ export class InitializerService {
: 'en';
return new Promise((resolve) => {
- void this.translator
- .use(language)
- .toPromise()
- .then(() => {
+ void firstValueFrom(this.translator.use(language)).then(() => {
resolve();
});
});

fix: change stepper to avoid stepping into wrong states - PAS-2967