All files / src/app/extensions/tacton/pages/configure configure-page.component.ts

85% Statements 17/20
75% Branches 6/8
40% Functions 2/5
84.21% Lines 16/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 601x 1x   1x   1x 1x   1x 1x   1x                         1x                 1x   1x     1x   1x 1x 1x   1x                              
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, ViewChild, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Observable } from 'rxjs';
import { filter } from 'rxjs/operators';
 
import { ProductContextFacade } from 'ish-core/facades/product-context.facade';
import { SelectedProductContextFacade } from 'ish-core/facades/selected-product-context.facade';
import { ProductView } from 'ish-core/models/product-view/product-view.model';
import { whenTruthy } from 'ish-core/utils/operators';
import { ModalDialogComponent } from 'ish-shared/components/common/modal-dialog/modal-dialog.component';
 
import { TactonFacade } from '../../facades/tacton.facade';
import {
  TactonProductConfiguration,
  TactonProductConfigurationConflictItem,
  TactonProductConfigurationGroup,
} from '../../models/tacton-product-configuration/tacton-product-configuration.model';
 
@Component({
  selector: 'ish-configure-page',
  templateUrl: './configure-page.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
  providers: [{ provide: ProductContextFacade, useClass: SelectedProductContextFacade }],
})
export class ConfigurePageComponent implements OnInit {
  @ViewChild('conflictResolutionDialog') conflictResolutionDialog: ModalDialogComponent<
    TactonProductConfigurationConflictItem[]
  >;
 
  state$: Observable<TactonProductConfiguration>;
  step$: Observable<TactonProductConfigurationGroup>;
  loading$: Observable<boolean>;
  product$: Observable<ProductView>;
  private destroyRef = inject(DestroyRef);
 
  constructor(private tactonFacade: TactonFacade, private context: ProductContextFacade) {}
 
  ngOnInit() {
    this.product$ = this.context.select('product');
 
    this.state$ = this.tactonFacade.configureProduct$;
    this.step$ = this.tactonFacade.currentStep$;
    this.loading$ = this.tactonFacade.loading$;
 
    this.tactonFacade.conflicts$
      .pipe(
        whenTruthy(),
        filter(() => !!this.conflictResolutionDialog),
        takeUntilDestroyed(this.destroyRef)
      )
      .subscribe(conflicts => {
        this.conflictResolutionDialog.show(conflicts);
      });
  }
 
  acceptResolution() {
    this.tactonFacade.acceptConflictResolution();
  }
}