Browse Source
fix(iot-hub): re-resolve install instructions after going back and changing a form
Instruction steps stay rendered, and tb-iot-hub-markdown resolved variables
only when its data changed. After Back, a corrected form value and Next, the
sketch kept showing the old value. The markdown component now also re-resolves
when the resolver changes, and the dialog passes a new resolver whenever form
values are committed.
feature/lts-4.2/iot-hub-devices
dpinkevych
1 month ago
Failed to extract signature
2 changed files with
12 additions and
5 deletions
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-markdown.component.ts
@ -376,13 +376,20 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
// Forward moves can come from the stepper header, which bypasses nextStep(),
// so commit every step being passed over here.
let formValuesChanged = false ;
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 ( ) ) ;
formValuesChanged = true ;
}
ws . completed = true ;
}
if ( formValuesChanged ) {
// Instruction steps stay rendered, and their markdown only changes when the resolver does:
// after Back and a corrected value, they would otherwise keep showing the old one.
this . resolveMarkdownVariable = this . _resolveMarkdownVariable . bind ( this ) ;
}
this . onStepActivated ( this . wizardSteps [ event . selectedIndex ] ) ;
}
@ -86,11 +86,11 @@ export class TbIotHubMarkdownComponent implements OnInit, OnChanges {
}
ngOnChanges ( changes : SimpleChanges ) : void {
for ( const propName of Object . keys ( changes ) ) {
const change = changes [ propName ] ;
if ( propName === 'data' && change . currentValue !== change . previousValue ) {
this . parsedData = this . parseData ( this . data ) ;
}
// A new resolver means the variable values changed, so the same data has to be resolved again.
const changed = [ 'data' , 'onResolveVariable' ]
. some ( propName = > changes [ propName ] && changes [ propName ] . currentValue !== changes [ propName ] . previousValue ) ;
if ( changed ) {
this . parsedData = this . parseData ( this . data ) ;
}
}