All files / src/app/extensions/quoting/shared/quote-edit quote-edit.component.ts

56.25% Statements 9/16
42.85% Branches 3/7
33.33% Functions 2/6
60% Lines 9/15

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 543x 3x 3x     3x                       3x   1x         1x             1x   1x                                        
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { pick } from 'lodash-es';
import { Observable } from 'rxjs';
 
import { QuoteContextFacade } from '../../facades/quote-context.facade';
import { QuoteRequest } from '../../models/quoting/quoting.model';
 
/**
 * The Quote Edit Component displays and updates quote or quote request data.
 * It provides modify and delete functionality for quote request items.
 */
@Component({
  selector: 'ish-quote-edit',
  templateUrl: './quote-edit.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class QuoteEditComponent implements OnInit {
  quote$: Observable<QuoteRequest>;
  form = new UntypedFormGroup({
    displayName: new UntypedFormControl(''),
    description: new UntypedFormControl(''),
  });
 
  constructor(private context: QuoteContextFacade) {}
 
  private get valuesFromQuote() {
    return pick(this.context.get('entity'), 'displayName', 'description');
  }
 
  ngOnInit() {
    this.quote$ = this.context.select('entityAsQuoteRequest');
 
    this.context.hold(this.quote$, () => this.reset());
  }
 
  update() {
    const formValues = this.form.value;
    const quoteValues = this.valuesFromQuote;
 
    Iif (
      formValues.displayName !== quoteValues.displayName ||
      // eslint-disable-next-line eqeqeq
      formValues.description != quoteValues.description
    ) {
      this.context.update(formValues);
    }
  }
 
  reset() {
    this.form.reset(this.valuesFromQuote);
  }
}