github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/components/dashboards/check/common/node/ControlResultNode.ts (about)

     1  import {
     2    CheckNodeStatus,
     3    CheckNodeType,
     4    CheckSummary,
     5    CheckNode,
     6    CheckResult,
     7    CheckSeveritySummary,
     8  } from "../index";
     9  
    10  class ControlResultNode implements CheckNode {
    11    private readonly _result: CheckResult;
    12  
    13    constructor(result: CheckResult) {
    14      this._result = result;
    15    }
    16  
    17    get sort(): string {
    18      return "0";
    19    }
    20  
    21    get name(): string {
    22      return `${this._result.control.name}-${this._result.resource}`;
    23    }
    24  
    25    get title(): string {
    26      return this._result.reason;
    27    }
    28  
    29    get result(): CheckResult {
    30      return this._result;
    31    }
    32  
    33    get type(): CheckNodeType {
    34      return "result";
    35    }
    36  
    37    get summary(): CheckSummary {
    38      const summary = {
    39        alarm: 0,
    40        ok: 0,
    41        info: 0,
    42        skip: 0,
    43        error: 0,
    44      };
    45      if (this._result.status === "alarm") {
    46        summary.alarm += 1;
    47      }
    48      if (this._result.status === "error") {
    49        summary.error += 1;
    50      }
    51      if (this._result.status === "ok") {
    52        summary.ok += 1;
    53      }
    54      if (this._result.status === "info") {
    55        summary.info += 1;
    56      }
    57      if (this._result.status === "skip") {
    58        summary.skip += 1;
    59      }
    60      return summary;
    61    }
    62  
    63    get status(): CheckNodeStatus {
    64      // If we have results, this node is complete
    65      return "complete";
    66    }
    67  
    68    get severity_summary(): CheckSeveritySummary {
    69      const summary = {};
    70      if (this._result.control.severity) {
    71        summary[this._result.control.severity] =
    72          this._result.status === "alarm" ? 1 : 0;
    73      }
    74      return summary;
    75    }
    76  }
    77  
    78  export default ControlResultNode;