Project

General

Profile

Cleanup #42907

mgr/dashboard: make CdTableSelection generic

Added by Patrick Seidensal about 1 year ago. Updated about 1 year ago.

Status:
New
Priority:
Normal
Category:
dashboard/general
Target version:
-
% Done:

0%

Tags:
Backport:
Reviewed:
Affected Versions:
Pull request ID:

Description

The CdTableSelection class of the dashboards frontend is a perfect candidate to become a generic class.

export class CdTableSelection<T> {
  selected: T[] = [];
  hasMultiSelection: boolean;
  hasSingleSelection: boolean;
  hasSelection: boolean;

  constructor() {
    this.update();
  }

  /**
   * Recalculate the variables based on the current number
   * of selected rows.
   */
  update() {
    this.hasSelection = this.selected.length > 0;
    this.hasSingleSelection = this.selected.length === 1;
    this.hasMultiSelection = this.selected.length > 1;
  }

  /**
   * Get the first selected row.
   * @return {T | null}
   */
  first(): T {
    return this.hasSelection ? this.selected[0] : null;
  }
}

History

#1 Updated by Patrick Seidensal about 1 year ago

  • Subject changed from mgr/dashboard: make CdTableColumn generic to mgr/dashboard: make CdTableSelection generic
  • Description updated (diff)

Also available in: Atom PDF