All files / components/_base/table table.base.ts

33.33% Statements 4/12
100% Branches 0/0
20% Functions 1/5
40% Lines 4/10

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                              1x     1x     1x     1x                      
import { signal } from '@angular/core';
 
import type { IDashboardTableConfig } from '../../../interfaces/table-config.interface';
 
/** Base class for table components. */
export abstract class AppTableBase<T> {
  /** Configuration of the table. */
  public set config(config: IDashboardTableConfig<T>) {
    this.columns.set(config.columns);
    this.displayedColumns.set(config.displayedColumns);
    this.dataSource.set(config.data);
    this.options.set(config.options);
  }
 
  /** All table columns. */
  public columns = signal<IDashboardTableConfig<T>['columns']>([]);
 
  /** Displayed tale columns. */
  public displayedColumns = signal<IDashboardTableConfig<T>['displayedColumns']>(this.columns().map(item => item.name));
 
  /** Table's data source. */
  public dataSource = signal<typeof this.config.data>([]);
 
  /** Row menu options. */
  public options = signal<IDashboardTableConfig<T>['options']>([]);
 
  /** Table column visibility change handler. */
  public columnVisibilityChange(columns: IDashboardTableConfig<T>['columns']) {
    const displayedColumns = columns.map(item => item.name);
    this.displayedColumns.set(displayedColumns);
  }
 
  /** Option selection handler. */
  public abstract optionSelected(value: string): void;
}