All files / app/component/action/inline-select inline-select.component.ts

59.09% Statements 13/22
75% Branches 12/16
25% Functions 2/8
50% Lines 8/16

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 4371x   71x 71x                 71x     1x       1x   1x 1x                                        
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { catchError, Observable, of } from 'rxjs';
import { LoadingComponent } from '../../loading/loading.component';
import { ActionComponent } from '../action.component';
 
@Component({
  selector: 'app-inline-select',
  templateUrl: './inline-select.component.html',
  styleUrls: ['./inline-select.component.scss'],
  host: { 'class': 'action' },
  imports: [LoadingComponent]
})
export class InlineSelectComponent extends ActionComponent {
 
  @Input()
  action: (value: any) => Observable<any|never> = () => of(null);
  @Input()
  value?: any;
  @Output()
  error = new EventEmitter<string>();
 
  editing = false;
  acting = false;
 
  override reset() {
    this.editing = false;
    this.acting = false;
  }
 
  override active() {
    return this.editing || this.acting;
  }
 
  save(field: HTMLSelectElement) {
    this.editing = false;
    this.acting = true;
    this.action((field.value || '').trim()).pipe(
      catchError(() => of(null)),
    ).subscribe(() => this.acting = false);
  }
 
}