Skip to content

Commit

Permalink
refactor: simplify quote-edit even more
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed Sep 23, 2020
1 parent cab61f2 commit 119f7e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'quote.edit.unsubmitted.name.label' | translate
}}</label>
<div class="col-8 col-md-9 col-xl-10">
<ish-inplace-edit (edited)="update.next()" (aborted)="reset.next()">
<ish-inplace-edit (edited)="update()" (aborted)="reset()">
<p class="form-control-plaintext w-auto" [ngClass]="{ 'font-italic': !form.get('displayName').value }">
{{ form.get('displayName').value || 'quote.edit.unsubmitted.enter_an_optional_name.text' | translate }}
</p>
Expand All @@ -38,7 +38,7 @@
'quote.edit.unsubmitted.comment.label' | translate
}}</label>
<div class="col-8 col-md-9 col-xl-10">
<ish-inplace-edit (edited)="update.next()" (aborted)="reset.next()">
<ish-inplace-edit (edited)="update()" (aborted)="reset()">
<p class="form-control-plaintext w-auto" [ngClass]="{ 'font-italic': !form.get('description').value }">
{{ form.get('description').value || 'quote.edit.unsubmitted.provide_comment.text' | translate }}
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { pick } from 'lodash-es';
import { Observable, Subject } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { Observable } from 'rxjs';

import { LineItemUpdate } from 'ish-core/models/line-item-update/line-item-update.model';

Expand All @@ -25,9 +24,6 @@ export class QuoteEditComponent implements OnInit {
description: new FormControl(''),
});

update = new Subject();
reset = new Subject();

constructor(private context: QuoteContextFacade) {}

private get valuesFromQuote() {
Expand All @@ -37,25 +33,24 @@ export class QuoteEditComponent implements OnInit {
ngOnInit() {
this.quote$ = this.context.select('entityAsQuoteRequest');

this.context.hold(this.reset, () => {
this.form.reset(this.valuesFromQuote);
});
this.context.hold(this.quote$, () => this.reset());
}

this.context.hold(this.quote$, () => this.reset.next());
update() {
const formValues = this.form.value;
const quoteValues = this.valuesFromQuote;

if (
formValues.displayName !== quoteValues.displayName ||
// tslint:disable-next-line: triple-equals
formValues.description != quoteValues.description
) {
this.context.update(formValues);
}
}

this.context.hold(
this.update.pipe(
map(() => [this.form.value, this.valuesFromQuote]),
filter(
([a, b]) =>
a.displayName !== b.displayName ||
// tslint:disable-next-line: triple-equals
a.description != b.description
),
map(([meta]) => meta)
),
meta => this.context.update(meta)
);
reset() {
this.form.reset(this.valuesFromQuote);
}

onUpdateItem(item: LineItemUpdate) {
Expand Down

0 comments on commit 119f7e7

Please sign in to comment.