Browse Source

Fix device install wizard navigation via stepper header (#16265)

Clicking a step in the stepper header bypassed nextStep(), so the
Provisioning step was never activated and rendered empty, and the
Configuration form values were not collected. Step activation now runs
on the stepper selectionChange, and instruction steps are marked
completed once shown so the header can move past them like the Next
button does.
pull/16134/merge
Dmytro Pinkevych 2 months ago
committed by GitHub
parent
commit
237025d80e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html
  2. 38
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts

3
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html

@ -190,7 +190,8 @@
<div mat-dialog-content>
<mat-stepper #installStepper
[linear]="true"
labelPosition="bottom">
labelPosition="bottom"
(selectionChange)="onStepSelectionChange($event)">
<ng-template matStepperIcon="edit">
<mat-icon>done</mat-icon>
</ng-template>

38
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts

@ -12,6 +12,7 @@ import { AppState } from '@core/core.state';
import { DialogComponent } from '@shared/components/dialog.component';
import { UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { MatStepper } from '@angular/material/stepper';
import { StepperSelectionEvent } from '@angular/cdk/stepper';
import { firstValueFrom } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
import { PageLink } from '@shared/models/page/page-link';
@ -261,10 +262,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
connectivityStep.completed = true;
this.cdr.detectChanges();
// Wait for new mat-step children to register before advancing.
setTimeout(() => {
this.stepper?.next();
this.onStepActivated();
}, 0);
setTimeout(() => this.stepper?.next(), 0);
return;
}
this.startWizard();
@ -315,12 +313,9 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
if (!step) {
return;
}
if (step.type === 'form') {
if (step.formGroup?.invalid) {
step.formGroup.markAllAsTouched();
return;
}
Object.assign(this.formValues, step.formGroup.getRawValue());
if (step.type === 'form' && step.formGroup?.invalid) {
step.formGroup.markAllAsTouched();
return;
}
if (this.isLastWizardStep) {
this.done();
@ -329,7 +324,22 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
step.completed = true;
this.cdr.detectChanges();
this.stepper.next();
this.onStepActivated();
}
onStepSelectionChange(event: StepperSelectionEvent): void {
if (event.selectedIndex <= event.previouslySelectedIndex) {
return;
}
// Forward moves can come from the stepper header, which bypasses nextStep(),
// so commit every step being passed over here.
for (let i = event.previouslySelectedIndex; i < event.selectedIndex; i++) {
const ws = this.wizardSteps[i];
if (ws.type === 'form') {
Object.assign(this.formValues, ws.formGroup.getRawValue());
}
ws.completed = true;
}
this.onStepActivated(this.wizardSteps[event.selectedIndex]);
}
get primaryEntityAction(): { url: string; label: string } | null {
@ -704,13 +714,14 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
return field.defaultValue ?? (field.type === FormFieldType.BOOLEAN ? false : '');
}
private onStepActivated(): void {
const step = this.currentWizardStep;
private onStepActivated(step = this.currentWizardStep): void {
if (!step) {
return;
}
if (step.type === 'instruction') {
step.markdown = this.zipFiles.get(step.rawSteps[0].file) || '';
// Nothing to validate here, so the linear stepper header may move past it right away.
step.completed = true;
} else if (step.type === 'progress' && !step.progressDone) {
if (this.reviewMode) {
this.showCompletedEntitySteps(step);
@ -826,7 +837,6 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
await this.delay(500);
this.stepper.next();
this.cdr.detectChanges();
this.onStepActivated();
}
}

Loading…
Cancel
Save