Skip to content

Commit

Permalink
fix(control schemes): fix op mode change resetting hub and port inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
nvsukhanov committed Aug 31, 2023
1 parent 113ca63 commit f0387c0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/app/control-schemes/binding-edit/binding-edit.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnDestroy } from '@angular/core';
import { MatCardModule } from '@angular/material/card';
import { NgIf } from '@angular/common';
import { Observable, Subscription, combineLatestWith, distinctUntilChanged, map, mergeWith, of, startWith, switchMap } from 'rxjs';
import { Observable, Subscription, combineLatestWith, distinctUntilChanged, map, mergeWith, of, pairwise, startWith, switchMap } from 'rxjs';
import { Store } from '@ngrx/store';
import { PushPipe } from '@ngrx/component';
import { concatLatestFrom } from '@ngrx/effects';
Expand Down Expand Up @@ -119,6 +119,16 @@ export class BindingEditComponent implements OnDestroy {
}
})
);
this.formUpdateSubscription.add(
this.form.controls.bindingType.valueChanges.pipe(
pairwise(),
).subscribe(([ prevOpMode, nextOpMode ]) => {
const prevOpModeHubId = this.form.controls[prevOpMode].controls.hubId.value;
const prevOpModePortId = this.form.controls[prevOpMode].controls.portId.value;
this.form.controls[nextOpMode].controls.hubId.setValue(prevOpModeHubId);
this.form.controls[nextOpMode].controls.portId.setValue(prevOpModePortId);
})
);
}

@Input()
Expand All @@ -136,7 +146,7 @@ export class BindingEditComponent implements OnDestroy {
operationMode: ControlSchemeBindingType | undefined
) {
if (operationMode !== undefined) {
this.formBuilder.patchForm(this.form, { operationMode });
this.form.controls.bindingType.setValue(operationMode);
}
}

Expand Down

0 comments on commit f0387c0

Please sign in to comment.